Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks for your help Storiy. I was able to get what I wanted. I added these following codes in chamfer.cpp

imshow("result0", cimg);

int count_pixels = countNonZero(img);
imshow("result1", img);

cvtColor(cimg, cimg, CV_BGR2GRAY);
threshold( cimg, cimg, 200, 255, THRESH_BINARY );
int count_white = countNonZero(cimg);

cout << "Contour = " << count_pixels << endl;
cout << "White = " << count_white << endl;

float m = count_contour - count_white;
float d = m / count_contour;
float s = d * 100;

cout << "Similarity = " << s << endl;

imshow("result2", cimg);

image description

Contour = 1572 White = 35 Similarity = 97.7735

Thanks for your help Storiy. @Storiy. I was able to get what I wanted. I added these following codes in chamfer.cpp

imshow("result0", cimg);

int count_pixels = countNonZero(img);
imshow("result1", img);

cvtColor(cimg, cimg, CV_BGR2GRAY);
threshold( cimg, cimg, 200, 255, THRESH_BINARY );
int count_white = countNonZero(cimg);

cout << "Contour = " << count_pixels << endl;
cout << "White = " << count_white << endl;

float m = count_contour - count_white;
float d = m / count_contour;
float s = d * 100;

cout << "Similarity = " << s << endl;

imshow("result2", cimg);

image description

Contour = 1572 White = 35 Similarity = 97.7735