How to check if two loops match using OpenCV matchShapes?

I am trying to check if the contours found in the two images match. I saw that OpenCV has a function called matchShapesthat returns a similarity metric. However, he only gets Matof Points, not all of them. In the doc example, he goes on to the method of the first Mat Of Points.

So, I can run this method by passing one Mat Of Points and getting a metric every time, but how can I do this if I need a unique similarity metric?

Maybe iterating over all the mat points, aplying matchShapesand calculating the average later?

The code:

var Binarized1:Mat=new Mat()
var Binarized2:Mat=new Mat()
var contours1 = new util.ArrayList[MatOfPoint]()
var contours2 = new util.ArrayList[MatOfPoint]()

//computing thresholds
 org.opencv.imgproc.Imgproc.threshold(mole1,Binarized1,0,255,org.opencv.imgproc.Imgproc.THRESH_BINARY_INV+org.opencv.imgproc.Imgproc.THRESH_OTSU)
 org.opencv.imgproc.Imgproc.threshold(mole2,Binarized2,0,255,org.opencv.imgproc.Imgproc.THRESH_BINARY_INV+org.opencv.imgproc.Imgproc.THRESH_OTSU)

//finding contours
 org.opencv.imgproc.Imgproc.findContours(Binarized1,contours1,new Mat(),org.opencv.imgproc.Imgproc.RETR_EXTERNAL,org.opencv.imgproc.Imgproc.CHAIN_APPROX_NONE)
 org.opencv.imgproc.Imgproc.findContours(Binarized2,contours2,new Mat(),org.opencv.imgproc.Imgproc.RETR_EXTERNAL,org.opencv.imgproc.Imgproc.CHAIN_APPROX_NONE)

//matching shapes
 var cnt1=contours1.get(0)
 var cnt2=contours2.get(0)
 print("matching shapes="+ org.opencv.imgproc.Imgproc.matchShapes(cnt1,cnt2,org.opencv.imgproc.Imgproc.CV_CONTOURS_MATCH_I1,0))

I know there are similar questions, but no one does the trick for me.

+4
1

, , .

, . , . n * m .

, .

+1

Source: https://habr.com/ru/post/1667123/


All Articles