import numpy as np
import cv2
import time
from hobot_vio import libsrcampy as srcampy
fourcc = cv2.VideoWriter_fourcc(*"XVID")
fps = 20
frame_size = (1920, 1080)
writer = cv2.VideoWriter("out.avi",fourcc, fps, frame_size)
cam_x3pi = srcampy.Camera()
x3pi = cam_x3pi.open_cam(0,1,30,1920,1080)
start = int(time.time())
for i in range(0,fps*10):
origin_image_x3pi = cam_x3pi.get_img(2,1920,1080)
nv12_x3pi = np.frombuffer(origin_image_x3pi,dtype=np.uint8).reshape(1080*3//2,1920)
bgr_x3pi = cv2.cvtColor(nv12_x3pi,cv2.COLOR_YUV2BGR_NV12) # COLOR_YUV420sp2RGB
cv2.putText(bgr_x3pi,"Camera",(30,60),cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,255),2)
#cv2.imwrite("test.jpg",bgr_x3pi)
writer.write(bgr_x3pi)
time.sleep(1/fps)
writer.release()
cam_x3pi.close_cam()
标签:MIPI,1080,cv2,x3pi,1920,OpenCV,bgr,cam,摄像头
From: https://www.cnblogs.com/commuter/p/18463674