Import OpenCV in Pycharm [duplicate] - opencv

This question already has answers here:
How to install OpenCV on Windows and enable it for PyCharm without using the package manager
(3 answers)
Closed 4 years ago.
I want to use OpenCV (Python module) in pycharm. I set my Python interpreter in settings and added OpenCV path (C:\opencv\build\python\2.7) to the Python interpreter path. Unfortunately pycharm couldn't import OpenCV. It's noticeable that I see the cv2.pyd in the left panel (project panel).
Can anyone help me to resolve this issue ?

Refer to How to install OpenCV on Windows and enable it for PyCharm without using the package manager
Steps to follow:
Install Python 2.7.10
Install Pycharm(If you have not done it already)
Download and install the OpenCV executable.
Add OpenCV in the system path(%OPENCV_DIR% = /path/of/opencv/directory)
Goto C:\opencv\build\python\2.7\x86 folder and copy cv2.pyd file.
Goto C:\Python27\DLLs directory and paste the cv2.pyd file.
Goto C:\Python27\Lib\site-packages directory and paste the cv2.pyd file.
Goto PyCharm IDE and goto DefaultSettings>PythonInterpreter.
Select the Python which you have installed on Step1.
Install the packages numpy,matplotlib and pip in pycharm.
Restart your PyCharm.
PyCharm now has OpenCV library installed and working.
If you have installed pycharm,then you can type :
pip install opencv-python
after satisfied,
then go to file ,setting (in pycharm)
project ,project interpreter,click on plus icon on the top right ,
search opencv-python and install package.

Related

Problem using opencv in visual studio code

I installed openCV and vsc sees this import. However, when the program executes, an error pops up.
I have no idea where the bug is
make sure you select the right interpreter (or virtual environment)
re-select python interpreter in VSCode
reinstall the opencv library in the right interpreter:
pip3 install --force-reinstall opencv-contrib-python
also, you can use Anaconda to manage your packages

Installing OpenCV into PyCharm

Idk if this is a stackoverflow-appropriate post so forgive if the question is misplaced. I'm trying to install OpenCV into my Pycharm IDE through the conda virtual environment. I typed conda install -c conda-forge opencv inside the PyCharm terminal and it has been doing this for 11 hours and God knows how many more to go.
Pycharm did this with PyTorch as well. Am I doing something wrong or is this normal?
While you can install packages directly in PyCharm by going to file->settings select Project Interpreter and click on the '+' icon on the top right (see image)
I would recommend creating a requirements.txt file in the root of your project, and write down all your required packages. When a package is missing, PyCharm will automatically suggest to install the package for you.
e.g. for installing opencv you can add the following to you requirements.txt
opencv-python
Or even specify the version that your project needs
opencv-python==4.1.2
edit: the advantage of using a requirement.txt is that you can more easily port the project to another machine, and re-install the packages if needed.

How to add custom Opencv library into pycharm

Basically I am developing a project using OpenVino and OpenCV,to do so I cannot use the normal and easy way of using pip to install opencv library but instead Intel provided their own optimized version OpenCV.
I cannot find a place to add the path for the custom OpenCV in pycharm.
If anybody can enlighten me,please do so.
Thank you in advance.
please try the below steps.
Install Python 2.7.10
Install Pycharm(If not installed previously)
Download the OpenCV executable.
Install OpenCV
Add OpenCV in the system path(%OPENCV_DIR% = /path/of/opencv/directory)
Goto C:\opencv\build\python\2.7\x86 folder and copy cv2.pyd file.
Goto C:\Python27\DLLs directory and paste the cv2.pyd file.
Goto C:\Python27\Lib\site-packages directory and paste the cv2.pyd file.
Goto PyCharm IDE and goto DefaultSettings>PythonInterpreter.
Select the Python which you have installed on Step1.
Install the packages numpy,matplotlib and pip in pycharm.
Restart your PyCharm.
PyCharm now has OpenCV library installed and working.
Hope this will solve your issue

