opencv3 android,Android中使用OpenCV3.3.0进行图片比较报错。OpenCV Error:Assertion failed

opencv-3.3.0-android-sdk

AndroidStudio2.3.3

Nexus6, Android6.0

private void compareImg(Bitmap bitmap1, Bitmap bitmap2){

Mat mat1 = new Mat();

Mat mat2 = new Mat();

Utils.bitmapToMat(bitmap1, mat1); // 将bitmap数据放入Mat

Utils.bitmapToMat(bitmap2, mat2); //

Mat matGray1 = new Mat();

Mat matGray2 = new Mat();

Imgproc.cvtColor(mat1, matGray1, Imgproc.COLOR_BGR2GRAY); // 转换彩色数据为灰度数据

Imgproc.cvtColor(mat2, matGray2, Imgproc.COLOR_BGR2GRAY);

matGray1.convertTo(matGray1, CvType.CV_32F);

matGray2.convertTo(matGray2, CvType.CV_32F);

double target = Imgproc.compareHist(matGray1, matGray2, Imgproc.CV_COMP_CORREL); // 报错的代码

}

出现的错误反馈:

com.cuiweiyou.testopencv E/cv::error():

OpenCV Error:

Assertion failed (A.size == arrays[i0]->size)

in void cv::NAryMatIterator::init(const cv::Mat**, cv::Mat*, uchar**, int),

file /build/master pack-android/opencv/modules/core/src/matrix.cpp, line 4790

com.cuiweiyou.testopencv E/org.opencv.imgproc:

imgproc::compareHist 10() caught cv::Exception: /build/master pack-android/opencv/modules/core/src/matrix.cpp:4790:

error: (-215) A.size == arrays[i0]->size

in function void cv::NAryMatIterator::init(const cv::Mat**, cv::Mat*, uchar**, int)

com.cuiweiyou.testopencv E/AndroidRuntime:

FATAL EXCEPTION:

main Process: com.cuiweiyou.testopencv, PID: 9817

CvException [org.opencv.core.CvException: cv::Exception: /build/master pack-android/opencv/modules/core/src/matrix.cpp:4790:

error: (-215) A.size == arrays[i0]->size

in function void cv::NAryMatIterator::init(const cv::Mat**, cv::Mat*, uchar**, int)]

at org.opencv.imgproc.Imgproc.compareHist 0(Native Method)

at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:767)

我尝试修改这行代码里的最后参数"Imgproc.cvtColor(mat1, matGray1, Imgproc.COLOR BGR2GRAY);",使用"Imgproc.COLOR BGRA2GRAY"或其它几个也失败。

请网友帮忙,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值