【问题标题】:Android OpenCV ErrorAndroid OpenCV 错误
【发布时间】:2018-08-06 00:10:29
【问题描述】:

我是 OpenCV 的新手。我在 This Post 之后在 Android Studio 中集成了 OpenCV

使用的 OpenCV SDK 版本是:3.4.0

Android Studio 版本:3.0.1

我的项目结构如下:

在 Canny 函数工作时访问 Imgproc 库时,其余函数(如 HoughLines、cornerHarris、.. LineSegmentDetector 类中的 detect() 方法)都会抛出相同类型的异常,我无法弄清楚为什么会抛出它。

我的代码:

public class MainActivity extends AppCompatActivity {
static{ System.loadLibrary("opencv_java3"); }
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView image=findViewById(R.id.image1);
    ImageView image2=findViewById(R.id.image2);
    Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.wall);
    image.setImageBitmap(bitmap);
    Mat imageMat=new Mat();
    Utils.bitmapToMat(bitmap,imageMat);
    Bitmap newBitmap=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Mat lines=new Mat();
    LineSegmentDetector lsd= Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_STD,0.75,2,0.6,10,0.6,0.1,2);
    lsd.detect(imageMat,lines);
    //Imgproc.Canny(imageMat,lines,1,60,3,false);
    //Imgproc.HoughLines(imageMat,lines,20,20,10);
    //Imgproc.cornerHarris(imageMat,lines,2,3,0.04);
    //Imgproc.GaussianBlur(imageMat,lines,new Size(3,4),2);
    //Utils.matToBitmap(lines,newBitmap);
    image2.setImageBitmap(newBitmap);}
  }

错误堆栈跟踪:

02-26 17:51:54.845 18690-18690/com.example.bssakala.opencvsample E/cv::error(): OpenCV 错误: 断言失败 (!image.empty() && image.type() = = (((0) & ((1

这条线表示什么??

错误:(-215) !image.empty() && image.type() == (((0) & ((1

【问题讨论】:

    标签: android opencv image-processing java-native-interface


    【解决方案1】:

    错误信息告诉你调用detect时某个断言失败

    来自https://github.com/opencv/opencv/blob/master/modules/imgproc/src/lsd.cpp 第 416 行:

     CV_Assert(!image.empty() && image.type() == CV_8UC1);
    

    这意味着:确保提供的输入图像不是空的,并且它的类型是 CV_8UC1 或者在调用者面前抛出一个丑陋的错误消息。

    因此,请确保向detect 提供正确的输入图像,因为其他任何方法都不起作用。

    这也可以在 OpenCV 参考手册中找到

    https://docs.opencv.org/3.1.0/db/d73/classcv_1_1LineSegmentDetector.html

    上面写着:

    参数

    _image 灰度 (CV_8UC1) 输入图像。

    【讨论】:

      猜你喜欢
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 2019-12-17
      • 2013-09-14
      • 2018-01-16
      • 1970-01-01
      相关资源
      最近更新 更多