Insatll python 2.7.14 with opencv 3.3.0
WARNING: This is a quick note for myself. So this may not be the proper way for anything in this blog.
I want to use python and opencv for mouse behavioral tracking for my experiments.
Setup the environment of python2.7.14 and opencv3.3.0
update: I found that it is much easier to have python 3.6 with opencv 3.3.0. Please see the other python note for how to setup the environment.
update: I found that it is much easier to have python 3.6 with opencv 3.3.0. Please see the other python note for how to setup the environment.
- install python 2.7.x.
- this step is easy, just download from https://www.python.org/downloads/ and install it.
- install opencv 3.3.0
- this step is annoying.
- download opencv 3.3.0 from https://sourceforge.net/projects/opencvlibrary/files/opencv-win/
- unzip the file and change the folder name to "opencv"
- copy and paste "opencv" file to C:\
- go to "this PC" -> right click, select "properties" -> "Advanced system settings" -> "Environmental Variables" -> chose "Path" in list of system variables -> click "edit " -> "New" -> type in "C:\opencv\build\x86\vc12\bin" (or the correct path to bin in opencv)
- go to "C:\opencv\python\2.7\x86\" copy cv2.pyd to "C:\python27\Lib\site-packages"
- check installation by using IDLE "import cv2", "print cv2.__version__"
- install ffmpeg
- opencv is heavy rely on ffmpeg, we need to install ffmpeg to make opencv work properly
- download the latest version of ffmpeg from http://ffmpeg.zeranoe.com/builds/
- unzip the file and change the folder name to "ffmpeg"
- copy and paste the folder "ffmpeg" to C:\
- go to "C:\opencv\build\bin" copy "opencv_ffmpeg330.dll" to "C:\Python27"
- the name of dll file should be same as the version of opencv. For example, my opencv is 3.3.0, so dll file should be opencv_ffmpeg330.dll
- Test the installation with following code on IDLE
import numpy as np
import cv2
print np.__version__
print cv2.__version__
cap = cv2.VideoCapture("test1.mp4") #0 is 1st camera, 1 is 2nd, or use the video file name
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Comments
Post a Comment