代码之家  ›  专栏  ›  技术社区  ›  Ha Bom

CvInvoke.minarearct(contour)返回错误的角度

  •  0
  • Ha Bom  · 技术社区  · 6 年前

    我有一个车牌的轮廓,我想看看它是否倾斜。我曾经 CvInvoke.MinAreaRect(contour) 但它总是返回 angle == -90

    return values

    contour draw

    original image

    有没有人知道发生了什么事以及我的问题的解决办法?

    Image<Gray, byte> gray = new Image<Gray, byte>("2.PNG");
    Image<Gray, byte> adaptive_threshold_img = gray.ThresholdAdaptive(new Gray(255), AdaptiveThresholdType.GaussianC, ThresholdType.BinaryInv, 11, new Gray(2));
    
    VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
    Mat hier = new Mat();
    CvInvoke.FindContours(adaptive_threshold_img, contours, hier, RetrType.Tree, ChainApproxMethod.ChainApproxSimple);
    
    double max_area = 0;
    VectorOfPoint max_contour = new VectorOfPoint();
    
    for (int i = 0; i < contours.Size; i++)
    {
        double temp = CvInvoke.ContourArea(contours[i]);
        if (temp > max_area)
        {
            max_area = temp;
            max_contour = contours[i];
        }
    }
    
    VectorOfVectorOfPoint contour_to_draw = new VectorOfVectorOfPoint(max_contour);
    CvInvoke.DrawContours(gray, contour_to_draw, 0, new MCvScalar(255), 2);
    
    CvInvoke.Imshow("plate", gray);
    
    RotatedRect plate_feature = CvInvoke.MinAreaRect(max_contour);
    
    CvInvoke.WaitKey();
    CvInvoke.DestroyAllWindows();
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   user10665551 user10665551    6 年前

    CvInvoke.threshold() 而不是 gray.ThresholdAdaptive() . 设置适当的阈值,你会得到比以前更好的轮廓。