How can I compile opencv from source at Win 10

I read this and this, and saw the videos, but looks I did not understand the required :(
I need to compile opencv from source in order to be able to use CV-Rust at my application, what I did is:
1- Downloaded and installed Visual Studio 2015 with Visual C++ option.
2- Downloaded and installed CUDA
3- Downloaded and installed Python
4- Downloaded and installed Tortoisegit
5- Downloaded and installed 7-zip
6- Downloaded and installed Miktex
7- Downloaded and installed DoxyGen
8- Upgraded the pip python -m pip install --upgrade pip and installed the below packages:
8-1- Setuptools as pip install setuptools
8-2- Sphinx as pip install -U Sphinx
8-3- NumPy as pip install NumPy
9- Downloaded and extracted the following, and put all the extracted folders in a seperate folder called it dep:
9-1- Threading Building Blocks 2018 Update 6 _win.zip
9-2- OpenEXR .tar.gz
9-3- Eigen .zip
10- Downloaded and unzipped the OpenCV winpack
11- Closed in another folder the OpenCV github using Tortoisegit
What is required now!
I'll summarize the issue I raised at github and its solution below:
It looks I was having some conflicts in my machine setup:
I was not having required permission to execute scripts as the PS, so I added the required permission as mentioned here, by writing:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Also, I was installing VS2017 and VS2015 which was appeared to be causing some kind of conflict, so I uninstalled VS2017 as shown here and removed Win10 SDK as well.
Confirmed Cmake is installed properly and added to the path, by running cmake -version
Then I downloaded the cv-rs repository.
Then created directory C:\opencv
In the file explorer, enabled see hidden folders, to see the .git
Then copied both .git and .windows folders to the C:\opencv
Opened powershell console as administrator in c:\opencv
Run the below commands in PS:
PS C:\opencv> git reset --hard
PS C:\opencv> git submodule update
PS C:\opencv> .\.windows\msvc_2_build_OCV.ps1 -EnableCuda $False -Compiler vc14
It will take sometime running the script and configuring opencv.

OpenCV Install for Pydev in Eclipse using Macports on OsX Mavericks

I used the following tutorial to install macports and opencv:
http://www.jeffreythompson.org/blog/2012/09/21/installing-opencv-for-python-on-mac-lion/
It works in that after typing "python" I can call "import cv" without errors.
My first question: how do I get this to work with IDLE. I think the issue is via the terminal I'm using Python 2.7.5. IDLE is using Python 2.7.3. If this is the problem, what is the easiest way to fix this.
My second question: how do I get opencv to work in eclipse with pydev? I can't really find much helpful information. I have installed opencv via macports. But I can't get Eclipse to recognize that opencv has been installed. "Import cv" command says no module named cv exists.
I was struggling with this problem today. Here are the steps I followed using macports
Install macports and xcode
Follow Sam Khans post listed here to install python, relink it in your terminal and then install OpenCV:
http://samkhan13.wordpress.com/2012/06/18/using-opencv-with-python-on-your-mac-os-x/
NOTE: At this point you should be able to enter a terminal session and type "python" and then "import cv2" successfully.
Open eclipse and click on "eclipse" then "preferences" in the bar menu at the top of the program.
In the pop-up that appears click the arrow next to "pydev" to expand the menu then click "Interpreter - Python"
Press the "new" button on the right of the window
In the pop-up type in the name for this interpreter (I did python27 for my python2.7 version)
Next link the python executable for the desired version under the macports install tree "/opt/local/bin/pythonX.X" where X.X is your version (i.e. 2.7) and click ok.
A list of the available python libraries should populate. Select only those under the macport install tree (so we don't confuse our interpreter and cross list with another python build)
Finally click OK (which should automatically apply the changes).
The window will compile the interpreter and VOILA Python, Numpy and OpenCV working together through pydev in eclipse.

Resources