/* dlist_remove */ int dlist_remove(DList *list, DListElmt *element, void **data) { /* Do not allow a NULL element or removal from an empty list. */ if(element == NULL || dist_size(list) == 0) return -1; /* remove the element from the list. */ *data = element->data; if(element == list->head) { /* handle removal from the head of the list. */ list->head = element->next; if(list->head == NULL) list->tail = NULL; else element->next->prev = NULL; } else { /* handle removal from other than the head of the list */ element->prev->next = element->next; if(element->next == NULL) list->tail = element->prev; else element->next->prev = element->prev; } /* free the storage allocated by the abstract datatype. */ free(element); /* adjust the size of the list to account for the removed element. */ list->size--; return 0; }
template <typename MatElem> cv::Mat _generateGaussianMask(const cv::Mat& covariance, double ignore_rate){ assert(skl::checkMat(covariance,-1,1,cv::Size(2,2))); cv::Mat Wvec,U,Vt; cv::SVD svd; svd.compute(covariance,Wvec,U,Vt); cv::Mat W(covariance.size(),covariance.type()); std::vector<MatElem> std_dev(W.rows); for(int i=0;i<W.rows;i++){ std_dev[i] = (MatElem)std::sqrt((double)Wvec.at<MatElem>(i,0)); } // mask size must be odd num cv::Point center( static_cast<int>(std_dev[0] * ignore_rate/2), static_cast<int>(std_dev[1] * ignore_rate/2)); cv::Size mask_size( center.x*2+1, center.y*2+1); cv::Mat gaussian_x = cv::getGaussianKernel(mask_size.width ,-1, covariance.depth()); cv::Mat gaussian_y = cv::getGaussianKernel(mask_size.height,-1, covariance.depth()); cv::Mat gaussian_mask = gaussian_y * gaussian_x.t(); /* for(int i=0;i<Wvec.rows;i++){ W.at<MatElem>(i,i) = Wvec.at<MatElem>(i,0); } std::cout << "covariance >> " << covariance << std::endl; std::cout << "W >> " << W << std::endl; std::cout << "U >> " << U << std::endl; std::cout << "Vt >> " << Vt << std::endl; std::cout << (U*W*Vt) << std::endl; */ float rad = skl::radian(cv::Point2f(U.at<MatElem>(0,0),U.at<MatElem>(0,1))); float degree = rad*180/CV_PI; // std::cout << "gausiann rotation: " << degree << std::endl; /* // DEBUG CODE: draw vertical/horizontal lines crossing at the center. for(int x=0;x<gaussian_mask.cols;x++){ gaussian_mask.at<MatElem>(center.y,x) = 1; } for(int y=0;y<gaussian_mask.rows;y++){ gaussian_mask.at<MatElem>(y,center.x) = 1; } */ // rotate gaussian mask int max_length = std::max(mask_size.width,mask_size.height); cv::Size dist_size(max_length,max_length); cv::Mat gaussian_mask_max_length(dist_size,gaussian_mask.type(),cv::Scalar(0)); int diff_x = max_length - mask_size.width; int diff_y = max_length - mask_size.height; gaussian_mask.copyTo( cv::Mat( gaussian_mask_max_length, cv::Rect(diff_x/2,diff_y/2,mask_size.width,mask_size.height) ) ); cv::Mat affin_mat = cv::getRotationMatrix2D(cv::Point(max_length/2,max_length/2),degree,1.0); // std::cout << affin_mat << std::endl; cv::Mat gaussian_mask_rotated; /* cv::namedWindow("before rotation",0); cv::imshow("before rotation",gaussian_mask_max_length); */ cv::warpAffine(gaussian_mask_max_length,gaussian_mask_rotated,affin_mat,dist_size); return gaussian_mask_rotated; }