gpt4 book ai didi

android - OpenCV Android - 查找/绘制轮廓错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:33 26 4
gpt4 key购买 nike

我正在尝试做的是获取阈值图像并对其执行 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 调度错误。

最佳答案

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

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

对于此类 future 的错误,查看 opencv github 存储库 ( 1 ) 可能会对您有所帮助。

关于android - OpenCV Android - 查找/绘制轮廓错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29286478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com