Ask Your Question
1

What is the correct way of using the cv2.correctMatches in Python

asked 2016-09-20 23:48:00 -0600

jads_96 gravatar image

I am trying to pass the corresponding image coordinates to the function and throws an error.

cv2.error: D:\OpenCV_3\opencv_8-18-16\modules\calib3d\src\triangulate.cpp:202: error: (-209) The point-matrices must have one row, and an equal number of columns in function cvCorrectMatches

I am passing some SHI-TOMASI features (cv2.goodFeaturetoTrack) and matching them with the KLT tracker ( cv2.calcOpticalFlowPyrLK).

This is the code producing the exception.

p1, st, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)


# Select good points
good_new = p1[st==1]
good_old = p0[st==1]

arrayF = cv2.findFundamentalMat(good_new, good_old, cv2.FM_RANSAC)
F = arrayF[0]
better_new, better_old = cv2.correctMatches(F, good_new, good_old)
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
-1

answered 2016-09-28 18:20:04 -0600

jads_96 gravatar image

Found the answer on another forum:

http://answers.opencv.org/question/34...

It was pretty simple, just had to reformat the arrays.

pt1 = np.reshape(pt1,(1,n,2))
pt2 = np.reshape(pt2,(1,n,2))
edit flag offensive delete link more

Comments

Didn't I just say the exact same thing..........

alienmon gravatar imagealienmon ( 2016-09-29 06:08:22 -0600 )edit
0

answered 2016-09-21 02:34:33 -0600

alienmon gravatar image

updated 2016-09-21 02:39:50 -0600

Please refer to this documentation

Let me quote from it:

Python: cv2.correctMatches(F, points1, points2[, newPoints1[, newPoints2]]) → newPoints1, newPoints2

Parameters: 
F – 3x3 fundamental matrix.
points1 – **1xN array** containing the first set of points.
points2 – **1xN array** containing the second set of points.
newPoints1 – The optimized points1.
newPoints2 – The optimized points2.

I thnk the cause of the error is pretty clear "The point-matrices must have one row, and an equal number of columns in function cvCorrectMatches"

Can you check/print the size of good_old and good_new? they both must have each one row, and equal number of cols to be passed to correctmatches

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-20 23:48:00 -0600

Seen: 2,795 times

Last updated: Sep 28 '16