Do the API code examples still work from this roboflow blog? Errors from sample code

I’m trying to use the roboflow API to run inference on my webcam but neither the simple or async versions work for me, I get the error:

cv2.imshow('image', image)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

[ WARN:0@2.715] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

My webcam definitely is in port 0 and is working on other python scripts that call cv2.videoCapture(0)

Any ideas whats going on?

Hey @Vulcan88

Skimming through, it looks like https://infer.roboflow.com/ should be https://detect.roboflow.com/. I’ll update this now.

Ah i see the blog post itself was wrong but the github files did use detect so I guess they were retroactively changed, unfortunately it wasn’t the cause of the problem :smiling_face_with_tear:

From some debugging it seems that on line 54 in infer_simple.py:

image = cv2.imdecode(image, cv2.IMREAD_COLOR)

This is the method at which image is being returned as a NoneType, hmmm…

Ok, can you try these things while I try to reproduce this error?

  • check if your webcam works fine with any other library other than OpenCV
  • change VideoCapture(0) => VideoCapture(1)
  • uninstall OpenCV and reinstall it
  • relaunch the code editor or try with a different IDE