cv2 Python library - python

Hi I am facing some issue while installing the library cv2 in python. I want to create a cctv camera in pythin, and after watching some tutorial, I found out that I need to import cv2 in the code. I have installed the library, and typed"import cv2" in vs code, and found out that vs code is highlighting the cv2, as error. The error says "Import 'cv2' could not be resolved". I have checked if cv2 is installed and found out that cv2 is installed in the computer.
I have checked the cv2 version on a python interpreter:
Cv2 version on Python 3.10 interpreter
Error image in vs code:
Image of the error in VS studio code
I have tried many solutions, but could not find any solutions.

Related

Symbol not found when importing cv2

I am attempting to import cv2 using python. When I use the import cv2 function in jupyter notebook I get a string of code indicating that the symbol is not found and therefore cv2 cannot be imported. enter image description here
I have tried updating opencv code using various code in my terminal including pip install opencv-python in both my terminal and my jupyter environment. Each time it said that the opencv is installed and that both environments are running on anaconda3 as expected.
Either upgrade your OS-X or install an older version of OpenCV (and python)

OpenCV in Python using Pycharm [duplicate]

I have opencv-python installed and the .pyd file is added in the site-packages and the DLLs. The code works with images. When I want to read, show, write an image it works. But I get a warning that the functions' references cannot be found in init.py . Due to this, I can not use the auto-complete feature. Could someone help me out? I am using opencv 3.4.0 and python 3.6.4 in pycharm. I downloaded opencv via pip in the command prompt.
The problem is caused by CV2 and how __init__.py does the imports. Just ignore the warnings the program will work all the same, or you can do an import with an alias like:
import cv2.cv2 as cv2
If you have a warning on it press Alt+Enter to install and fix it. Now you will have the code completion and no other warnings (about that) on the project.
Switching to an older version of opencv solved this problem for me.
Apparently pycharm sometime breaks depending on the version of opencv. For me, the newest version was, 4.6.X unstalling and installing 4.5.X did the trick.
I use python 3.10 and my newest version for opencv is 4.6.0.66 ,by changing opencv version to 4.5.5.62 and with an alias: import cv2.cv2 as cv2 my problem has solved.
Import cv2 as follows:
from cv2 import cv2
I installed version 4.5.5.64 and imported with an alias.
import cv2.cv2 as cvv2
I was using Python 3.10.2288.0 and OpenCV 1.6.0.66.
I resolved the issue by rolling back the OpenCV version to 4.5.5.62.

How to resolve this error of "Cannot find reference 'imread' in '__init__.py" in python after installing opencv?

I am new to python and installed opencv by typing: pip install opencv-contrib-python in the command prompt.
Below I have shown a very simple example of reading in an image and showing it on the screen:
However, I get this error:
When I hover over the imread method in PyCharm, it says Cannot find reference 'imread' in '__init__.py'
It was showing import and runtime errors when I typed import cv2 and import numpy in the command prompt.
I tried going back to the previous version of NumPy by typing pip install --force-reinstall numpy=1.19.3. So, now when I type import cv2 and import numpy in the command prompt, it shows no error but it says it still can't find a reference to it in PyCharm.
I am using Python 3.9.1 with pip 20.2.3.
If you are using python interpreter with anaconda change it to default python one. if you have not installed python separately then install it and assign the path to it.
somewhat this will be the path
c://user/APpData/Local/Programs/Python/python39/python.exe
The NumPy multicore import error is a result of installing NumPy on Windows that is incompatible with the version of OpenCV that you have. Judging from your screenshots as well as the error, you are running Windows. Try installing Christoph Gohlke's NumPy libraries instead that were built with multicore support enabled.
First do:
pip install pipwin
Then:
pipwin install numpy
This should hopefully settle the OpenCV dependency problem you have.
To solve it, you should upgrade numpy installation. Try:
pip install -U numpy
For information here
Instead of doing:
import cv2
try doing:
from cv2 import cv2
This worked for me after a lot of troubleshooting also using pycharm. I now have access to all of the regular cv2 methods.

What is the different between opencv-python library and cv2 library?

I am trying to use openCV. Normally, When I run command panel on desktop, I can see version of my openCV:
But when I couldn't import to my project. Normally, I was adding opencv-python library from interpreter but I builded cv2 library which version is 4.4.0 to use gpu. So I haven't got a opencv-python library at site-packages but I have cv2 file in site-packages. Unfortunately I couldn't import it to my project. How can I use this opencv version or file which name is cv2.cp37-win_amd64.pyd?
I can use all other libraries in site-packages. But when I couldn't add cv2 library. Here the a basic image read from file :
The interesting part of the problem is, all cv2 function cannot be found but program is working :D I am really confused.
cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.
The IDE probably doesn't recognize the cv2 commands because you are using a 64 bit version of opencv-python on a 32 bit version of Python or vice-versa. I believe this can be resolved by uninstalling your current OpenCV installation using pip uninstall opencv-python and then reinstalling it with the correct version following the linked tutorial.
Sources / Additional Links:
Install Tutorial: https://www.youtube.com/watch?v=Z78zbnLlPUA

Unable to import cv2 OpenCV 2.4.13 in python 3.6

import cv2
On executing the above code, it shows the following error.
Error:
Traceback (most recent call last) in
()
----> 1 import cv2
ImportError: DLL load failed: The specified module could not be found.
Unable to import cv2 in python
I have installed OpenCV 2.4.13 and Anaconda3 with python 3.6.4.
OpenCV location:C:\Users\harsh\Anaconda3
Anaconda location:C:\Users\harsh\opencv.
I have also added cv2.pyd in C:\Users\harsh\Anaconda3\Lib\site-packages.
Try pip install opencv-python instead of pip install cv2. Although the name of the package changes, you can still import it as import cv2, It will work.
Have also experienced some issues with OpenCV and Anaconda. Anaconda can fetch only OpenCV 2.4, that might not suit your versions. You should try install OpenCV this way
pip install opencv-python
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
If the problem still persists try using Dependency walker to find out where specifically your problems stem from and then try fixing them individually.
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
If the problem still persists feel free to add comments.

Categories

Resources