cvMatchShapes returns me result which is out of logic

谁都会走 提交于 2019-12-11 09:35:00

问题


I'm a newer in computer vision field.

I found some code examples in EmguCV(.NET wrapper for OpenCV) which I`m trying to use.

Currently I'm working on triangle traffic sign recognition and I'm using cvMatchShapes function.

The function returns "zero" in ideal case, it means that the shapes are the same and the number is

close to zero if shapes are similar.

The problem is that in my case function returns me result which is out of logic. when function compares triangle with the circle, it returns figure which is less than figure, got after comparing two triangles.

Here is the function that I use and the images:

                double ratio = CvInvoke.cvMatchShapes(modelSignTraffic, trafficSign, Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);

modelSignTraffic - is a template. In my case it is -

trafficSign - is an shape that should be compared to the template.

first compared shape-

second compared shape-

For the first shape I get ratio 0.55 and for the second shape I get ratio 0.61 .

I would be very grateful if anybody could explain why do I get such illogical result and how I can fix it?

Thank you in advance.


回答1:


I don't understand why do you think that this result is not logical. Did you read formula for CV_CONTOURS_MATCH_I3? Here it is. I'm 100% sure that if you calculate this coeficient by hand you will get the same result.

By the way you have to calculate this coeficient for contours (shapes) not for images. So firstly detect shapes and after this use MatchShapes.

Update:

Your solution is wrong. You have to segment red color first and after this use findContours to detect red shapes.




回答2:


I was able to get better result from the cvMatchShapes function after the images were scaled to same size with help of Resize extension.

Unfortunately this solution is not ideal because when checking other options with this approach, I do not always get the desired result.

Here is the code:

     Image<Bgr, Byte> triangleModel = new Image<Bgr, Byte>("TriangleTamplate.jpg")
                        .Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR,true);
     Image<Gray, Byte> grayModel = triangleModel.Convert<Gray, Byte>();
     Image<Gray, Byte> cannyModel = grayModel .Canny(new Gray(100), new Gray(160));


     Image<Bgr, Byte> comparedImage = new Image<Bgr,Byte>("ImageToCompare.jpg")
                         .Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR,true);
     Image<Gray, Byte> grayImage = tempImage.Convert<Gray, Byte>();
     Image<Gray, Byte> cannyImage = grayImage.Canny(new Gray(100),new Gray(160));

     double eRatio = CvInvoke.cvMatchShapes(cannyModel.Ptr, cannyImage,Emgu.CV.CvEnum.CONTOURS_MATCH_TYPE.CV_CONTOURS_MATCH_I3, 0);

For triangle Ratio is 0.0320

For circle Ratio is 0.0829



来源:https://stackoverflow.com/questions/12122033/cvmatchshapes-returns-me-result-which-is-out-of-logic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!