欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

图像数据采集与保存

程序员文章站 2022-04-25 19:37:59
...
#!/usr/bin/python3
#coding: utf-8
import cv2
 
## opening videocapture
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
## some videowriter props

sz = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
        int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fps = 10
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
#fourcc = cv2.VideoWriter_fourcc('m', 'p', 'e', 'g')
#fourcc = cv2.VideoWriter_fourcc(*'mpeg')
 
## open and set props
vout = cv2.VideoWriter()

id = 9
cnt = 0
print('cap begin')
save_path = '{}{}{}'.format('C:/Users/Administrator/Desktop/get-hand-data/', str(id), '/')
vout.open(save_path+str(id)+'.mp4',fourcc,fps,sz,True)
while (cap.isOpened()):
    cnt += 1
    
    ret, frame = cap.read()
    if ret == True:
      #cv2.putText(frame, str(cnt), (10, 20), cv2.FONT_HERSHEY_PLAIN, 1, (0,255,0), 1, cv2.LINE_AA)
      print(cnt)
      cv2.imshow('frame', frame)
      cv2.waitKey(1)
      #frame = cv2.resize(frame, (1920, 1080), interpolation=cv2.INTER_AREA)
      tmp_name = save_path + str(cnt) + '.jpg'
      print('tmp_name',tmp_name)
      cv2.imwrite(tmp_name, frame)
      vout.write(frame)
print('cap end')
vout.release()
cap.release()

 

相关标签: data