PYNQ(2)USB摄像头

PYNQ Z2读取USB摄像头数据并通过HDMI输出到显示器

我们主要是通过其arm核来读取USB摄像头的数据,要求所用摄像头支持免驱,如果采用的是工业摄像头,则需要先安装相应的驱动。由于PYNQ Z2镜像自带了opencv库,所以我们主要采用python3+opencv库。

from pynq.overlays.base import BaseOverlay
from pynq.lib.video import *
import cv2
import numpy as np
import time
 
base = BaseOverlay("base.bit")
 
# monitor configuration: 640*480 @ 60Hz,在此我们设置HDMI输出为640*480
Mode = VideoMode(640,480,24)
hdmi_out = base.video.hdmi_out
hdmi_out.configure(Mode,PIXEL_BGR)
hdmi_out.start()
 
# camera (input) configuration
frame_in_w = 640
frame_in_h = 480
 
 
videoIn = cv2.VideoCapture(0)
videoIn.set(cv2.CAP_PROP_FRAME_WIDTH, frame_in_w);
videoIn.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_in_h);
print("capture device is open: " + str(videoIn.isOpened()))
 
 
num_frames = 1000
readError = 0
 
globalimage=np.zeros((640,480,3), np.uint8) 
 
while True:   
    # read next image
    start = time.time()
    ret, frame_vga = videoIn.read()
    globalimage=frame_vga
 
    if (ret):
        outframe = hdmi_out.newframe()
        outframe[:] = frame_vga
        hdmi_out.writeframe(outframe)
        #print("test ok")
    else:
        readError += 1
    end = time.time()
    seconds=end-start
    num_frames -=1
    if num_frames<10:
        break

PYNQ(2)USB摄像头_第1张图片
PYNQ(2)USB摄像头_第2张图片

你可能感兴趣的:(PYNQ(2)USB摄像头)