Skip to content

Instantly share code, notes, and snippets.

@keithweaver
Last active October 8, 2024 10:09
Show Gist options
  • Save keithweaver/5bd13f27e2cc4c4b32f9c618fe0a7ee5 to your computer and use it in GitHub Desktop.
Save keithweaver/5bd13f27e2cc4c4b32f9c618fe0a7ee5 to your computer and use it in GitHub Desktop.

Revisions

  1. keithweaver revised this gist Mar 8, 2017. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion start-video-stream-w-opencv.py
    Original file line number Diff line number Diff line change
    @@ -7,17 +7,28 @@
    # Capturing video from webcam:
    cap = cv2.VideoCapture(0)

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

    # Handles the mirroring of the current frame
    frame = cv2.flip(frame,1)

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Saves image of the current frame in jpg file
    # name = 'frame' + str(currentFrame) + '.jpg'
    # cv2.imwrite(name, frame)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break # Press Q to close the frame <-- how to close frame
    break

    # To stop duplicate images
    currentFrame += 1

    # When everything done, release the capture
    cap.release()
  2. keithweaver revised this gist Mar 8, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion start-video-stream-w-opencv.py
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break
    break # Press Q to close the frame <-- how to close frame

    # When everything done, release the capture
    cap.release()
  3. keithweaver created this gist Mar 8, 2017.
    33 changes: 33 additions & 0 deletions start-video-stream-w-opencv.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # For more info: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html
    import cv2
    import numpy as np

    # Playing video from file:
    # cap = cv2.VideoCapture('vtest.avi')
    # Capturing video from webcam:
    cap = cv2.VideoCapture(0)

    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()

    # Potential Error:
    # OpenCV: Cannot Use FaceTime HD Kamera
    # OpenCV: camera failed to properly initialize!
    # Segmentation fault: 11
    #
    # Solution:
    # I solved this by restarting my computer.
    # http://stackoverflow.com/questions/40719136/opencv-cannot-use-facetime/42678644#42678644