用于浮动的 openCV fincontours
openCV fincontours for float
这是我的代码,你可以看到我正在使用 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() 不会 return x=4 ,y=3 但会 return x=4.312..., y=3.145....?
输入是整数数据(图像),因此输出也是整数数据(这是最准确的答案)。在您的情况下,我建议您从为 findContours 提供不同的标志开始。尝试使用 CV_CHAIN_APPROX_TC89_L1 而不是 CV_CHAIN_APPROX_NONE。这将执行一些多边形简化,即它会 'smooth' 轮廓一点以换取精度。或者您可以在调用 findContours 后使用 approxPolyDP 进行简化。
这是我的代码,你可以看到我正在使用 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() 不会 return x=4 ,y=3 但会 return x=4.312..., y=3.145....?
输入是整数数据(图像),因此输出也是整数数据(这是最准确的答案)。在您的情况下,我建议您从为 findContours 提供不同的标志开始。尝试使用 CV_CHAIN_APPROX_TC89_L1 而不是 CV_CHAIN_APPROX_NONE。这将执行一些多边形简化,即它会 'smooth' 轮廓一点以换取精度。或者您可以在调用 findContours 后使用 approxPolyDP 进行简化。