Advertisement
Guest User

Untitled

a guest
Apr 18th, 2012
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. calcCovarMatrix in multichannel image and unresolved assertion error
  2. Mat covar, selection, meanBGR;
  3. selection = src(roi);
  4. calcCovarMatrix(selection, covar, meanBGR, CV_COVAR_NORMAL|CV_COVAR_ROWS);
  5.  
  6. vector<Scalar> samples;
  7.  
  8. for(int i=0; i<selection.rows; i++) {
  9. for(int j=0; j<selection.cols; j++) {
  10.  
  11. Scalar pixel = selection.at<Scalar>(i,j);
  12. Scalar sample(pixel[0], pixel[1], pixel[2]);
  13. samples.push_back(sample);
  14. }
  15. }
  16.  
  17. calcCovarMatrix(samples, covar, meanBGR, CV_COVAR_NORMAL|CV_COVAR_ROWS);
  18.  
  19. #include <opencv2/core/core.hpp>
  20. #include <opencv2/highgui/highgui.hpp>
  21.  
  22. #include <iostream>
  23.  
  24. using namespace cv;
  25. using namespace std;
  26.  
  27. int main(int /*argc*/, char** /*argv*/)
  28. {
  29. Mat_<float> samples = (Mat_<float>(3, 3) << 1.0, 2.0, 3.0,
  30. 4.0, 5.0, 6.0,
  31. 7.0, 8.0, 9.0);
  32.  
  33. Mat cov, mu;
  34. cv::calcCovarMatrix(samples, cov, mu, CV_COVAR_NORMAL | CV_COVAR_ROWS);
  35.  
  36. cout << "cov: " << endl;
  37. cout << cov << endl;
  38.  
  39. cout << "mu: " << endl;
  40. cout << mu << endl;
  41.  
  42. return 0;
  43. }
  44.  
  45. cov:
  46. [18, 18, 18;
  47. 18, 18, 18;
  48. 18, 18, 18]
  49. mu:
  50. [4, 5, 6]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement