如何利用opencv实现捕获摄像头并且显示出来
Admin 2022-08-15 群英技术资讯 482 次浏览
1、捕获摄像头和实时显示
import cv2 import numpy as np import pickle import matplotlib.pyplot as plt cap = cv2.VideoCapture(0) while True: ret,frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()
2、从摄像头内抓拍图片
import cv2 import numpy as np import pickle import matplotlib.pyplot as plt cap = cv2.VideoCapture(0) index = 0 while True: ret,frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame',gray) if cv2.waitKey(1) & 0xFF == ord('p'): cv2.imwrite("kk.jpg",frame) index = index + 1 if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了通过Pygame模块实现监听鼠标的功能,文章的示例代码讲解详细,对我们的学习或工作有一定的价值,感兴趣的小伙伴可以了解一下
这篇文章主要介绍了Python 权限控制模块 Casbin,Casbin是一个强大的、高效的开源访问控制框架,其权限管理机制支持多种访问控制模型,更多相关内容感兴趣的朋友可以参考下面文章内容
Scipy是Python算法库和数学工具包,包括最优化、线性代数、积分、插值、特殊函数、傅里叶变换等模块。scipy.optimize模块中提供了多个用于非线性规划问题的方法,适用于不同类型的问题。本文将利用起解决经济调度问题,感兴趣的可以了解一下
本文主要介绍了Python中Tkinter组件Listbox的具体使用,Listbox组件用于显示一个选择列表,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了Python pyecharts绘制柱状图,文章介绍的柱状/条形图,通过柱形的高度/条形的宽度来表现数据的大小,感兴趣的小伙伴一起进入文章学习更详细内容吧<BR>
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008