gpt4 book ai didi

java - Android Java Opencv canny 抛出 cvexception

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

我想在 Android 中使用 Canny 检测图像的边缘,但它一直抛出此错误:

E/cv::error(): OpenCV Error: Assertion failed (_dx.type() == CV_16SC1 || _dx.type() == CV_16SC3) in void cv::Canny(cv::InputArray, cv::InputArray, cv::OutputArray, double, double, bool), file /build/master_pack-android/opencv/modules/imgproc/src/canny.cpp, line 959
E/org.opencv.imgproc: imgproc::Canny_11() caught cv::Exception: /build/master_pack-android/opencv/modules/imgproc/src/canny.cpp:959: error: (-215) _dx.type() == CV_16SC1 || _dx.type() == CV_16SC3 in function void cv::Canny(cv::InputArray, cv::InputArray, cv::OutputArray, double, double, bool)
W/System.err: CvException [org.opencv.core.CvException: cv::Exception: /build/master_pack-android/opencv/modules/imgproc/src/canny.cpp:959: error: (-215) _dx.type() == CV_16SC1 || _dx.type() == CV_16SC3 in function void cv::Canny(cv::InputArray, cv::InputArray, cv::OutputArray, double, double, bool)
W/System.err: ]
W/System.err: at org.opencv.imgproc.Imgproc.Canny_1(Native Method)
W/System.err: at org.opencv.imgproc.Imgproc.Canny(Imgproc.java:984)
W/System.err: at app.android.opencvproject.OpenCVText.detectContours(OpenCVText.java:185)
W/System.err: at app.android.opencvproject.CameraPreview$1$1.run(CameraPreview.java:428)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)

我不知道是什么原因导致错误,我在互联网上也没有找到任何答案。

这是我使用的代码:

public void detectContours(Bitmap bitmap){
try{
Mat img = new Mat();
Utils.bitmapToMat(bitmap, img);

Mat gray = new Mat(img.size(), CvType.CV_8UC1);
Imgproc.cvtColor(img, gray, Imgproc.COLOR_RGB2GRAY, 4);
Imgproc.Canny(gray, gray, 80, 100);

Bitmap outputBitmap = Bitmap.createBitmap(gray.cols(), gray.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(gray, outputBitmap);
MediaStore.Images.Media.insertImage(context.getContentResolver(), outputBitmap, "Opencv" , "Hello");
Log.d("OPENCV", "Image stored in your gallery");
}catch (Exception e){
e.printStackTrace();
}
}

谁能帮我解决这个问题?

提前致谢!

最佳答案

在应用 cvtColor 后,您是否尝试过检查灰色输出?

你能检查你的图像类型吗(意味着调用 getType())

关于java - Android Java Opencv canny 抛出 cvexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42349966/

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