Example of what to do when the sample script does not work (OpenCV-Python)

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.

** 1. There is no input image. ** **

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'.

** 2. Function not found **

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__`**

 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__
\>>> help(cv2.drawMatches)
Help on built-in function 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.)

** 4. Isn't it working as expected? ** **

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

Example of what to do when the sample script does not work (OpenCV-Python)
Notes on what to do when matplotlib scatter () / scatter3d () does not work
What to do when the graph does not appear in jupyter (ipython) notebook
What to do when python3 type venv does not work well on Raspberry Pi
What to do when the jupyterlab extension settings are not reflected
[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement
What to do when PermissionError of tempfile.mkstemp occurs
[EC2] What to do when selenium is stuck and processing does not proceed
What to do if sys / cdefs.h does not exist
What to do when is not in the sudoers file.This incident will be reported.
What to do if the progress bar is not displayed in tqdm of python
What to do when Python starts up in Anaconda does not come out unexpectedly
What to do if Python does not switch from the System version in pyenv
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do when Japanese is not displayed on matplotlib
Check when the Docker container does not connect to the Internet
What to do when Ubuntu crashes
What to do to get tensorflow-gpu to work
[AWS] What to do when the ping command causes a "timeout"
When incrementing the value of a key that does not exist
Solution when background-cover of Linux version VS Code does not work
The story of the release work of the application that Google does not tell
What to do when you get "I can't see the site !!!!"
What to do when the value type is ambiguous in Python?
When the program pip installed on Mac / Marvericks does not work
[Beginner] What to do when "[Errno 2] File b'test.csv' does not exist: b'test.csv" is displayed when reading pandas csv
What to do when a part of the background image becomes transparent when the transparent image is combined with Pillow
What to do if the user name is changed and the pyenv library path does not pass
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do when the result downloaded via scrapy is in English
Script to change the description of fasta
Do not change the order of columns when concatenating pandas data frames.
[Docker] What to do when error Couldn't find the binary git appears
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
What to do when "Something is already running at port 8000" is displayed when the develop command of Gatsby is executed.
What to do if the Chainer (Windows) sample mnist terminates with WinError 183.
What to do if pyenv install does not proceed with an error
Check items when the imported python module does not work as expected
Processing when the key input of Python pygame does not go well.
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do when you get angry that libxml / xmlversion.h does not exist when you put lxml with pip
I want to visualize the transfer status of the 2020 J League, what should I do?
I managed to solve the situation where Python does not work on Mac
What to do if the latest Jupyter Notebook and nb extensions don't work
[python] What to do when an error occurs in send_keys of headless chrome
What to do when "TypeError: must be string, not int…" appears when using strptime
Let's Encrypt updated! What to do if the certbot renew command doesn't work
Solution to the problem that build does not end when installing OpenCV (PEP517)
[Ubuntu 18.04 LTS] What to do when the screen resolution cannot be selected [NVIDIA]
[Verification] Does levelDB take time to register data when the amount of data increases? ??
What to do when "TypeError: data type not understood" appears in python's numpy.zeros
What to do if (base) is displayed at the beginning of the Mac terminal
What to do if rails s doesn't work
After installing php7.2, the php command does not work
What to do if atom autocomplete-python doesn't work
When wildcard specification does not work with pylint
When the Spyder integrated environment fails to work
I will summarize what I was happy to do to get out of the state where I do not know the letter D of Docker
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
[systemd] How to deal with the problem that fancontrol does not work after suspending
What to do when only the window is displayed and nothing is displayed in pygame Note