Error : CV_8U in function initialize
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!
Asked by Aylin COŞKUN on 2014-11-11 10:28:32 UTC
Answers
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 );
Asked by Wolf on 2014-11-11 10:50:07 UTC
Comments
So how can ı do remove background from kinect dept data? Can ı change kinect max. distance range?
Asked by Aylin COŞKUN on 2014-11-11 15:40:47 UTC
maybe you can threshold the image to filter pixels that are "far away" or very close....
Asked by Wolf on 2014-11-12 02:43:45 UTC
Comments