How to use OpenCV in Python?

非 Y 不嫁゛ 提交于 2019-11-28 06:17:21

The problem was resolved. The following steps has been done:

  1. A new version of python (version 2.7) has been installed.
  2. After that I still was unable to run OpenCV because I had some problems with the numpy library.
  3. I tired to install numpy but the installer did not see my new version of the Python.
  4. I deleted the old version of Python as well as links to the old version in the Path system vatriable.
  5. After that numpy installer was not able to finish the installation.
  6. I have realized that I need to run another numpy installer that is associated with the Python 2.7. It can be found here.
  7. Finally everything worked. I was able to "import cv".

I suspect you have the same problem I've run into. If you have a 64-bit version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to compile them yourself. There are some instructions on the OpenCV Wiki, but it's not for the faint of heart. Expect to have a substantial time investment.

The easiest solution is to:

  1. Uninstall 64-bit Python
  2. Install a 32-bit distribution.

The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. The only limitation is that it's 32-bit, so don't make plans to process gigapixel astronomy data with it! ;)

If you must have the 64-bit version, follow these instructions to get it OpenCV to compile with Visual Studio 2010. There's a discussion on stackoverflow that describes building 64-bit apps with VC Express.

EDIT: OpenCV now ships with 64-bit Python binaries. The .dll files need to go somewhere in your path (I put them in the scripts folder), and the .pyd files go in your site-packages directory.

I had trouble interfacing OpenCV with Python, and I was looking all over the place for help. Here's what worked for me. I basically followed this post: http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html. After downloading and extracting OpenCV 2.4.6, you basically get a folder called "opencv" with a bunch of stuff in it. Navigate to build->python->2.7. Inside, there is only one file called "cv2.pyd". I copied this file and pasted it in "python-2.7.5\Lib\site-packages". I'm actually using the Spyder IDE, and it works fine. In the python interpreter, typing in "import cv" worked for me.

Maybe you should edit your environment variable
right click on the "My Computer" or something like this, click on properties.

In the properties window click on the Advanced tab.
Then, the environment variables button.
Change the path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!