首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从vector<point2f>创建材质

从vector<point2f>创建材质
EN

Stack Overflow用户
提问于 2014-05-11 03:08:19
回答 1查看 16.6K关注 0票数 9

我对计算机视觉和opencv库非常陌生。

我做了一些谷歌搜索,试图找到如何从Point2fs的向量生成新图像,但还没有找到任何可行的示例。我见过vector to Mat,但当我使用这些示例时,我总是收到错误。

我正在从this示例中工作,任何帮助都将不胜感激。

代码:传入occludedSquare。

代码语言:javascript
复制
   resize(occludedSquare, occludedSquare, Size(0, 0), 0.5, 0.5);

   Mat occludedSquare8u;
   cvtColor(occludedSquare, occludedSquare8u, CV_BGR2GRAY);

   //convert to a binary image. pixel values greater than 200 turn to white. otherwize black
   Mat thresh;
   threshold(occludedSquare8u, thresh, 170.0, 255.0, THRESH_BINARY);



   GaussianBlur(thresh, thresh, Size(7, 7), 2.0, 2.0);

   //Do edge detection
   Mat edges;
   Canny(thresh, edges, 45.0, 160.0, 3);

   //Do straight line detection
   vector<Vec2f> lines;
   HoughLines( edges, lines, 1.5, CV_PI/180, 50, 0, 0 );

   //imshow("thresholded", edges);


   cout << "Detected " << lines.size() << " lines." << endl;

   // compute the intersection from the lines detected...
   vector<Point2f> intersections;
   for( size_t i = 0; i < lines.size(); i++ )
   {
       for(size_t j = 0; j < lines.size(); j++)
       {
           Vec2f line1 = lines[i];
           Vec2f line2 = lines[j];
           if(acceptLinePair(line1, line2, CV_PI / 32))
           {
               Point2f intersection = computeIntersect(line1, line2);
               intersections.push_back(intersection);
           }
       }

   }

   if(intersections.size() > 0)
   {
       vector<Point2f>::iterator i;
       for(i = intersections.begin(); i != intersections.end(); ++i)
       {
           cout << "Intersection is " << i->x << ", " << i->y << endl;
           circle(occludedSquare8u, *i, 1, Scalar(0, 255, 0), 3);
       }
   }

//Make new matrix bounded by the intersections
...
imshow("localized", localized);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-11 03:15:23

应该像这样简单

代码语言:javascript
复制
std::vector<cv::Point2f> points;
cv::Mat image(points);
//or
cv::Mat image = cv::Mat(points) 

可能会混淆的是,cv::Mat是通道的图像矩阵,但它也是一个数学矩阵rows*columns*other dimension

如果你从一个包含'n‘个二维点的矢量中创建一个Mat,它将创建一个2列x 'n’行的矩阵。您正在将此函数传递给一个需要图像的函数。

如果您只有一组分散的2D点,并希望将它们显示为图像,则需要创建一个足够大的空cv::Mat (无论您的最大x,y点是多少),然后使用绘图函数http://docs.opencv.org/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.html绘制这些点

如果您只想设置这些点坐标下的像素值,以便opencv设置像素值,那么有很多解决方案

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23585158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档