I cannot run code that "detects in real time" the model I created.

I have created a model "in a project where I am trying to detect in real time “---------------------------------------------------------------------------
error Traceback (most recent call last)
c:\Users\cloud\OneDrive\Desktop\PythonLand\PoloPlus\AI\CV\Food-Detection\Biscuit-Decetion\Special_Object_Recognition\yolov8\yolo_realcv.ipynb Cell 3 line 7
68 image = infer()
69 # And display the inference results
—> 70 cv2.imshow(‘image’, image)
72 # Print frames per second
73 print((1/(time.time()-start)), " fps”)

error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:967: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow’"

I get an error like "{
“__comment1”: “Obtain these values via Roboflow”,
“ROBOFLOW_API_KEY”: “########”,
“ROBOFLOW_MODEL”: “biscuit_detct”,
“ROBOFLOW_SIZE”: 416,

"__comment2": "",
"FRAMERATE": 24,
"BUFFER": 0.5"

I can not solve this error? I can send the complete code.

Can you help me? .
Thanks for your help.

The error message you’re seeing is typically due to OpenCV’s imshow function not receiving a valid image. This could be because the image is not being loaded correctly or the image path is incorrect.

In the context of Roboflow, if you’re using a webcam or other video source for real-time detection, you might encounter issues if the video source is not found or not accessible. As mentioned in the Roboflow blog post, if you encounter an error like assert cap.isOpened(), f'Failed to open {s}' and AssertionError: Failed to open 0, it indicates that your camera was unable to be found. You can try reconnecting your camera or changing the source argument to detect.py. To try changing the source argument, use --source 1 with detect.py instead of --source 0.

If you’re still encountering issues, please ensure that your image or video source is correctly set up and accessible.


Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, knowledge base, and previous forum responses. If you find this to be a helpful answer, please mark it as the solution using the checkbox icon below. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.