cv :: error():OpenCV错误:Android中的断言失败(A.size == arrays [i0] - > size)

时间:2016-10-06 08:03:23

标签: android opencv compare

我的错误是

  

E / cv :: error():OpenCV错误:void cv :: NAryMatIterator :: init中的断言失败(A.size == arrays [i0] - > size)(const cv :: Mat **, cv :: Mat *,uchar **,int),file /Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp,line 4442   E / org.opencv.imgproc:imgproc :: compareHist_10()抓住了cv :: Exception:/Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:4442:错误:(-215 )A.size == arrays [i0] - >函数中的大小void cv :: NAryMatIterator :: init(const cv :: Mat **,cv :: Mat *,uchar **,int)   E / AndroidRuntime:致命异常:主要                     处理:com.example.yantingchen.testopencv4,PID:28141                     CvException [org.opencv.core.CvException:cv :: Exception:/Volumes/Linux/builds/master_pack-android/opencv/modules/core/src/matrix.cpp:4442:error:(-215)A.size = = arrays [i0] - >函数中的大小void cv :: NAryMatIterator :: init(const cv :: Mat **,cv :: Mat *,uchar **,int)                     ]                         在org.opencv.imgproc.Imgproc.compareHist_0(本机方法)                         在org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:753)                         在com.example.yantingchen.testopencv4.MainActivity.compareHist(MainActivity.java:188)                         在com.example.yantingchen.testopencv4.MainActivity.onClick(MainActivity.java:131)                         在android.view.View.performClick(View.java:4785)                         在android.view.View $ PerformClick.run(View.java:19858)                         在android.os.Handler.handleCallback(Handler.java:739)                         在android.os.Handler.dispatchMessage(Handler.java:95)                         在android.os.Looper.loop(Looper.java:155)                         在android.app.ActivityThread.main(ActivityThread.java:5696)                         at java.lang.reflect.Method.invoke(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:372)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1028)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

我的代码是

    onCreate(){

      Mat mat1 = new Mat();
      Mat mat2 = new Mat();
      Mat mat11 = new Mat();
      Mat mat22 = new Mat();

      bitmap1 = ((BitmapDrawable)imageView1.getDrawable()).getBitmap();
      bitmap2 = ((BitmapDrawable)imageView2.getDrawable()).getBitmap();

      Utils.bitmapToMat(bitmap1 , mat1);
      Utils.bitmapToMat(bitmap2 , mat2);
      Imgproc.cvtColor(mat1 , mat11 , Imgproc.COLOR_BGR2GRAY);
      Imgproc.cvtColor(mat2 , mat22 , Imgproc.COLOR_BGR2GRAY);

      compareHist(mat11 , mat22);
    }

和我的compareHist方法

public void compareHist(Mat srcMat , Mat desMat)
{
    srcMat.convertTo(srcMat , CvType.CV_8U);
    desMat.convertTo(desMat , CvType.CV_8U);

    double target = Imgproc.compareHist(srcMat , desMat , Imgproc.CV_COMP_CORREL);

    Log.e(TAG , "相似度: == " + target);
    Toast.makeText(this , "相似度:==" + target , Toast.LENGTH_LONG).show();
    txt1.setText("相關性CORREL" + target);//越接近1越好

    double target1 = Imgproc.compareHist(srcMat , desMat , Imgproc.CV_COMP_CHISQR);
    double target2 = Imgproc.compareHist(srcMat , desMat , Imgproc.CV_COMP_INTERSECT);
    double target3 = Imgproc.compareHist(srcMat , desMat , Imgproc.CV_COMP_BHATTACHARYYA);

    txt2.setText("卡方CHISQR" + target1);//為0最好
    txt3.setText("交集法INTERSECT" + target2);//值越大越好
    txt4.setText("距離法BHATTACHARYYA" + target3);//為0最好
}

我使用两张不同尺寸的照片,我收到此错误, 我该如何解决这个错误

谢谢

0 个答案:

没有答案