拉普拉斯 OpenCV Android 不工作

Laplacian OpenCV Android not working

我正在尝试在我的应用程序中使用拉普拉斯算子:

Bitmap result = source.copy(source.getConfig(), true);
Utils.bitmapToMat(source, in);
Imgproc.Laplacian(in, out, 3, 3, 1, 0);
Utils.matToBitmap(out, result);

但我收到以下错误:

E/cv::error()﹕ OpenCV Error: Assertion failed (src.type() == CV_8UC1 || src.type() == CV_8UC3 || src.type() == CV_8UC4) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

根据 documentation Utils.matToBitmap 仅接受 MatCV_8U 深度。在您的示例中,您将输出深度指定为 CV_16S。您应该为 Imgproc.Laplacian 指定输出深度,如下所示:

Imgproc.Laplacian(in, out, CvType.CV_8U, 3, 1, 0); 
Utils.matToBitmap(out, result);

请参阅 documentation 拉普拉斯算子。