OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor

asked 2020-02-20 03:02:45 -0500

jahim44229 gravatar image

updated 2020-02-20 04:08:39 -0500

gvdhoorn gravatar image

Images are bgr, where is the problem?

This is my code block.(callback function)

void callback_function(const ImageConstPtr& image_l,const ImageConstPtr& image_r){

cv_ptr_l = cv_bridge::toCvCopy(image_l, sensor_msgs::image_encodings::BGR8);

cv_ptr_r = cv_bridge::toCvCopy(image_r, sensor_msgs::image_encodings::BGR8);

Mat right = cv_ptr_r->image;

Mat left = cv_ptr_l->image;

    if(filter=="wls_conf") {  
       Ptr<StereoBM> left_matcher = StereoBM::create(max_disp,wsize);
       wls_filter = createDisparityWLSFilter(left_matcher);
       wls_filter->setLambda(lambda);
       wls_filter->setSigmaColor(sigma);
       Ptr<StereoMatcher> right_matcher = createRightMatcher(left_matcher);

       left_for_matcher  = left.clone();
       right_for_matcher = right.clone();

       cvtColor(left_for_matcher,  left_for_matcher,  COLOR_BGR2GRAY);
       cvtColor(right_for_matcher, right_for_matcher, COLOR_BGR2GRAY);
       imshow("lefti", left_for_matcher);
       imshow("righti", right_for_matcher);
       waitKey(1)

That is my error ;

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp, line 9716
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/imgproc/src/color.cpp:9716: error: (-215) scn == 3 || scn == 4 in function cvtColor

Aborted (core dumped)
edit retag flag offensive close merge delete