python操作摄像头
- 前言
- 一、直接展示代码
- 总结
前言
一篇文章让你能用python来调用你笔记本的摄像头,进行拍照保存指定位置,进行更多操作。
一、直接展示代码
import os
import cv2
def video_demo(e):
if not os.path.exists(e):
os.makedirs(e)
print("开始")
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
i = 1
while True:
ret,frame = cap.read()
frame = cv2.flip(frame,1)
cv2.imshow("window",frame)
if cv2.waitKey(1) & 0xff == ord('w'):
cv2.imwrite(f"{e}/{i}.jpg", cv2.resize(frame, (224, 224), interpolation=cv2.INTER_AREA))
print(f"{i}.jpg已保存")
i += 1
if cv2.waitKey(1) & 0xff == ord('q') or cv2.getWindowProperty('window', cv2.WND_PROP_VISIBLE) < 1:
break
cap.release()
video_demo('img')
总结
在此提醒,若果笔记本摄像头有手动开关的记得打开,否则就会报错。至于为什么会提醒呢,就不说了,只能说博主~
有想要了解更多的可以点击这里
最后
以上就是细腻小海豚最近收集整理的关于python操作摄像头前言一、直接展示代码总结的全部内容,更多相关python操作摄像头前言一、直接展示代码总结内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复