Search code examples
object-detectionyoloobs

Yolo V7 | Obs Virtual Camera Shows Only Single Frame


I'm making a project using yolo v7. Im using Obs as virtual cam for yolo v7 The input for obs is specific app / game screen

This is the Terminal line I wrote it.

py .\yolov7\detect.py --weights .\yolov7-tiny.pt --source 0  --conf-thres 0.2 --save-txt --view-img

I got output for only Single Frame Game screen

The Terminal output:

Namespace(weights=['.\\yolov7-tiny.pt'], source='0', img_size=640, conf_thres=0.2, iou_thres=0.45, device='', view_img=True, save_txt=True, save_conf=False, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=False)
YOLOR  v0.1-115-g072f76c torch 1.12.1+cu116 CUDA:0 (NVIDIA GeForce GTX 1650, 4095.6875MB)

Fusing layers... 
Model Summary: 200 layers, 6219709 parameters, 229245 gradients
 Convert model to Traced-model... 
 traced_script_module saved! 
 model is traced! 

1/1: 0... [swscaler @ 000001d35d7340c0] Warning: data is not aligned! This can lead to a speed loss
 success (640x480 at 0.00 FPS).

Exception in thread Thread-1 (update):
Traceback (most recent call last):
  File "C:\Users\Thiroshan\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\Thiroshan\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Thiroshan\Desktop\python\Projects\Reinforcement\Aim_ai_fps\yolov7\utils\datasets.py", line 318, in update
    time.sleep(1 / self.fps)  # wait time
ZeroDivisionError: float division by zero
C:\Users\Thiroshan\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ..\aten\src\ATen\native\TensorShape.cpp:2895.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]

Video Detection Working Verry well except Webcam (Obs Virtual Camera) To test it out the webcam without obs, I don't have webcam

I check the Obs virtual Camera using Opencv it worked perfectly well

let me know why yolo v7 has the webcam problem

# import the opencv library
import cv2 
# define a video capture object
vid = cv2.VideoCapture(0)
  
while(True):
      
    # Capture the video frame
    # by frame
    ret, frame = vid.read()
  
    # Display the resulting frame
    cv2.imshow('frame', frame)
      
    # the 'q' button is set as the
    # quitting button you may use any
    # desired button of your choice
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
  
# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()

Solution

  • I have Fix this problem by downloading https://www.xsplit.com/vcam and virtualizing OBS at same time

    what really its doing

    1. virtualizing cam using OBS
    2. Reading OBS virtualized cam inside Xplit vcam
    3. Reading Xplit output to Yolo (for me cam id is 0)