hi I need to inverse the two color BackgroundSubtractor

asked 2017-04-18 17:09:53 -0600

lolo gravatar image

updated 2017-04-18 17:12:19 -0600

hi I need to inverse the two color of BackgroundSubtractor (black and white) is that possible or not? if yes how to do it? this is my code. I'm using ROS indigo

//ROS #include <ros ros.h=""> #include <sensor_msgs image.h=""> #include <sensor_msgs image_encodings.h=""> #include <image_transport image_transport.h=""> #include <cv_bridge cv_bridge.h=""> //OpenCV #include <opencv2 opencv.hpp=""> #include <opencv2 imgproc="" imgproc.hpp=""> #include <opencv2 highgui="" highgui.hpp=""> //BG SUBTRACTION #include <opencv2 video="" background_segm.hpp="">

cv::Ptr<cv::backgroundsubtractor> pMog;

cv::Mat fgMask;

void rgbCallback(const sensor_msgs::ImageConstPtr& msg) { cv_bridge::CvImageConstPtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8); } catch (cv_bridge::Exception& ex) { ROS_ERROR("cv_bridge exception: %s", ex.what()); exit(-1); }

pMog->operator()(cv_ptr->image, fgMask);

cv::imshow("RGB", cv_ptr->image); cv::imshow("FgMask", fgMask); cv::waitKey(30); } int main(int argc, char **argv) { ros::init(argc, argv, "kinectgrabber");

pMog = new cv::BackgroundSubtractorMOG(); //MOG Approach

ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/camera/rgb/image_color", 1, rgbCallback);

ros::spin(); return 0; }

edit retag flag offensive close merge delete