2014-07-23 2 views
0

OpenCV 용 Java 래퍼를 사용하여 유역 분할을 구현하려고합니다. 나는 '분수령'호출 어디라는 오류를 참조OpenCV의 유역 분할에 대한 이미지 형식이 일치하지 않습니다.

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); 

    } 

오른쪽 지점에서 : 여기

내가 뭘하는지의 나는 그것을 얻을

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

... 그들 모두.

오류는 복원력이 있습니다. 그것은 사라지지 않습니다.

도와주세요.

미리 감사드립니다.

답변

2

귀하의 그레이 스케일 행렬은 지역의 초기 씨앗 가득, 당신은

watershed 두 번째 행렬 매개 변수가 CV_32F 매트릭스있을 것으로 기대 Imgproc.cvtColor(image, grayScale, Imgproc.COLOR_BGR2GRAY);을 통과 한 후에는, CV_64F 플래그를 사용하여 만든 경우에도 형 CV_8UC1의 가장 아마 the doc을 참조하십시오. 그냥 실행 유역하려는 경우, 당신은 같은 것을 할 수있는 의견에 따라

[편집] :

Mat seeds = new Mat(image.rows(), image.cols(), CvType.CV_32FC1); 
for (int i = 0; i < 10; ++i) { 
    // initialize 10 random seeds 
    seeds.at<float>(rand()%image.rows, rand()%image.cols) = i; // translate that into the Java interface 
} 
Imgproc.watershed(target, seeds); 
+0

확인을, 그래서 당신이 cvtColor (...)를 용의자로 이미지 유형을 변화 CV_8UC1? 가능한 해결 방법이 될 수 있습니다 (회색 음영이 필요하기 때문에). – metsburg

+0

당신이 맞는지 확인할 수 있습니다. cvtColor() 전후에 grayScale.depth()를 확인했습니다. 하나의 채널로 변경됩니다. 하지만 아직 해결책을 찾지 못했습니다. – metsburg

+0

정확히 무엇을하려고합니까? 두 번째 행렬은 유역 알고리즘에 대한 이니셜 라이저 (영역 시드 제공)입니다. 내가 추측 해보 자면, 그레이 스케일로 변환하고, otsu + morpho를 사용하여 연결된 구성 요소를 생성합니다. 이것이 여러분이하는 일입니다. 그런 다음 연결된 구성 요소에 레이블을 붙이고 CV_32F의 행렬에 넣고 유역을 호출합니다. – remi

관련 문제