6

I've followed this tutorial of OpenCV object tracking and managed to make the code work on my laptop, both on Windows using Visual Studio and on my Ubuntu VM (Using CMake). Now I try to run it on my Raspberry Pi (running Raspbian). cmake . and make commands seems to works fine but when I try to run the executable I get the following error:

pi@raspberrypi ~/Desktop/Track $ ./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 looked at this question and similar to it but it did not help me solve the problem.

Source code available here:

objectTrackingTutorial.cpp

Fruit.cpp

Fruit.h

I've heard that the problem might be with the camera or camera drivers so I tried using a usb camera as well as the pi camera and I also tried to change the line capture.open(0); to capture.open("someMovie.mp4"); so instead of open a live stream it will run in on an exiting video but it still giving me the same error.

Community
  • 1
  • 1
DMEM
  • 1,573
  • 8
  • 25
  • 43
  • Maybe try it with a preloaded image you are completely sure of the size, format etc. This is because it might be reading from the webcam in a completely unexpected way. – GPPK Apr 02 '15 at 13:55
  • Can you be more specific? Do you mean I should change `Capture.open(0);`? – DMEM Apr 02 '15 at 14:11
  • Are you using the Raspberry Pi camera? – theo-brown Dec 15 '15 at 10:12
  • Perhaps the program is expecting an argument that it is not getting. Ive seen similar errors for that reason. – j0h Sep 06 '16 at 22:47

1 Answers1

5

The error indicate that the frame or image that you would to convert at level of calling 'cvtColor()' have not the same type as you indicate it in the function. two possible cause:

  1. image has different type
  2. or your frame is empty

try to change CV_BGR2HSV to CV_RGB2HSV or try to print the image you get from your cam to check if it is empty or not. Hope it help

Kacem
  • 126
  • 6
  • Changing CV_BGR2HSV to CV_RGB2HSV did not work. Can you explain in more details how to print the image from the camera. Just a reminder: This code works perfectly on my laptop (Ubuntu and Windows). This is why I think the problem got something to do with the Pi – DMEM Apr 02 '15 at 17:04
  • to print image from camera just use: if(!image.empty()) imshow(" result ", image); else continue; – Kacem Apr 02 '15 at 17:07
  • I know how to print a picture, I'm asking how should I try printing in this code considering the code is not working...? – DMEM Apr 03 '15 at 08:45