banner



How To Install Conda Windows

I have summarized my now fully working solution, OpenCV-Python - How to install OpenCV-Python package to Anaconda (Windows). Even so I've copied and pasted the important bits to this post.


At the time of writing I was using Windows 8.1, 64-bit machine, Anaconda/ Python 2.10. (come across notes beneath - this works besides for Windows 10, and likely Python 3.x too).

  • NOTE ane: as mentioned mentioned by @great_raisin (cheers) in comment section however, this solution appears to also work for Windows 10.

  • Annotation ii: this will probably work for Anaconda/Python 3.ten as well. If you are using Windows 10 and Anaconda/Python 3.x, and this solution works, please add a comment below. Thanks! (Update: noting from comment "Working on Windows ten")

  • NOTE 3: depending on whether you are using Python 2.x or 3.x, just adjust the impress statement accordingly in code snippets. i.e. in Python 3.x it would be print("howdy"), and in Python two.10 information technology would be print "howdy".

TL;DR

To use OpenCV fully with Anaconda (and Spyder IDE), nosotros need to:

  1. Download the OpenCV parcel from the official OpenCV site
  2. Copy and paste the cv2.pyd to the Anaconda site-packages directory.
  3. Set user environmental variables and so that Anaconda knows where to find the FFMPEG utility.
  4. Do some testing to confirm OpenCV and FFMPEG are now working.

(Read on for the detail instructions...)

Prerequisite

Install Anaconda

Anaconda is substantially a nicely packaged Python IDE that is shipped with tons of useful packages, such as NumPy, Pandas, IPython Notebook, etc. It seems to be recommended everywhere in the scientific customs. Check out Anaconda to become it installed.

Install OpenCV-Python to Anaconda

Cautious Note: I originally tried out installing the binstar.org OpenCV package, every bit suggested. That method however does not include the FFMPEG codec - i.e. yous may be able to utilize OpenCV, but yous won't exist able to process videos.

The post-obit instruction works for me is inspired by this OpenCV YouTube video. So far I have got information technology working on both my desktop and laptop, both 64-flake machines and Windows 8.1.

Download OpenCV Packet

Firstly, get to the official OpenCV site to download the complete OpenCV package. Pick a version you like (two.10 or 3.ten). I am on Python 2.x and OpenCV three.x - mainly because this is how the OpenCV-Python Tutorials are setup/based on.

In my instance, I've extracted the parcel (essentially a folder) straight to my C drive (C:\opencv).

Re-create and Paste the cv2.pyd file

The Anaconda Site-packages directory (e.g. C:\Users\Johnny\Anaconda\Lib\site-packages in my instance) contains the Python packages that you lot may import. Our goal is to copy and paste the cv2.pyd file to this directory (and so that nosotros can use the import cv2 in our Python codes.).

To do this, copy the cv2.pyd file...

From this OpenCV directory (the beginning part might exist slightly different on your machine). For Python 3.x, I judge, only change the 2.ten to three.10 accordingly.

          # Python two.vii and 32-bit machine: C:\opencv\build\python\two.7\x84  # Python 2.7 and 64-bit machine: C:\opencv\build\python\2.7\x64                  

To this Anaconda directory (the beginning part might be slightly different on your car):

          C:\Users\Johnny\Anaconda\Lib\site-packages                  

Subsequently performing this step we shall now be able to use import cv2 in Python code. Just, we still demand to do a little bit more work to get FFMPEG (video codec) to work (to enable us to do things like processing videos).

Set Ecology Variables

Correct-click on "My Computer" (or "This PC" on Windows eight.i) → left-click Backdrop → left-click "Advanced" tab → left-click "Environment Variables..." button.

Add a new User Variable to point to the OpenCV (either x86 for 32-flake system or x64 for 64-scrap system). I am currently on a 64-bit machine.

          | 32-fleck or 64 bit automobile? | Variable     | Value                                | |---------------------------|--------------|--------------------------------------| | 32-bit                    | `OPENCV_DIR` | `C:\opencv\build\x86\vc12`           | | 64-flake                    | `OPENCV_DIR` | `C:\opencv\build\x64\vc12`           |                  

Suspend %OPENCV_DIR%\bin to the User Variable PATH.

For example, my PATH user variable looks similar this...

Before:

          C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts                  

After:

          C:\Users\Johnny\Anaconda;C:\Users\Johnny\Anaconda\Scripts;%OPENCV_DIR%\bin                  

This is it we are done! FFMPEG is ready to be used!

Test to confirm

We need to test whether we tin now do these in Anaconda (via Spyder IDE):

  • Import OpenCV package
  • Utilize the FFMPEG utility (to read/write/procedure videos)

Test 1: Can nosotros import OpenCV?

To ostend that Anaconda is now able to import the OpenCV-Python package (namely, cv2), event these in the IPython console:

          import cv2 print cv2.__version__                  

If the packet cv2 is imported OK with no errors, and the cv2 version is printed out, and then we are all skilful! Hither is a snapshot:

import-cv2-ok-in-anaconda-python-2.png
(source: mathalope.co.uk)

Test 2: Tin can nosotros Employ the FFMPEG codec?

Identify a sample input_video.mp4 video file in a directory. We want to examination whether we can:

  • read this .mp4 video file, and
  • write out a new video file (can exist .avi or .mp4 etc.)

To practise this we need to have a exam Python lawmaking, call it exam.py. Identify information technology in the aforementioned directory as the sample input_video.mp4 file.

This is what test.py may look like (I've listed out both newer and older version codes here - practice let usa know which i works / not work for you!).

(Newer version...)

          import cv2 cap = cv2.VideoCapture("input_video.mp4") impress cap.isOpened()   # True = read video successfully. Fake - fail to read video.  fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter("output_video.avi", fourcc, xx.0, (640, 360)) print out.isOpened()  # True = write out video successfully. Faux - fail to write out video.  cap.release() out.release()                  

(Or the older version...)

          import cv2 cv2.VideoCapture("input_video.mp4") print cv2.isOpened()   # True = read video successfully. Imitation - fail to read video.  fourcc = cv2.cv.CV_FOURCC(*'XVID') out = cv2.VideoWriter("output_video.avi",fourcc, 20.0, (640,360)) print out.isOpened()  # Truthful = write out video successfully. False - neglect to write out video.  cap.release() out.release()                  

This test is VERY Important. If you lot'd like to process video files, you'd need to ensure that Anaconda / Spyder IDE can use the FFMPEG (video codec). It took me days to take got it working. But I promise it would have you lot much less fourth dimension! :)

Note: 1 more very important tip when using the Anaconda Spyder IDE. Make certain you check the electric current working directory (CWD)!!!

Conclusion

To use OpenCV fully with Anaconda (and Spyder IDE), nosotros need to:

  1. Download the OpenCV bundle from the official OpenCV site
  2. Copy and paste the cv2.pyd to the Anaconda site-packages directory.
  3. Set user ecology variables so that Anaconda knows where to find the FFMPEG utility.
  4. Do some testing to confirm OpenCV and FFMPEG are now working.

Good luck!

Source: https://stackoverflow.com/questions/23119413/how-do-i-install-python-opencv-through-conda

Posted by: daileystrue1978.blogspot.com

0 Response to "How To Install Conda Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel