我尝试做的是拍摄阈值图像并对其执行findContours,然后将其绘制为旋转校正图像。旋转校正图像和阈值图像按预期工作,所以我有点亏本,弄清楚为什么会崩溃。保留图像是旋转校正图像的灰色版本,其已应用二进制阈值。
public void findImageContours(Mat passedThreshInt, Mat passedRotatedInit)
{
/* Get Thresholded input image */
Mat initThresh = passedThreshInt.clone();
/* Get image to draw Contours on */
Mat initRotated = passedRotatedInit.clone();
/* Get contours from threshold image */
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(initThresh, contours, mHierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
/* Draw Contours */
Scalar CONTOUR_COLOR = new Scalar(255,0,0,255);
Log.e(TAG, "Contours count: " + contours.size());
Imgproc.drawContours(initRotated, contours, -1, CONTOUR_COLOR);
/* Save Output */
contouredInit = initRotated.clone(); //ContouredInit is Global
Utils.matToBitmap(contouredInit, contouredBitmapInit); // contouredBitmapInit is Global
}
错误:
OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
nMatToBitmap catched cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
之后是JDI Dispatch Error。
答案 0 :(得分:2)
Bitmap
的尺寸必须与OpenCV Mat
的尺寸相匹配。我建议你创建如下的Bitmap。
Bitmap bitmapImg = Bitmap.createBitmap( matImg.cols(), matImg.rows(), Bitmap.Config.ARGB_8888 );
对于这些类型的未来错误,查看opencv github存储库(1)可能会对您有所帮助。