对于完全相同的图像
OpenCV 代码:
img = imread("testImg.png",0);
threshold(img, img_bw, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
Mat tmp;
img_bwR.copyTo(tmp);
findContours(tmp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
// Get the moment
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mu[i] = moments( contours[i], false );
}
// Display area (m00)
for( int i = 0; i < contours.size(); i++ )
{
cout<<mu[i].m00 <<endl;
// I also tried the code
//cout<<contourArea(contours.at(i))<<endl;
// But the result is the same
}
Matlab 代码:
Img = imread('testImg.png');
lvl = graythresh(Img);
bw = im2bw(Img,lvl);
stats = regionprops(bw,'Area');
for k = 1:length(stats)
Area = stats(k).Area; %m00
end
有人对此有何想法?如何统一它们?我认为他们使用不同的方法来查找轮廓。
我在下面的链接中上传了测试图像,以便有兴趣的人可以重复该过程。
这是一个100x100的小8位灰度图像,只有0和255的像素强度。为简单起见,它只有一个斑点。
对于OpenCV,轮廓的面积(图像矩m00)为609.5(非常奇怪的值) 对于Matlab,轮廓的面积(图像矩m00)为763。谢谢