openCV Error: Assertion failed (scn == 3 || scn == 4) on Raspberry Pi

18,211

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

Share:
18,211
DMEM
Author by

DMEM

Sr. Director of R&D

Updated on June 13, 2022

Comments

  • DMEM
    DMEM almost 2 years

    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.