This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Probability ellipse using Eigen library

Tags: None
(comma "," separated)
kreuzerkrieg
Registered Member
Posts
2
Karma
0
Hi,
I'm trying to follow this tutorial to draw tilted ellipse based on covariance matrix. Above tutorial has Matlab and C++ examples, the C++ one uses OpenCV to calculate radiuses and angle and works fine, however, I prefer to use header only library, that's why Eigen v3. On the other hand, I'm not familiar with it at all and I have a difficulty to "translate" the above sample from OpenCV notation to Eigen v3. How do I find min or max value in eigenvector? In eigenvalue? and the angle? How do I cover all points and not only 95%

The sample:
Code: Select all
cv::RotatedRect getErrorEllipse(double chisquare_val, cv::Point2f mean, cv::Mat covmat){
   
   //Get the eigenvalues and eigenvectors
   cv::Mat eigenvalues, eigenvectors;
   cv::eigen(covmat, true, eigenvalues, eigenvectors);

   //Calculate the angle between the largest eigenvector and the x-axis
   double angle = atan2(eigenvectors.at<double>(0,1), eigenvectors.at<double>(0,0));

   //Shift the angle to the [0, 2pi] interval instead of [-pi, pi]
   if(angle < 0)
      angle += 6.28318530718;

   //Conver to degrees instead of radians
   angle = 180*angle/3.14159265359;

   //Calculate the size of the minor and major axes
   double halfmajoraxissize=chisquare_val*sqrt(eigenvalues.at<double>(0));
   double halfminoraxissize=chisquare_val*sqrt(eigenvalues.at<double>(1));

   //Return the oriented ellipse
   //The -angle is used because OpenCV defines the angle clockwise instead of anti-clockwise
   return cv::RotatedRect(mean, cv::Size2f(halfmajoraxissize, halfminoraxissize), -angle);
}
kreuzerkrieg
Registered Member
Posts
2
Karma
0


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]