Opencv 提取轮廓路径属性

Opencv 提取轮廓路径属性,opencv,visual-c++,Opencv,Visual C++,我目前正在从一个特定的图像文件中提取轮廓路径属性。我能够使用Open CV函数findContours()提取轮廓,输出如下 [98, 81][97, 80][95, 80][94, 79][93, 79][92, 78][91, 78][88, 75][87, 75][85, 73][84, 73][83, 72][82, 72] 但是我想要的输出是这样的 [98, 81][97, 80][95, 80][94, 79][93, 79][92, 78][91, 78][88, 75][87,

我目前正在从一个特定的图像文件中提取轮廓路径属性。我能够使用Open CV函数
findContours()
提取轮廓,输出如下

[98, 81][97, 80][95, 80][94, 79][93, 79][92, 78][91, 78][88, 75][87, 75][85, 73][84, 73][83, 72][82, 72]
但是我想要的输出是这样的

[98, 81][97, 80][95, 80][94, 79][93, 79][92, 78][91, 78][88, 75][87, 75][85, 73][84, 73][83, 72][82, 72]
M 398.7106.8c-5.5、-2.7-20.7、-4.7-36.1、-4.6-15.4,0.1

我怎样才能得到它

这是我的代码:

using namespace cv;
using namespace std;
Mat src_grays;
int threshs = 100;
int max_threshs = 255;
RNG rng(12345);
void thresh_callbacks(int, void* );
void main(  )
{
Mat src = imread( "F:/academic/pro4/t/download.jpg" );
imshow("real Image", src);
Mat gray,edge,edges, draw,draws;
Mat samples(src.rows * src.cols, 3, CV_32F);
for( int y = 0; y < src.rows; y++ )
for( int x = 0; x < src.cols; x++ )
  for( int z = 0; z < 3; z++)
    samples.at<float>(y + x*src.rows, z) = src.at<Vec3b>(y,x)[z];
int clusterCount = 5;
Mat labels;
int attempts = 10;
Mat centers;
kmeans(samples, clusterCount, labels, TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 10000, 0.0001), attempts, KMEANS_PP_CENTERS, centers );
Mat new_image( src.size(), src.type() );
for( int y = 0; y < src.rows; y++ )
for( int x = 0; x < src.cols; x++ )
{ 
  int cluster_idx = labels.at<int>(y + x*src.rows,0);
  new_image.at<Vec3b>(y,x)[0] = centers.at<float>(cluster_idx, 0);
  new_image.at<Vec3b>(y,x)[1] = centers.at<float>(cluster_idx, 1);
  new_image.at<Vec3b>(y,x)[2] = centers.at<float>(cluster_idx, 2);
}
imshow( "clustered image", new_image );
char filename[80];
    sprintf(filename,"F:/academic/pro4/t/seg.png");
    imwrite(filename, new_image);
     cvtColor(src, gray, CV_BGR2GRAY);
Canny( new_image, edges, 50, 150, 3);
edges.convertTo(draws, CV_8U);
namedWindow("imageAfterSegmnetation", CV_WINDOW_AUTOSIZE);
imshow("imagesAfterCluster", draws);
cvtColor( new_image, src_grays, CV_BGR2GRAY );
blur( src_grays, src_grays, Size(3,3) );
char* source_window = "Source";
namedWindow( source_window, CV_WINDOW_AUTOSIZE );
imshow( source_window, src );
createTrackbar( " Canny thresh:", "Source", &threshs, max_threshs, thresh_callbacks );
thresh_callbacks( 0, 0 );
  waitKey( 0 );
 }
void thresh_callbacks(int, void* )
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Detect edges using canny
Canny( src_grays, canny_output, threshs, threshs*2, 3 );
/// Find contours
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
for(int i= 0; i < contours.size(); i++)
{
for(int j= 0; j < contours[i].size();j++) // run until j < contours[i].size();
{
    int a=  contours[i][j].x  ; 
    int b =contours[i][j].y ;
   // printf("Point(x,y)=" + a, b);
    std::cout << contours[i][j] << std::endl;       
}
printf ("%i", i + "\n");
}
/// Draw contours
int a=contours.size();

for( int i = 0; i<contours.size(); i++ )
 {
     Mat drawing_i = Mat::zeros( canny_output.size(), CV_8UC3 );
   Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
   drawContours( drawing_i, contours, i, color, 2, 8, hierarchy, 0, Point() );
    namedWindow( "Contours_i", CV_WINDOW_AUTOSIZE );
    imshow( "Contours_i", drawing_i );
   }
   }
使用名称空间cv;
使用名称空间std;
Mat src_灰色;
int阈值=100;
int max_threshs=255;
RNG RNG(12345);
void thresh_回调(int,void*);
空干管()
{
Mat src=imread(“F:/academic/pro4/t/download.jpg”);
imshow(“真实图像”,src);
垫子灰,边,边,画,画;
垫样品(src.rows*src.cols,3,CV_32F);
对于(int y=0;y你能更好地解释你想要的输出吗?我需要轮廓路径,这意味着如何连接轮廓,例如,它可以是M=moveto L=lineto H=horizontal lineto V=vertical lineto C=curveto S=smooth curveto Q=Squadral Bézier curve T=smooth Squadral Bézier curveto A=Ellizel Arc Z=closepath就像SVG pathEdit y一样我们对这个问题的评论。这是非常相关的。而且,这不是一个简单的问题:你能更好地解释你想要的输出吗?我需要轮廓路径,它意味着如何连接轮廓,例如它可以是M=移动到L=直线到H=水平线到V=垂直线到C=曲线到s=平滑曲线到Q=二次Bézier曲线T=平滑二次Bézier curveto A=椭圆弧Z=闭合路径就像SVG路径一样将您的评论编辑到问题中。这非常相关。而且,这不是一个简单的问题:D