【问题标题】:OpenCV Error: Unsupported format or combination of formatsOpenCV 错误:不支持的格式或格式组合
【发布时间】:2013-05-23 09:38:19
【问题描述】:

我正在开发一个应用程序,我必须从相机拍照,然后检测图片中的边缘正方形(像文档页面。)......经过长时间的搜索,我找到了 OpenCV 库来实现这一点,我已成功导入android的java库,但问题是当我调用opencv的方法检测Square时(方法是

Imgproc.findContours(converted, contours,hierarchy,Imgproc.CHAIN_APPROX_SIMPLE,Imgproc.RETR_LIST))..它给了我

异常...OpenCV 错误: _CvContourScanner* cvStartFindContours(void*, CvMemStorage*, int, int, int, CvPoint),文件 /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/contours.cpp,第 196 行

我正在向您发送一些代码--------------------------------------- --------------

public void convertImage() {

    Mat ori = new Mat();
    Mat converted = new Mat(200, 200, CvType.CV_8UC1, new Scalar(0));

    try {
        ori = Utils.loadResource(MainActivity.this, R.drawable.ic_launcher, Highgui.CV_LOAD_IMAGE_COLOR);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Imgproc.cvtColor(ori,  converted, Imgproc.COLOR_RGB2GRAY, 4);  // convert Image to grayscale
    Imgproc.threshold(ori, converted, 50, 250, Imgproc.ADAPTIVE_THRESH_MEAN_C); // threshold the image

    List<MatOfPoint> contours = new ArrayList<MatOfPoint>(10);
    Mat hierarchy = new Mat(200, 200, CvType.CV_32FC1, new Scalar(0));

    Imgproc.findContours(converted, contours, hierarchy,Imgproc.CHAIN_APPROX_SIMPLE,Imgproc.RETR_LIST);

    ImageView frame = (ImageView) findViewById(R.id.imageView1);

    Imgproc.cvtColor(converted, converted, Imgproc.COLOR_GRAY2RGBA, 4); // convert Image back to RGB
    Bitmap bmp = Bitmap.createBitmap(converted.cols(), converted.rows(), Bitmap.Config.ARGB_8888);




    frame.setImageBitmap(bmp);
    }

任何帮助将不胜感激------------------ 提前致谢

【问题讨论】:

    标签: android opencv


    【解决方案1】:

    在'cvFindCounters'的第一个参数是输入图像;此图像应为 8 位单通道图像,并将被解释为二进制。 因此,您应该传递单通道图像,而不是传递 4 通道图像。

    这应该适合你。
    Imgproc.cvtColor(ori, 已转换, Imgproc.COLOR_RGB2GRAY, 1);

    【讨论】:

      【解决方案2】:

      尝试使用

      Imgproc.cvtColor(ori,  converted, Imgproc.COLOR_RGB2GRAY, 1);
      Imgproc.cvtColor(converted, converted, Imgproc.COLOR_GRAY2RGBA, 1);
      

      而不是

      Imgproc.cvtColor(ori,  converted, Imgproc.COLOR_RGB2GRAY, 4);
      Imgproc.cvtColor(converted, converted, Imgproc.COLOR_GRAY2RGBA, 4);
      

      因为你需要使用 1 个频道。

      【讨论】:

        【解决方案3】:

        首先将位图加载为-

        Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                               R.drawable.ic_launcher);
        

        然后将位图转换为 Mat -

        Mat m = new Mat();
        Utils.bitmapToMat(icon, m);
        Imgproc.cvtColor(m, m, Imgproc.COLOR_RGB2GRAY, 1);
        

        执行你的阈值和findcontours如上..基本思想是将位图转换为单通道的Mat..

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-02-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多