2/09/2015

OpenCV, Mat operation example of sum(sqrt( A.-B) )

Simple Mat operation using opencv.
But it always not remember well.





vector< float> v1;
 vector< float> v2;
 for(int i=0; i<5; ++i)
 {
  v1.push_back(i*2);
  v2.push_back(i*3);
 }


 Mat AA(v1.size(),1,CV_32FC1); 
 //copy vector to mat  
 memcpy(AA.data,v1.data(),v1.size()*sizeof(float));
 //create Mat  
 Mat BB(v2.size(),1,CV_32FC1); 
 //copy vector to mat  
 memcpy(BB.data,v2.data(),v2.size()*sizeof(float));

 cout << "AA: " << AA << endl;
 cout << "BB: " << BB << endl << endl;


 Mat CC = AA-BB;
 cout << "CC = AA-BB : " << CC << endl << endl;
 CC = CC.mul(CC);
 cout << "CC.*CC or CC^2 : " << CC << endl << endl;
 cv::sqrt(CC, CC);
 cout << "sqrt(CC.) : " << CC << endl << endl;
 cv::Scalar rr = cv::sum(CC);
 float rrr = rr(0);
 cout << "sum(CC.) : " << rrr << endl << endl;


No comments:

Post a Comment