What to do if you think the example script doesn't work
I will talk about my experience in the situation of import cv2 from Python 2.7.
Even if you get only the script, it will not work without the input image that the script assumes. Look for images in the OpenCV distribution that are related to the context in which they are used, such as'box.png','box_in_scene.png'.
Suppose you get an error when you call cv2.drawMatches while the script is running.
>>> help(cv2.drawMatches)
But it causes an error.
#### **`>>> cv2.__version__`**
```__version__
If so, the value before 3.0.0 should be displayed.
Since the distribution in OpenCV3 and the distribution in OpenCV2 are both cv2.pyd.
Find out which version you are using.
drawMatches () is a function that is not included in OpenCV2 and is implemented in the OpenCV3 distribution.
In the location of the Python library (eg C: \ Python27 \ Lib \ site-packages, please read according to your environment),
Copy the Python binding cv2.pyd of the version of OpenCV you want to use.
Then restart python and do the same, you will find cv2.drawMatches.
\>>> import cv2
\>>> cv2.\_\_version__
'3.0.0-beta'
\>>> help(cv2.drawMatches)
Help on built-in function drawMatches:
drawMatches(...)
drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg
### 3. 3. ** Function not found (name was different) **
Even though I gave the version of OpenCV used in Python to OpenCV3
Scripts written about OpenCV3 may not work.
A detector for calculating ORB features.
\>>> cv2.ORB()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ORB'
\>>> cv2.ORB_create()
<ORB 064E4490>
\>>>
#### **`cv2.__version__But'3.0.0-beta'では、関数名Butcv2.ORB()Not cv2.ORB_create()It has become.`**
Why did you know cv2.ORB_create ()? Start [Python Documentation Server] When you press the [Open Browser] button, the Python library will be displayed in the browser. [C:\Python27\lib\site-packages] Follow the link to and select [cv2]. So I searched the page with "ORB" and found it.
The features added in OpenCV3 are still likely to change significantly. (The description in this article should quickly become obsolete and useless.)
cv2.drawMatches (...) should show the desired matching result for the two images, Only one image is displayed, and it is hard to say that it shows the correspondence. What's wrong?
When I searched for cv2.drawMatches, there was a person who published drawMatches by himself.
Feature calculation and matching using OpenCV --SIFT
Let me use it A graph connecting the corresponding points of the two images with a straight line was displayed safely. (However, there are many points of incorrect mapping, which are due to the feature point descriptor and matching algorithm.)
Note: The original site, where I thought the example script didn't work, should be constantly being revised. Therefore, on this page, I intend to show the idea that beginners and intermediates can try to solve the problem by themselves when they encounter such a problem.
Recommended Posts