0

I'm using Raspberry Pi 4B and running OpenCV on it. I have attached webcam for video steam to detect objects using OpenCV, also, a mouse and keyboard. I'm facing a very unique problem here, when I run the python script containing the OpenCV program, it runs smoothly without any errors, and the frame window (webcam) is opened for detection. But after some time (say 50 frames), the RGB lights on my mouse and keyboard turns off meaning that they stop working (goes blank) as well as the webcam which is also connected to one of the USB ports, stops working, but everything turns back on after a second or two. So, the whole problem process takes like 1~2 seconds. Due to this problem, the program shows an error.

Error:

frame = imutils.resize(frame, width=400)
File "home\pi\python\lib\site-packages\imutils\convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'

which basically means that the program is unable to read frames from the webcam as it gets non-responsive for like 1~2 seconds. Not to mention that this problem doesn't occur while idling or doing anything else.

What could be the cause that is making Raspberry Pi do that weird thing? PS: I have run this program on Windows PC multiple times and it runs smoothly without giving any errors.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 01 '22 at 00:43
  • Likely that your video camera or frame grabber did not get an image. So the image is blank and non-existent. NoneType means no image. So if no image, then the shape will fail. – fmw42 Jul 01 '22 at 01:17
  • yes that I know, I wanna the reason behind it. – asadishtiaque Jul 01 '22 at 03:06
  • Here's the code: https://github.com/balajisrinivas/Face-Mask-Detection/blob/master/detect_mask_video.py – asadishtiaque Jul 01 '22 at 03:08
  • Check your video camera and stream before you do anything else. Did the camera produce a picture? If not, then something is wrong with your camera setup or its interface to your Raspberry Pi – fmw42 Jul 01 '22 at 04:23
  • This looks more like a RPi issue. You'll get a better chance of an answer on the [Raspberry Pi Stck](https://raspberrypi.stackexchange.com/) – DrBwts Jul 01 '22 at 09:25

0 Answers0