Skip to content

Instantly share code, notes, and snippets.

@bcattle
Created August 1, 2019 20:29
Show Gist options
  • Save bcattle/eedbdbe5c80c743b2b77ba3ede49ec46 to your computer and use it in GitHub Desktop.
Save bcattle/eedbdbe5c80c743b2b77ba3ede49ec46 to your computer and use it in GitHub Desktop.
Simple python code to capture images from a webcam
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# Install OpenCV with
# pip install opencv-python
# https://stackoverflow.com/questions/26583316/python-3-capture-image
# https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html
import cv2
import matplotlib.pyplot as plt
cam = cv2.VideoCapture(0)
s, img = cam.read()
print("Frame default resolution: (" + str(cam.get(cv2.CAP_PROP_FRAME_WIDTH))
+ "; " + str(cam.get(cv2.CAP_PROP_FRAME_HEIGHT)) + ")")
def set_res(cap, x,y):
cap.set(cv2.CV_CAP_PROP_FRAME_WIDTH, int(x))
cap.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, int(y))
return str(cap.get(cv2.CV_CAP_PROP_FRAME_WIDTH)),
str(cap.get(cv2.CV_CAP_PROP_FRAME_HEIGHT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment