Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include "opencv2/opencv.hpp"
  2. using namespace std;
  3. using namespace cv;
  4.  
  5. // >>>>> Color to be tracked
  6. #define MIN_H_BLUE 200
  7. #define MAX_H_BLUE 300
  8. // <<<<< Color to be tracked   int main() {    // Camera frame    cv::Mat frame;      // >>>> Kalman Filter
  9.  int main()
  10. {
  11.     // Camera frame
  12.     cv::Mat frame;
  13.  
  14.     // >>>> Kalman Filter
  15.     int stateSize = 6;
  16.     int measSize = 4;
  17.     int contrSize = 0;
  18.  
  19.     unsigned int type = CV_32F;
  20.     cv::KalmanFilter kf(stateSize, measSize, contrSize, type); //c32f om filter nauwkeurig te houden
  21.  
  22.     cv::Mat state(stateSize, 1, type);  // [x,y,v_x,v_y,w,h]
  23.     cv::Mat meas(measSize, 1, type);    // [z_x,z_y,z_w,z_h]
  24.  
  25.     cv::setIdentity(kf.transitionMatrix);
  26.  
  27.     kf.measurementMatrix = cv::Mat::zeros(measSize, stateSize, type);
  28.     kf.measurementMatrix.at<float>(0) = 1.0f;
  29.     kf.measurementMatrix.at<float>(7) = 1.0f;
  30.     kf.measurementMatrix.at<float>(16) = 1.0f;
  31.     kf.measurementMatrix.at<float>(23) = 1.0f;
  32.  
  33.     //cv::setIdentity(kf.processNoiseCov, cv::Scalar(1e-2));
  34.     kf.processNoiseCov.at<float>(0) = 1e-2;
  35.     kf.processNoiseCov.at<float>(7) = 1e-2;
  36.     kf.processNoiseCov.at<float>(14) = 5.0f;
  37.     kf.processNoiseCov.at<float>(21) = 5.0f;
  38.     kf.processNoiseCov.at<float>(28) = 1e-2;
  39.     kf.processNoiseCov.at<float>(35) = 1e-2;
  40.  
  41.     // Measures Noise Covariance Matrix R
  42.     cv::setIdentity(kf.measurementNoiseCov, cv::Scalar(1e-1));
  43.     // <<<< Kalman Filter
  44.  
  45.     // Camera Index
  46.     int idx = 0;
  47.  
  48.     // Camera Capture
  49.     VideoCapture test("/home/john/car.mpeg");
  50.  
  51.     // >>>>> Camera Settings
  52.     if (!test.isOpened())
  53.     {
  54.         cout << "file not opened"<<endl;
  55.         waitKey(0);
  56.         return EXIT_FAILURE;
  57.     }
  58.     else
  59.     {
  60.         cout<<"video successfully opened"<<endl;   
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement