利用python从相机中读取一个图片,再切分成两部分,再保存成文件

import cv2
import numpy
import matplotlib.pyplot as plot
cap = cv2.VideoCapture(0)
cap.set(3,1280)
cap.set(4,480)
k=0
#sleep(100)
while(1):
   ret, frame = cap.read()
   cv2.imshow("capture",frame)
   frame1 = frame[:,0:640,:]
   #cv2.imshow("split1",frame1)
   cv2.imwrite(str(k)+'left'+'.jpg',frame1)
   frame2 = frame[:,640:1280,:]
   #cv2.imshow("split2",frame2)
   cv2.imwrite(str(k)+'right'+'.jpg',frame2)
   k=k+1
   if cv2.waitKey(5000) & 0xFF == ord('q'):
      break
cap.release()
cv2.destroyAllWindows()

你可能感兴趣的:(ubuntu系统常用)