python调用相机
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
while ret:
ret, frame = cap.read()
cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cap.release()
python调用双目相机
import cv2
import time
AUTO = False
INTERVAL = 2
cv2.namedWindow("left")
cv2.namedWindow("right")
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2560)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
counter = 0
utc = time.time()
folder = "./SaveImage/"
def shot(pos, frame):
global counter
path = folder + pos + "_" + str(counter) + ".jpg"
cv2.imwrite(path, frame)
print("snapshot saved into: " + path)
while True:
ret, frame = cap.read()
print("ret:", ret)
left_frame = frame[0:720, 0:1280]
right_frame = frame[0:720, 1280:2560]
cv2.imshow("left", left_frame)
cv2.imshow("right", right_frame)
now = time.time()
if AUTO and now - utc >= INTERVAL:
shot("left", left_frame)
shot("right", right_frame)
counter += 1
utc = now
key = cv2.waitKey(1)
if key == ord("q"):
break
elif key == ord("s"):
shot("left", left_frame)
shot("right", right_frame)
counter += 1
cap.release()
cv2.destroyWindow("left")
cv2.destroyWindow("right")
![在这里插入图片描述](https://img-blog.csdnimg.cn/34bbfe8b8cff4adf9866b9b71795f5aa.png?x-oss-process=image/watermark,type_d3F5LXplb
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)