1. 程式人生 > >【OpenCv/EmguCv】指標式儀表讀數(二)

【OpenCv/EmguCv】指標式儀表讀數(二)

1. 計算偏移角度

計算三個點的夾角:以儀表圓心為中心,指標的一個端點和參考點為另外兩個點計算三個點所組成的兩條線段的夾角α

 public  double Angle(Point cen, Point first, Point second)
        {
            const double M_PI = 3.1415926535897;

            double ma_x = first.X - cen.X;
            double ma_y = first.Y - cen.Y;
            double mb_x = second.X - cen.X;
            double
mb_y = second.Y - cen.Y; double v1 = (ma_x * mb_x) + (ma_y * mb_y); double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y); double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y); double cosM = v1 / (ma_val * mb_val); double angleAMB = Math.Acos(cosM) * 180
/ M_PI; return angleAMB; }

2. 計算示數

value = max*α/360(0<α<180);
value = max*(360-α)/360(180<α<360);

 private double getValue()
        {
            double angle = Angle(center, new Point(center.X, 0), p);
            if (p.X < center.X)
            {
                angle = 360
- angle; } return ((angle/360)*60; }

這裡寫圖片描述