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

cv::KalmanFilter not working [Solved]

asked 2016-02-26 05:38:15 -0500

PKumars gravatar image

updated 2016-02-26 09:43:45 -0500

I'm trying to use kalman filter in ROS with OpenCV library, but I'm getting error.

below is the error that I'm getting while compilation.

error: ‘KalmanFilter’ is not a member of ‘cv’ cv::KalmanFilter kf(stateSize, measSize, contrSize, type); ^ /home/pkumars/catkin_ws/src/cv_bridge_tutorial_pkg/src/kalman_code1.cpp:59:19: error: expected ‘;’ before ‘kf’ cv::KalmanFilter kf(stateSize, measSize, contrSize, type); ^

and here is my code that I'm trying to compile.

// ROS synchronization headers
#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <message_filters/time_synchronizer.h>
// ROS headers
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
#include <sensor_msgs/PointCloud2.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
// OpenCV headers
#include <cv_bridge/cv_bridge.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
// c++ headers
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <math.h>  
// pcl headers
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <boost/foreach.hpp>
#include <pcl/io/pcd_io.h>
// visualization header
#include <visualization_msgs/Marker.h>

// point cloud definition
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

// standard namespace for c++, ROS messages transport, ROS message filters, OpenCV 
using namespace std;
using namespace sensor_msgs;
using namespace message_filters;
using namespace cv;

// Kalman filter parameters 
int stateSize = 6;          // 6 no of states 
int measSize = 3;           // 3 parameters to be measured 
int contrSize = 0;          // 
unsigned int type = CV_32F; // type

int main( int argc, char *argv[] )


ros::init(argc, argv, "prediction_node");
ros::NodeHandle nh;
ROS_INFO("Starting ");

cv::KalmanFilter kf(stateSize, measSize, contrSize, type);

return 0;


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-02-26 05:50:06 -0500

ros_geller gravatar image

updated 2016-02-26 05:52:30 -0500

You are already using namespace cv, so you don't have to write cv:: infront of your methods. That won't cause an error, but just nice to know.

The KalmanFilter is in the #include "tracking.hpp", and i can't see that you have included that, so try to do that and see if it still gives an error.

Here is a sample code of how to use it:

edit flag offensive delete link more


it worked. Thanks a lot..

PKumars gravatar image PKumars  ( 2016-02-26 07:17:49 -0500 )edit

Please flag it as solved and upvote if the problem is solved ;)

ros_geller gravatar image ros_geller  ( 2016-02-26 08:21:34 -0500 )edit

Question Tools

1 follower


Asked: 2016-02-26 05:38:15 -0500

Seen: 1,705 times

Last updated: Feb 26 '16