我对计算机视觉和opencv库非常陌生.
我已经做了一些谷歌搜索试图找到如何从Point2fs的矢量创建一个新的图像,并没有找到任何有效的例子.我见过vector<Point>,Mat但是当我使用这些例子时,我总是会遇到错误.
我正在从这个例子工作,任何帮助将不胜感激.
代码:我通过了occludedSquare.
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);
Run Code Online (Sandbox Code Playgroud)
Mar*_*ett 11
应该如此简单
std::vector<cv::Point2f> points;
cv::Mat image(points);
//or
cv::Mat image = cv::Mat(points)
Run Code Online (Sandbox Code Playgroud)
可能的混淆是cv :: Mat是一个width*height*number通道的图像,但它也是一个数学矩阵,rows*columns*other dimension.
如果你从'n'个2D点的矢量制作一个Mat,它将按'n'行矩阵创建一个2列.您将此传递给期望图像的函数.
如果您只有一组散在的2D点,并希望将它们显示为图像,则需要制作一个足够大的空cv :: Mat(无论您的最大x,y点是什么),然后使用绘图绘制点函数http://docs.opencv.org/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.html
如果您只想在这些点坐标处设置像素值,请搜索SO以获取opencv设置像素值,这里有很多答案