I have made this OPENCV code which takes the camera video, add a mask.jpg to it and create a new “fake” virtual camera out of it. It’s working well on my Ubuntu Desktop PC, but I can’t make it work on Jetson Nano. Spent all day on it, but still getting this error. Can anyone help me, please? (Also tried both CSI and USB webcam, with the same result)
Error:
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
Code:
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 is done, release the video capture object
cap.release()
# Closes all the frames
cv2.destroyAllWindows()