Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 轮廓不是很好_Opencv_Contour - Fatal编程技术网

Opencv 轮廓不是很好

Opencv 轮廓不是很好,opencv,contour,Opencv,Contour,我试着在我的图像中勾勒出形状的轮廓 以下是我的步骤: 灰度 模糊 索贝尔 找到轮廓线 代码如下: void detect_features ( string &path ){ std::cout << "detection\n"; Mat image, src; int ddepth = CV_16S; image = imread( path, IMRE

我试着在我的图像中勾勒出形状的轮廓

以下是我的步骤:

  • 灰度
  • 模糊
  • 索贝尔
  • 找到轮廓线
  • 代码如下:

     void detect_features ( string &path ){
    
                std::cout << "detection\n";
                Mat image, src;
                int ddepth = CV_16S;
    
                image = imread( path, IMREAD_GRAYSCALE ); // Load an image
    
                // Remove noise by blurring with a Gaussian filter ( kernel size = 3 )
                GaussianBlur( image, src, Size( 3, 3 ), 0, 0, BORDER_DEFAULT );
    
                // ![sobel]
                /// Generate grad_x and grad_y
                Mat grad_x, abs_grad_x;
                Mat grad_y, abs_grad_y;
    
                Sobel( src, grad_x, ddepth, 1, 0 );
                Sobel( src, grad_y, ddepth, 0, 1 );
                convertScaleAbs( grad_x, abs_grad_x );
                convertScaleAbs( grad_y, abs_grad_y );
    
                addWeighted( abs_grad_x, 1, abs_grad_y, 1, 0, final );
    
        }
    
    无效检测功能(字符串和路径){
    标准::cout
    
            void shapes_detection (){
                std::cout << "shape\n";
                vector <vector <Point> > contours;
    
                findContours( final, contours, RETR_TREE, CHAIN_APPROX_NONE );
    
                  drawContours( final, contours, -1, 100, 2 );
                  string pj = "out_shapes.jpg";
                  write_final_img( pj );
    
                  return;