rmislam/PythonSIFT

Perspective transform raises error

ChargedMonk opened this issue · 4 comments

I got the following error while matching two images.

OpenCV(4.1.2) /io/opencv/modules/core/src/matmul.dispatch.cpp:531: error: (-215:Assertion failed) scn + 1 == m.cols in function 'perspectiveTransform'

Hi @ChargedMonk, can you please attach your two images here so I can debug?

Here are the two images -

Image 1

Image 2

@ChargedMonk I can't exactly reproduce your error, but I have an idea of what is happening. Probably very few keypoints are generated for your images. When I run the matching script with your images on my computer, I only generate 9 keypoints, which is enough to generate a homography. However, possibly on your machine, there are fewer than 4 keypoints generated.

When you run template_matching_demo.py on your machine, what is the length of the list variable good? This is the number of keypoint matches. If there are too few points, I can suggest some threshold changes in the demo script for you.

I also realize you must have reduced the value of MIN_MATCH_COUNT at the top of the script. I've set this to 10 specifically to avoid this problem. You need at least 4 keypoints to generate a unique homography, and typically around 10 keypoints for the homography to be stable. If you can't generate enough keypoints, I suggest you try higher resolution images.

I'm going to close this issue because it's not an issue with the actual code -- it's just that not enough keypoints are generated for your particular images.