Create Mat from Vector <point2f>
I am extremely familiar with computer vision and the opencv library.
I did some searches to try and find how to make a new image from a Point2fs vector, and did not find any examples that work. I saw vector<Point> before Mat , but when I use these examples, I always get errors.
I am working from this example and any help would be appreciated.
Code: I turn to 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); It should be as simple as
std::vector<cv::Point2f> points; cv::Mat image(points); //or cv::Mat image = cv::Mat(points) There is probably confusion that cv :: Mat is an image of the width*height*number channels, but also the mathematical matrix rows*columns*other dimension .
If you make Mat from the vector "n" of 2D points, it will create a matrix of rows "n" from 2 columns. You pass this to a function that expects an image.
If you have a scattered set of two-dimensional points and you want to display them as an image, you need to make an empty cv :: Mat large enough (regardless of your maximum x, y points), and then draw the points using the drawing functions http: // docs .opencv.org / doc / tutorials / core / basic_geometric_drawing / basic_geometric_drawing.html
If you just want to set the pixel values ββin these coordinates, looking for SO for the opencv installation pixel values, there are many answers