vislearn/ngransac

The feature dimensions of the demo program are inconsistent

Closed this issue · 5 comments

python3 ngransac_demo.py -img1 images/demo1.jpg -fl1 900 -img2 images/demo2.jpg -fl2 900

Using the code on the official website, the following error occurred

image

Three variable dimensions are inconsistent

pts1.shape, (2000, 1, 2) ,pts2.shape, (2000, 1, 2) ,ratios.shape (1, 2000, 1)

image

thanks!

Hi,

I cannot reproduce your error. The tensors pts1 and pts2 have the wrong dimensions. They should be (1,2000,2).

ngransac/ngransac_demo.py

Lines 130 to 135 in 8cd278b

for (m,n) in matches:
if m.distance < opt.ratio*n.distance: # apply Lowe's ratio filter
good_matches.append(m)
pts2.append(kp2[m.trainIdx].pt)
pts1.append(kp1[m.queryIdx].pt)
ratios.append(m.distance / n.distance)

The code above should result in pts1 and pts2 being lists with 2000 entries.

ngransac/ngransac_demo.py

Lines 139 to 140 in 8cd278b

pts1 = np.array([pts1])
pts2 = np.array([pts2])

The code above should turn pts1 and pts2 into tensors of shape (1,2000,2). Particularly, wrapping pts1 in a list [pts1] before passing it to np.array should create a tensor with the first axis being one-dimensional. In your case, the first axis is 2000-dimensional. Did you alter the code?

Hi,
I think i find where is wrong,
pts1 = cv2.undistortPoints(pts1, K1, None) pts2 = cv2.undistortPoints(pts2, K2, None)
those two lines of code will turn pts1 and pts2 from (1,2000,2) to (2000,1,2)

Thanks for the update. Interesting. Which version of OpenCV are you using?

opencv-python 4.4.0.42

At the moment, we can only confirm compatibility to OpenCV 3.4. You might encounter other problems when using Opencv 4.x.