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.

  1. install python 2.7.x.
  2. install opencv 3.3.0
    • this step is annoying.
    1. download opencv 3.3.0 from https://sourceforge.net/projects/opencvlibrary/files/opencv-win/
    2. unzip the file and change the folder name to "opencv"
    3. copy and paste "opencv" file to C:\
    4. 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)
    5. go to "C:\opencv\python\2.7\x86\" copy cv2.pyd to "C:\python27\Lib\site-packages"
    6. check installation by using IDLE "import cv2", "print cv2.__version__"
  3. install ffmpeg
    • opencv is heavy rely on ffmpeg, we need to install ffmpeg to make opencv work properly
    1. download the latest version of ffmpeg from http://ffmpeg.zeranoe.com/builds/
    2. unzip the file and change the folder name to "ffmpeg"
    3. copy and paste the folder "ffmpeg" to C:\
    4. go to "C:\opencv\build\bin" copy "opencv_ffmpeg330.dll" to "C:\Python27"
      1. 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
  4. 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

    Popular posts from this blog

    some errors with tensorflow 'object_detection' and preprocessor_pb2