Ask Your Question
3

Chamfer Matching match score

asked 2015-05-04 21:15:06 -0600

thevinci gravatar image

updated 2016-01-04 22:32:54 -0600

I am currently working on a project that will utilize the chamfer matching algorithm. The program will show an image and then a user will try draw the image using a touch device. The program will then match and compute the similarity scores of the hand drawn image vs the given image based on their edges.

image description image description

I had reviewed the chamfer matching example from the /opencv/samples/cpp. The example provides a way on how to use the chamerMatching() effectively but it does not provide the chamfer distance score between the template image and the image edge map. My question is what is the specific function/method i should use to get the chamfer score of the hand drawn image against the given image. Is there also a way to get the similarity score in percentage?

edit retag flag offensive close merge delete

Comments

1

I think, if you transfer both images to binary, you can count pixels in matching points using mask from original image. Btw if you are trying to compare images, you probably should use contour images, not colored one's.

Storiy gravatar imageStoriy ( 2015-05-05 05:44:42 -0600 )edit
1

first of all, you can use cvtColor(input_image, output_image, CV_BGR2GRAY); to transfer image to binary, also, to count only black and white pixels, you will need to threshold already binary image with threshold( input_image, output_image, 200, 255, THRESH_BINARY );, after that with a help of countNonZero you can count them. That will only work for black-n-white images so keep it on mind.

        count_white = countNonZero(partyROI);
        count_black = input_image.cols * input_image.rows - count_white;

but to work only with a selected region you need something like this, i think.

Storiy gravatar imageStoriy ( 2015-05-12 05:56:23 -0600 )edit

Thanks man it solved my problem.

thevinci gravatar imagethevinci ( 2015-05-12 10:39:51 -0600 )edit

thanks for this post! i got an idea for my own problem :)

thesis_ gravatar imagethesis_ ( 2016-01-14 17:14:16 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2015-05-12 10:45:56 -0600

thevinci gravatar image

updated 2015-05-12 21:15:18 -0600

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

edit flag offensive delete link more
0

answered 2015-05-05 07:15:47 -0600

Eduardo gravatar image

I think that your best bet is to tweak the source files to have access to the different methods like computeDistanceTransform (OpenCV 2.4.11). and or create variables to store the Chamfer distance for each matches.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-04 21:15:06 -0600

Seen: 2,567 times

Last updated: May 12 '15