ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Error : CV_8U in function initialize [closed]

asked 2014-11-11 09:28:32 -0600

Aylin COŞKUN gravatar image

updated 2014-11-11 09:29:01 -0600

Hi all!

I am trying to background subtraction using MOG subtractor with kinect depth data.

Code is below.

 class ImageConverter
{
cv_bridge::CvImagePtr cv_ptr;
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::Subscriber image_sub_;

//for back_sub
//global variables
Mat frame; //current frame
Mat fgMaskMOG; //fg mask generated by MOG method
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
Ptr<BackgroundSubtractor> pMOG; //MOG Background subtractor
Ptr<BackgroundSubtractor> pMOG2; //MOG2 Background subtractor


public:
ImageConverter(): it_(nh_)
  {
  //image_sub_ = it_.subscribe("/camera/rgb/image_color", 1, &ImageConverter::imageCb, this);
  image_sub_ = it_.subscribe("camera/depth/image", 1, &ImageConverter::imageCb, this);

        pMOG= new BackgroundSubtractorMOG(); //MOG approach
        pMOG2 = new BackgroundSubtractorMOG2(); //MOG2 approach

 }

 ~ImageConverter()
  {
   cv::destroyWindow(WINDOW);
   destroyAllWindows();
  }


 void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {
cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_32FC1);
    processVideo();
   cv::waitKey(3);

 }


    void processVideo()
    {
        imshow("Image", cv_ptr->image);
        pMOG->operator()(cv_ptr->image, fgMaskMOG);
       imshow("Image2", fgMaskMOG);

    }

 };

 int main(int argc, char** argv)
  {
     ros::init(argc, argv, "subtract_node");
    ImageConverter ic;
     ros::spin();
    return 0;
 }

Error is :

terminate called after throwing an instance of 'cv::Exception'  what():/build/buildd/opencv-.4.8+dfsg1/modules/video/src/bgfg_gaussmix.cpp:117 :
 error: (-215) CV_MAT_DEPTH(frameType) == CV_8U in function initialize

Thanks!

edit retag flag offensive reopen merge delete

Closed for the following reason OpenCV Question: THe OpenCV community prefers to answer questions at: http://answers.opencv.org/questions/ by tfoote
close date 2014-11-23 13:51:19.137698

1 Answer

Sort by » oldest newest most voted
0

answered 2014-11-11 09:50:07 -0600

Wolf gravatar image

kinect depth data is not 8 bit depth, I think its 16 bit but not sure. Therefore you cannot use a opencv image rpocessing function you use because it is only implemented for images with 8bit depth per channel. The line that causes the error assert that the image channel depth is 8bit, thereby causes the error: CV_Assert( CV_MAT_DEPTH(frameType) == CV_8U );

edit flag offensive delete link more

Comments

So how can ı do remove background from kinect dept data? Can ı change kinect max. distance range?

Aylin COŞKUN gravatar image Aylin COŞKUN  ( 2014-11-11 14:40:47 -0600 )edit

maybe you can threshold the image to filter pixels that are "far away" or very close....

Wolf gravatar image Wolf  ( 2014-11-12 01:43:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-11 09:28:32 -0600

Seen: 412 times

Last updated: Nov 11 '14