Skip to content

Instantly share code, notes, and snippets.

@zhanghang1989
Created May 27, 2017 02:55
Show Gist options
  • Save zhanghang1989/b413e065041b9bd8679f9b142601ca1d to your computer and use it in GitHub Desktop.
Save zhanghang1989/b413e065041b9bd8679f9b142601ca1d to your computer and use it in GitHub Desktop.
Python Opencv Camera Show
import cv2
def run_demo(mirror=False):
cam = cv2.VideoCapture(0)
cam.set(3, 640)
cam.set(4, 480)
key = 0
while True:
# read frame
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
cv2.imshow('my webcam', img)
key = cv2.waitKey(1)
if key == 27:
break
cv2.destroyAllWindows()
def main():
run_demo(mirror=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment