python调用相机和双目相机
生活随笔
收集整理的這篇文章主要介紹了
python调用相机和双目相机
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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調用雙目相機
# -*- coding: utf-8 -*- import cv2 import timeAUTO = False # 自動拍照,或手動按s鍵拍照 INTERVAL = 2 # 自動拍照間隔 cv2.namedWindow("left") cv2.namedWindow("right") cap = cv2.VideoCapture(0) # 設置分辨率左右攝像機同一頻率,同一設備ID;左右攝像機總分辨率2560x720;分割為兩個1280x720 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 counterpath = folder + pos + "_" + str(counter) + ".jpg"cv2.imwrite(path, frame)print("snapshot saved into: " + path) while True:ret, frame = cap.read()print("ret:", ret)# 裁剪坐標為[y0:y1, x0:x1] HEIGHT * WIDTH,#雙目相機是兩個在一起的,通過剪切坐標位置可以單獨分開相機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 += 1utc = nowkey = cv2.waitKey(1)if key == ord("q"):breakelif 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
總結
以上是生活随笔為你收集整理的python调用相机和双目相机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习笔记21.07.10:绘制页面组合图
- 下一篇: 基于python-opencv和PIL的