Exemplo n.º 1
0
    /// <summary>
    /// use 1920x1080
    /// </summary>
    /// <param name="curr_img"></param>
    /// <returns></returns>
    public float GetSpeed(Mat curr_img)
    {
        Point2f[] curr_feature_pts = new Point2f[100];
        byte[]    status;
        float[]   err;

        Cv2.PyrDown(curr_img, curr_img_resize, curr_img_resize.Size());
        var feature_mask = NMS(hog.Detect(curr_img_resize), 0.8f);

        if (feature_mask == Rect.Empty)
        {
            return(-1.0f);
        }

        feature_mask = new Rect(feature_mask.X - (feature_mask.Width / 2), feature_mask.Y - (feature_mask.Height / 2), feature_mask.Width, feature_mask.Height);

        Cv2.CalcOpticalFlowPyrLK(prev_img, curr_img_resize, FeaturePoints, ref curr_feature_pts, out status, out err);
        var speed = CalcSpeed(FeaturePoints, curr_feature_pts, feature_mask, status, err, between_frame);
        var acc   = Math.Abs(speed - prev_speed);

        FeaturePoints = curr_feature_pts;
        curr_img_resize.CopyTo(prev_img);
        DetectedRect = feature_mask;
        //var result = anomaly.DataRecorded(speed, 0.03f * 1);
        //Trace.WriteLine(msg); // test
        var estimation = new SpeedEstimation();

        estimation.speed      = speed;
        estimation.accelation = acc;
        estimation.result     = 1;
        prev_speed            = speed;
        return(estimation.speed);
    }
Exemplo n.º 2
0
    void opticalFlow()
    {
        InputOutputArray feature_next = new Mat();
        OutputArray      status       = new Mat();
        OutputArray      err          = new Mat();
        Point2f          good_prev;
        Point2f          good_next;

        for (int i = 0; i < 2; i++)
        {
            //歪み補正を追加?
            grayNext[i] = leapUVC.LeftRightFrame[i].Clone();
            Cv2.CvtColor(grayNext[i], colorFrame[i], ColorConversionCodes.GRAY2BGR);
            //左カメラ
            if (i == 0)
            {
                //オプティカルフロー検出
                Mat feature_prev = new Mat(1, feature_prev_l.Length, MatType.CV_32FC2, feature_prev_l);
                feature_prev = feature_prev.T();
                //Debug.Log(feature_prev.Size());
                Cv2.CalcOpticalFlowPyrLK(grayPrev[i], grayNext[i], feature_prev, feature_next, status, err, winSize, maxLevel, criteria);
                //Mat st = status.GetMat();
            }
            else
            {
                Mat feature_prev = new Mat(1, feature_prev_r.Length, MatType.CV_32FC2, feature_prev_r);
                feature_prev = feature_prev.T();
                Cv2.CalcOpticalFlowPyrLK(grayPrev[i], grayNext[i], feature_prev, feature_next, status, err, winSize, maxLevel, criteria);
            }

            Mat feature_nextMat = feature_next.GetMat();
            for (int j = 0; j < feature_nextMat.Height; j++)
            {
                Debug.Log(j);
            }
        }
    }