OpenCV の Java ラッパーを使用して流域セグメンテーションを実装しようとしています。
これが私がやっていることです:
public void watershedSegmentation(Mat image)
{
Mat target = new Mat(image.rows(), image.cols(), CvType.CV_8UC3);
Imgproc.cvtColor(image, target, Imgproc.COLOR_BGRA2RGB);
//Conversion to 8UC1 grayscale image
Mat grayScale = new Mat(image.rows(), image.cols(), CvType.CV_64FC1);
Imgproc.cvtColor(image, grayScale, Imgproc.COLOR_BGR2GRAY);
//Otsu's Threshold, applied to the grayscale image
Imgproc.threshold(grayScale, grayScale, 0, 255, Imgproc.THRESH_OTSU);
//constructing a 3x3 kernel for morphological opening
Mat openingKernel = Mat.ones(3,3, CvType.CV_8U);
Imgproc.morphologyEx(grayScale, grayScale, Imgproc.MORPH_OPEN, openingKernel, new Point(-1,-1), 3);
//dilation operation for extracting the background
Imgproc.dilate(grayScale, grayScale, openingKernel, new Point(-1,-1), 1);
Imgproc.watershed(target, grayScale);
}
「watershed」を呼び出した時点で、次のようなエラーが表示されます。
OpenCV Error: Unsupported format or combination of formats (Only 32-bit, 1-channel output images are supported) in cvWatershed, file ..\..\..\..\opencv\modules\imgproc\src\segmentation.cpp, line 151
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\imgproc\src\segmentation.cpp:151: error: (-210) Only 32-bit, 1-channel output images are supported in function cvWatershed
]
at org.opencv.imgproc.Imgproc.watershed_0(Native Method)
at org.opencv.imgproc.Imgproc.watershed(Imgproc.java:9732)
at segmentation.Segmentation.watershedSegmentation(Segmentation.java:60)
at segmentation.Segmentation.main(Segmentation.java:29)
わかりました。OpenCV は、出力として 32 ビットの 1 チャネル ファイルを探しています。
考えられるすべての組み合わせを試しました:
CvType.CV_32FC1、
CvType.CV_32F、
CvType.CV_32S、
CvType.CV_32SC1、
CvType.CV_8UC1、
CvType.CV_16UC1
...それらすべて。
エラーは回復力があります。それは去ることを拒否します。
助けてください。
前もって感謝します。