Error : CV_8U in function initialize [closed]
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!