1

我正在尝试做的是获取阈值图像并对其执行 findContours 然后将其绘制为旋转校正图像。旋转校正图像和阈值图像按预期工作,所以我有点不知道为什么会崩溃。Thersholded 图像是已应用二进制阈值的旋转校正图像的灰度版本。

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 调度错误。

4

1 回答 1

2

的尺寸Bitmap必须与 OpenCV 的尺寸相匹配Mat。我建议您如下创建位图。

Bitmap bitmapImg = Bitmap.createBitmap( matImg.cols(), matImg.rows(), Bitmap.Config.ARGB_8888 );

对于这些类型的未来错误,查看 opencv github 存储库(1)可能会对您有所帮助。

于 2015-03-27T05:41:26.770 回答