Files
Roboteksperimentarium/Examples/opencv2-python/simple/Example1/example1.py
NikolajDanger cea460354e
2022-09-19 13:51:56 +02:00

35 lines
733 B
Python

# This script shows how to open a camera in OpenCV and grab frames and show these.
# Kim S. Pedersen, 2022
import cv2 # Import the OpenCV library
print("OpenCV version = " + cv2.__version__)
# Open a camera device for capturing
cam = cv2.VideoCapture(0)
if not cam.isOpened(): # Error
print("Could not open camera")
exit(-1)
# Open a window
WIN_RF = "Example 1"
cv2.namedWindow(WIN_RF)
cv2.moveWindow(WIN_RF, 100, 100)
while cv2.waitKey(4) == -1: # Wait for a key pressed event
retval, frameReference = cam.read() # Read frame
if not retval: # Error
print(" < < < Game over! > > > ")
exit(-1)
# Show frames
cv2.imshow(WIN_RF, frameReference)
# Finished successfully