简体   繁体   中英

Calculating contour vertices for vector<Point2f> point cloud with cv::findContour()

Please understand that I'm fairly new to opencv. What I have is a vector filled with a 2D point cloud with float values as x and y indices. All I want is some way to calculate the outer contour of this cloud. Determining a bounding rectangle and a convex hull was no problem since the respective functions simply worked with my vector. I was expecting findContour() to be no different but it seems I was wrong. Literally every tutorial on findContour() teaches me how to load images into a cv::Mat object and noone talks about how this is supposed to work with a 2D point cloud which is not that different from a binary image in theory. I understand that findContour() expects it's first argument to be a special type of matrix but I have no idea on how to modify my vector to get to the desired result. I've tried to instantiate a matrix with cv::Mat(vector<Point2f>) which works in itself but results in an exception when I pass it to findContour() unfortunately. Please help!

I am working with GCC on a Raspberry Pi 3 with Raspbian btw.

findContours will only find contours in an image.

The outer contour of a point cloud isn't well defined - how do you know not to go 'in' between two dots to connect to a dot closer to the middle?

It only makes sense if you have some scale length that you consider an edge. Simplest way with openCV is to calculate the convex hull and then look at convexity defects - add any defects you consider part of the outline into the point list at that position

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM