重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

python实现从本地摄像头和网络摄像头截取图片功能-创新互联

python-----从本地摄像头和网络摄像头截取图片 ,具体代码如下所示:

创新互联专注于长乐企业网站建设,响应式网站,商城网站建设。长乐网站建设公司,为长乐等地区提供建站服务。全流程按需定制开发,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
import cv2
# 获取本地摄像头
# folder_path 截取图片的存储目录
def get_img_from_camera_local(folder_path):
  cap = cv2.VideoCapture(0)
  i = 1
  while True:
    ret, frame = cap.read()
    cv2.imshow("capture", frame)
    print str(i)
    cv2.imwrite(folder_path + str(i) + '.jpg', frame) # 存储为图像
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
    i += 1
  cap.release()
  cv2.destroyAllWindows()
# 获取网络摄像头,格式:rtsp://username:pwd@ip/
# folder_path 截取图片的存储目录
def get_img_from_camera_net(folder_path):
  cap = cv2.VideoCapture('rtsp://username:pwd@ip/')
  i = 1
  while True:
    ret, frame = cap.read()
    cv2.imshow("capture", frame)
    print str(i)
    cv2.imwrite(folder_path + str(i) + '.jpg', frame) # 存储为图像
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
    i += 1
  cap.release()
  cv2.destroyAllWindows()
# 测试
if __name__ == '__main__':
  folder_path = 'D:\\img_from_camera\\'
  get_img_from_camera_local(folder_path)

当前题目:python实现从本地摄像头和网络摄像头截取图片功能-创新互联
当前网址:http://cqcxhl.cn/article/jesgc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP