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;