基于opencv+cuda实现形态学

  1. opencvsharp
 /*读入图片*/
 Mat Src_map = Cv2.ImRead("D:/1.jpg");
 
 /*初始化*/
 Mat open_map = new Mat();
 Mat close_map = new Mat();
 Mat Erode_map = new Mat();
 Mat Dilate_map = new Mat();
 
 /*膨胀核(要为奇数)*/
 int size = 5;
 Mat se = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(size,    size), new Point(-1, -1));
 
 /*开运算*/
 Cv2.MorphologyEx(Src_map, open_map, MorphTypes.Open, se);
 
 /*闭运算*/
 Cv2.MorphologyEx(Src_map, close_map, MorphTypes.Close, se);
 
 /*腐蚀运算*/
 Cv2.Erode(Src_map, Erode_map, se);
 
 /*膨胀运算*/
 Cv2.Dilate(Src_map, Dilate_map, se);
 
  1. opencv+cuda
 using namespace cv;
 using namespace cv::cuda;

 /*读入图片*/
 Mat Src_map = imread("D:/1.jpg");
 
 /*上传图片到gpu*/
 cuda::GpuMat GPU_src(Src_map);
 
 /*初始化*/
 GpuMat GPU_open, GPU_close, GPU_Erode, GPU_Dilate;
 
 /*核(要为奇数)*/
 Mat kenel = getStructuringElement(MORPH_RECT, Size(5, 5), Point(-1, -1));
 
 /*开运算*/
 Ptr<cuda::Filter> open_Filter = cuda::createMorphologyFilter( MORPH_OPEN, CV_8UC1, kenel);
 open_Filter->apply(GPU_src, GPU_open);
 
 /*闭运算*/
 Ptr<cuda::Filter> close_Filter = cuda::createMorphologyFilter( MORPH_CLOSE, CV_8UC1, kenel);
 close_Filter->apply(GPU_src, GPU_close);

 /*腐蚀运算*/
 Ptr<cuda::Filter> erode_Filter = cuda::createMorphologyFilter( MORPH_ERODE, CV_8UC1, kenel);
 erode_Filter->apply(GPU_src, GPU_Erode);

/*膨胀运算*/
 Ptr<cuda::Filter> dilate_Filter = cuda::createMorphologyFilter( MORPH_DILATE, CV_8UC1, kenel);
 dilate_Filter->apply(GPU_src, GPU_Dilate);
 
 /*初始化*/
 Mat open_map,close_map,Erode_map,Dilate_map ;
 
 /*从gpu下载*/
 GPU_open.download( open_map );
 GPU_close.download( close_map );
 GPU_Erode.download( Erode_map );
 GPU_Dilate.download( Dilate_map );
 

你可能感兴趣的:(opencv,cuda)