DMEM
DMEM

Reputation: 1613

OpenCV: cvtColor function cause error on Raspberry Pi

I'm running an OpenCV code on my laptop both on Windows using Visual Studio and Ubuntu VM (using CMake). The code works perfectly fine on both but when I try to run it on my Raspberry Pi 2B, the function cvtColor() (line 205), cause the following error:

pi@raspberrypi ~/Desktop/Track1 $ ./TrackObj 
init done 
opengl support available 
OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor, file /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp, line 3961
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/pi/opencv-2.4.10/modules/imgproc/src/color.cpp:3961: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor

Aborted

I've seen recommendations to try to check if the frame is empty but I'm not sure how to do it in this code given the fact that it is not running.

I've also tried to change the input from camera.open(0); to camera.open("someMovieInFolder.mp4"); but the problem stays as is.

Upvotes: 0

Views: 1558

Answers (2)

DMEM
DMEM

Reputation: 1613

Ok I got it. Indeed the problem was with the image being empty, that's what caused the run-time error. The reason was the Pi camera. Unfortunately this function does not work with the Pi cam (or at least some adjustments needed) so after plunging a USB camera it all worked perfectly.

Upvotes: 0

mkr
mkr

Reputation: 91

It looks indeed as if the image was empty. The image capture function returns a boolean value that can be checked to see if the capture was completed successfully and returned a vaild image. You could also try to printf or cout the width/height of the image. It should be non-zero.

Upvotes: 2

Related Questions