Skip to content

Instantly share code, notes, and snippets.

@vb100
Created July 11, 2017 19:57
Show Gist options
  • Save vb100/ba530715a038fe8cfe449f1dd3963125 to your computer and use it in GitHub Desktop.
Save vb100/ba530715a038fe8cfe449f1dd3963125 to your computer and use it in GitHub Desktop.
Stream live video directly from external camera to Python. Exit with 'Q' key.
import cv2, time
#1. Create an object. Zero for external camera
video=cv2.VideoCapture(0)
#7. Play the video (Indenting)
#8. a variable
a=0
while True:
a = a + 1
#3. Create a frame object
check, frame = video.read()
print(check)
print(frame) #Reresenting image
#6. Converting to Graycolor
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#time.sleep(3)
#4. Show the frame
#cv2.imshow("Capturing", frame)
#6.1.
cv2.imshow("Capturing", gray)
#5. For press any key to out (miliseconds)
#cv2.waitKey(0)
#7. For playing
key=cv2.waitKey(1)
if key == ord('q'):
break
print(a)
#2. Shut down the camera
video.release()
cv2.destroyAllWindows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment