0

I am looking to complete a simple live feed object detection tutorial from the 'imageai' documentation (https://imageai.readthedocs.io/en/latest/video/index.html). As per tutorial the code is following:

from imageai.Detection import VideoObjectDetection
import os
import cv2

execution_path = os.getcwd()

camera = cv2.VideoCapture(0)

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path , "yolov3.pt"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(camera_input=camera,
    output_file_path=os.path.join(execution_path, "camera_detected_video")
    , frames_per_second=20, log_progress=True, minimum_percentage_probability=30)

print(video_path)

I have installed all the necessary packages for the tutorial (including opencv package in my environmental variable). However, once I run the code, I get the following error:

OpenCV: Couldn't read movie file "" [ERROR:0@1.705] global cap.cpp:166 open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.7.0) /private/var/folders/p5/T/pip-install-fu_8bn3g/opencv-python_/opencv/modules/videoio/src/cap_images.cpp:293: error: (-215:Assertion failed) !_filename.empty() in function 'open'

I saw that similar issue arose when the path for detectObjectFromImage was specified incorrectly. However, I do not understand how is it related here if I am using VideoCapture(0).

Thank you so much for the help!

starship
  • 53
  • 1
  • 6
  • complete traceback please. -- what build/package of opencv is this? how did you install it? output of `print(cv2.getBuildInformation())` – Christoph Rackwitz Jun 23 '23 at 21:15
  • @ChristophRackwitz pip install opencv-python, i am on macOS old version, so it took time to build wheels but it eventually installed. print(cv2.getBuildInformation()) General configuration for OpenCV 4.7.0 Version control: unknown Platform: Timestamp: 2023-06-23T19:13:03Z Host: Darwin 19.4.0 x86_64 CMake: 3.26.4 CMake generator: Unix Makefiles CMake build tool: /usr/bin/make Configuration: Release [The output is too big obv] – starship Jun 23 '23 at 21:24
  • the video IO section is of particular interest in this case. you can [edit] your question to add information. I suspect something's wrong with the videoio backends, given that the VideoCapture dropped through all of them, down to CAP_IMAGES, and none felt responsible for handling `0` – Christoph Rackwitz Jun 23 '23 at 22:38
  • @ChristophRackwitz cv2.videoio_registry.getBackends() (1900, 1800, 2300, 1200, 2000, 2200, 2500); i am not sure what else i can get or change, apparently i can try to set an api preference in VideoCapture(), i tried bunch of things but nothing worked. Am I in a right place? – starship Jun 24 '23 at 04:53

0 Answers0