android中的CV异常

时间:2017-05-10 09:53:26

标签: android opencv

这是我的例外

CvException [org.opencv.core.CvException:cv :: Exception:/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/hough.cpp:712:错误: (-5)源图像必须是8位,单通道功能CvSeq * cvHoughLines2(CvArr *,void *,int,double,double,int,double,double)

    mat = new Mat();
    edges = new Mat();
    lines = new Mat();
    mRgba = new Mat(612, 816, CvType.CV_8UC1);
    Utils.bitmapToMat(bitmap, mat);
    Imgproc.Canny(mat, edges, 50, 90);
    int threshold = 50;
    int minLineSize = 20;

    int lineGap = 20;
    try {

        Imgproc.HoughLines(mat, lines, 1, Math.PI / 180, threshold, minLineSize, lineGap);
        for (int x = 0; x < lines.cols(); x++) {
            double[] vec = lines.get(0, x);
            double x1 = vec[0], y1 = vec[1], x2 = vec[2], y2 = vec[3];
            Point start = new Point(x1, y1);
            Point end = new Point(x2, y2);
            Core.line(mRgba, start, end, new Scalar(255, 0, 0), 3);
        }
        Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(mRgba, bmp);
        bitmap = bmp;




    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("e = " + e);
    }

1 个答案:

答案 0 :(得分:0)

你的功能HoughLines中的图像是不对的。在将其放入函数之前,您没有将其格式化。

尝试准备这样的图像:

https://stackoverflow.com/a/7975315/5577679