Skip to content

Instantly share code, notes, and snippets.

@maksimKorzh
Last active April 15, 2024 12:58
Show Gist options
  • Save maksimKorzh/9b8d9f498a76e7f262ece43227545515 to your computer and use it in GitHub Desktop.
Save maksimKorzh/9b8d9f498a76e7f262ece43227545515 to your computer and use it in GitHub Desktop.
Simple web camera view for recording programming videos
#!/usr/bin/python3
############################################
#
# Simple script to display web camera view
# for the video tutorial recording
# purposes
#
# by
#
# Code Monkey King
#
############################################
# import package
import cv2
# init webcam capture stream
capture = cv2.VideoCapture(0)
# window size
WIDTH = 160 # 160
HEIGHT = 120 # 120
# set resolution
capture.set(3, WIDTH) # 160
capture.set(4, HEIGHT) # 120
# create output window
cv2.namedWindow('code', flags=cv2.WINDOW_GUI_NORMAL)
# set window size
cv2.resizeWindow('code', WIDTH, HEIGHT)
# main loop
while True:
# read input webcam stream
material, frame = capture.read()
# render webcam stream in window
cv2.imshow('code', frame)
# handle script exit
if cv2.waitKey(1) == ord('~'):
break
# make clean up
capture.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment