协方差矩阵用椭圆显示:opencv画椭圆

在做kalman滤波算法时,会看系统协方差的变化,椭圆是很好的可视化表示协方差.

  椭圆表示:  中性点  长短轴  角度  

协方差矩阵==>椭圆表示   特征值与特征矩阵..



opencv API : ellipse

C++: void ellipse (Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )
Parameters:
  • img – Image.
  • center – Center of the ellipse.             椭圆中心点
  • axes – Half of the size of the ellipse main axes.                   长短轴长
  • angleEllipse rotation angle in degrees.                               长轴角度  角度制0~360°
  • startAngle – Starting angle of the elliptic arc in degrees.        起始角度 0 
  • endAngle – Ending angle of the elliptic arc in degrees.          终止角度  360
  • box – Alternative ellipse representation via RotatedRect or CvBox2D. This means that the function draws an ellipse inscribed in the rotated rectangle.
  • colorEllipse color.
  • thickness – Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
  • lineType – Type of the ellipse boundary. See the line() description.
  • shift – Number of fractional bits in the coordinates of the center and values of axes.

协方差矩阵用椭圆显示:opencv画椭圆_第1张图片


opencv API: eigen

C++: bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1, int highindex=-1)

Parameters:

  • src – input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical (src T == src).                   对称方阵
  • eigenvalues – output vector of eigenvalues of the same type as src; the eigenvalues are stored in the descending order.  特征值
  • eigenvectors – output matrix of eigenvectors; it has the same size and type as src; the eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues.        特征向量
  • lowindex – optional index of largest eigenvalue/-vector to calculate; the parameter is ignored in the current implementation.
  • highindex – optional index of smallest eigenvalue/-vector to calculate; the parameter is ignored in the current implementation.



    Mat a = Mat::ones(2,2,CV_32FC1);
        a.at<float>(0,0) = 5;
        a.at<float>(0,1) = -4;
        a.at<float>(1,0) = -4;
        a.at<float>(1,1) = 5;
    Mat eigen_values;
    Mat eigen_vector;

    eigen(a,eigen_values,eigen_vector);
    cout<<" eigen_values00 "<<eigen_values.at<float>(0,0)<<endl;
    cout<<" eigen_values "<<eigen_values <<endl;
    cout<<" eigen_vector "<<eigen_vector <<endl;

    cv::Mat img_test = Mat::ones(640,480,CV_32FC1)*255;  //imread("test.png",1);
    Point2f center(50.0,50.0);
    float angle = atan2(eigen_values.at<float>(0,1),eigen_values.at<float>(0,0))*180.0/3.1415;
    Size size(eigen_values.at<float>(0)*5,eigen_values.at<float>(1)*5);
    ellipse(img_test, center, size ,angle, 0, 360, CV_RGB(0,255,0));

    while(1)
    {
    imshow("display ellipse",img_test);
    cv::waitKey(200);
    cv::waitKey(20);
    }


协方差矩阵用椭圆显示:opencv画椭圆_第2张图片


参考::


协方差矩阵在目标二维姿态测量中的应用 

opencv API : ellipse

opencv API: eigen




你可能感兴趣的:(协方差矩阵用椭圆显示:opencv画椭圆)