【问题标题】:Java Opencv not detecting contours. imgproc.Drawcontours()Java Opencv 未检测轮廓。 imgproc.Drawcontours()
【发布时间】:2017-12-04 17:05:02
【问题描述】:

我正在尝试在 Xamarin 上开发移动应用程序。首先,我正在为 android 设备做这件事。我希望 Oncamera 功能能够自动检测轮廓并测量对象的大小。作为主要步骤,我试图实时检测轮廓。阅读大量表格和许多文件,但没有任何帮助

public Mat OnCameraFrame(CameraBridgeViewBase.ICvCameraViewFrame inputFrame)
    {
        Mat input = inputFrame.Rgba();
        List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
        Mat gray = new Mat();
        //Mat hierarchy = new Mat();
        Imgproc.CvtColor(p0: input, p1: gray, p2: Imgproc.ColorRgb2gray);
        Mat blur = new Mat();
        Imgproc.GaussianBlur(gray, blur, new Size(7, 7), -2);
        Mat thresh = new Mat();
        Imgproc.Threshold(blur, thresh, 127, 250, Imgproc.ThreshBinary);
        Mat edged = new Mat();
        Imgproc.Canny(thresh, thresh, 25, 50);
        Imgproc.Dilate(thresh, thresh, new Mat(), new Point(-1, 1), 1);
        Mat hierarchy = thresh.Clone();
        Imgproc.FindContours(hierarchy, contours, new Mat(), 
             Imgproc.RetrExternal, Imgproc.ChainApproxNone);
        Java.Lang.JavaSystem.Out.Println("contours" + contours);
        if (contours != null)
        {
                Java.Lang.JavaSystem.Out.Println("found contours");
            for (int i = 0; i < contours.Count(); i++)
            {
                Imgproc.DrawContours(input, contours, i, new Scalar(255, 0, 0), -1);
            }

        }
        else
        {
            Java.Lang.JavaSystem.Out.Println("no contours");
        }
        return input;

我在代码中使用了上述逻辑。但是我在应用程序中的输出显示的是没有绘制任何轮廓的正常图像。如果我返回“thresh”,那么精明的边缘检测就可以完美地工作。但 Drawcontours 没有显示任何内容。 我使用 Contours.count() 因为我的 Xamarin ide 显示 contours.Size() 错误;

【问题讨论】:

  • 您不需要遍历所有轮廓来绘制它们。删除for循环并将i替换为-1,这将绘制所有轮廓。
  • @Jyr 我也试过这样。但我无法实时绘制任何轮廓。我不明白哪里出了问题!
  • @Shofwan Amrullah 你能看看这个吗?

标签: java android opencv xamarin


【解决方案1】:

我遇到了类似的问题。 就我而言,我已经更换了

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

IList<MatOfPoint> contours = new JavaList<MatOfPoint>();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 2016-10-24
    • 2014-12-12
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多