Skip to content
Alec Graves edited this page Apr 18, 2018 · 3 revisions

How to opencv (with python)

Install python on your computer:

  1. Go to https://www.anaconda.com/download/
  2. download install python 2.7 version for your os
    1. Windows set-up instructions:
      1. Open the conda .exe
      2. Choose an installation location (use the default if you are unsure, only for your user)
      3. Make sure the checkbox that asks if you want to add to PATH is checked!
        1. If you miss this, just uninstall and repeat installation process.
        2. Or add conda to your path manually if you are elite.
    2. Linux set-up instructions:
    cd ~/Downloads/
    sudo bash <minicondafile.sh>
    <go through setup>
    <yes you want to add to path>
    

Install OpenCV

  1. Open the terminal
  2. conda install -c menpo opencv

A simple OpenCV program (for reference)

test.py

import cv2

print(cv2.__version__)

cap = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
    ans = False
    while ans == False:
        ret, frame = cap.read()
        ans = ret

    # Our operations on the frame come here
    frame = cv2.flip(frame, flipCode=1) 
    # ^ that command flips the image about y axis, making the camera act like a mirror

    # Display the resulting frame
    cv2.imshow('frame', frame)

    #pause, allowing the image to be displayed
    if cv2.waitKey(1)== ord('q'):
        break #quit if you press q during the pause

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

( to run it from the terminal: python test.py)

An awesome object-tracking tutorial for OpenCV

https://thecodacus.com/opencv-object-tracking-colour-detection-python/