How to solve this? (finding an image)

asked 2020-07-09 22:38:46 -0600

despair104 gravatar image

updated 2020-07-11 22:48:56 -0600

Edited, Thank you for bearing with me.

Ok! I will approach my question in a different manner this time:

Using

  1. Python 3.8.3 64-bit
  2. opencv-python 4.3.0.36
  3. VS Code

So I have this image:

image description

How would you match the paint palette on the top (green box) with the one within the image (red box)?

matchtemplate does not work since there is rotation and different image size.

I am a beginner and I am trying to learn through projects I make up myself. I have been trying to figure this out for quite a while with no success, I hope you guys can help me. Thanks!

edit retag flag offensive close merge delete

Comments

1

may be smaller, different color or rotated, but they have a similar shape.

no, won't work. feature detection works on texture, not shape.

it's also not meant to find "a needle in a haystack", but "a rotated / scaled part of the same image"

berak gravatar imageberak ( 2020-07-10 01:53:42 -0600 )edit
1

features2D is already on OpenCV, you should have it installed. Without any other information is difficult give an help. It's up to the version of OpenCV that you're using, in the version that I use daily, some algorithm like SIFT are in the xfeatures2d module. Despite the characteristics of the feature detector that can deal with scale and rotation or not, the problem here is that you want to recognize two SIMILAR objects that have the same shape. In that case I think is might be better address the problem as a object detection. So you're able to find eventually the two object (or whatever) in different color and then you can try to compute an homography. It is an idea, but I think you should study and think about many stuff...

HYPEREGO gravatar imageHYPEREGO ( 2020-07-10 02:57:03 -0600 )edit

Thank you for your answers! I am a beginner, these terms may get confusing:

using:

python 3.8.3 64bit opencv 4.3.0.36

The problem I have with module features2d and xfeatures2d is that VS Code does not recognize them, VS Code does offer the autocomplete option, but when I hover the mouse on it, the description reads "unknown".

When I try to run the code in: https://docs.opencv.org/master/d5/d6f... , the following error appears:

cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\surf.cpp:1029: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SURF::create'

despair104 gravatar imagedespair104 ( 2020-07-10 13:30:18 -0600 )edit

The error is very explanatory, it say that you should recompile the entire library with the nonfree module. In opencv 3 it was necessary to download the opencv_contrib and build against it. You find a lot of howto guide about it, is really simple. In Opencv 4 I don't know exactly how have been moved that package. Regarding the problem, The ingredients for the recipe are the following:

  • Scale and rotation invariant feature detector
  • Feature matcher
  • Homography estimation.

That's the easy way that I suggest to you as a beginner, Try with that first before deep into other techniques. The first two step should be executed in green and the other img. If the input image (the green) is always in BW and the others are coloured, I suggest you to convert the image to grayscale

HYPEREGO gravatar imageHYPEREGO ( 2020-07-12 11:45:50 -0600 )edit

@HYPEREGO, thank you!

I cannot find any guide on installing the nonfree modules in Visual Studio Code. Do you know if it is possible, or if I must use Visual Studio Community?

despair104 gravatar imagedespair104 ( 2020-07-12 12:40:39 -0600 )edit