openCV fincontours for float

openCV fincontours for float

本文关键字:float for fincontours openCV      更新时间:2023-10-16

这是我的代码,正如你所看到的,我正在使用cv::Point和Vec4i

cv::Mat bwImage;
cv::cvtColor(dst,bwImage, CV_RGB2GRAY); 
cv::vector<cv::vector<cv::Point> > contours1;
cv::vector<cv::Vec4i> hierarchy2;
//% Get the borders of each object
//[B,~] = bwboundaries(bwImgLabeled,'noholes');
cv::findContours(bwImage,contours1,hierarchy2,CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);

既然我需要精度,有没有办法将其用于cv::Point2f?所以findContours()不会返回x=4,y=3,但会返回x=4.312…,y=3.145。。。。?

输入是整数数据(图像),因此输出也是整数数据(这是最精确的答案)。在您的情况下,我建议您从提供不同的标志来查找Contours开始。尝试使用CV_CHAIN_APPROX_TC89_L1而不是CV_CHAIN _APPROX_NONE。这将执行一些多边形简化,即它将稍微"平滑"轮廓以换取精度。或者,您可以在调用findContours后使用approxPolyDP来执行简化。