Created
July 25, 2019 06:27
-
-
Save chenminhua/08b9cfc7fadaefec37f5063ea3836114 to your computer and use it in GitHub Desktop.
opencv camera snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
# cam = cv2.VideoCapture(0) # local camera | |
# cam = cv2.VideoCapture("/path/to/video") # open video | |
cam = cv2.VideoCapture("rtsp://admin:password123@192.168.1.64:554") | |
# 设置摄像头尺寸 | |
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 64) | |
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 48) | |
# 获取摄像头尺寸 | |
while True: | |
ret, frame = cam.read() | |
if ret == True: | |
cv2.imshow('frame', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
else: | |
break | |
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
cap = cv2.VideoCapture(0) | |
fourcc = cv2.VideoWriter_fourcc(*'XVID') | |
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (1280, 720)) | |
while(cap.isOpened()): | |
ret, frame = cap.read() | |
if ret == True: | |
out.write(frame) | |
cv2.imshow('frame', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break else: | |
break | |
# Release everything if job is finishedcap.release() | |
out.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment