0

我制作了这段代码,它获取相机视频,添加一个 mask.jpg 并从中创建一个新的“假”虚拟相机 ( v4l2loopback)。它在我的 Ubuntu 台式电脑上运行良好,但我无法在 Jetson Nano 上运行。花了一整天的时间,但仍然收到此错误。任何人都可以帮助我吗?(还尝试了 CSI 和 USB 网络摄像头,结果相同)

错误:

Traceback (most recent call last):
  File "/home/scotty/dice_mask/mask_video.py", line 31, in <module>
    with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
  File "/home/scotty/.local/lib/python3.6/site-packages/pyvirtualcam/camera.py", line 219, in __init__
    raise RuntimeError('\n'.join(errors))
RuntimeError: 'v4l2loopback' backend: std::exception

代码:

import cv2
import numpy as np
import pyvirtualcam

flip = 2
dispW = 640
dispH = 480

camSet='nvarguscamerasrc !  video/x-raw(memory:NVMM), width=3280, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cap=cv2.VideoCapture(2)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
img2 = cv2.imread('/home/scotty/dice_mask/mask_480.jpg')


# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")

# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:

    # Display the resulting frame
    dst = cv2.addWeighted(frame,1,img2,1,0)
    #cv2.imshow('Frame',dst)
    
    #creating virtual camera /dev/video2
    with pyvirtualcam.Camera(width=640, height=480, fps=20) as cam:
      print(f'Using virtual camera: {cam.device}')

      framex = cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)
      cam.send(framex)
      cam.sleep_until_next_frame() 


    # Press Q on keyboard to  exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break

  # Break the loop
  else: 
    break

# When everything done, release the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()
4

0 回答 0