java.lang.UnsupportedOperationException: Mat data type is not compatible: 6[SOLVED]
I was implementing the tutorial of anisotropic image segmentation in java and wrote the following code:
```
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
class AnisotropicImageSegmentationrun{
public void run(){
int W = 52;
double C_Thr = 0.43;
int LowThr = 35;
int HighThr = 57;
Mat imgIn = new Mat();
imgIn = Imgcodecs.imread("C:\\Users\\goura\\IdeaProjects\\first_project\\data\\gst_input.jpg",Imgcodecs.IMREAD_GRAYSCALE);
if(imgIn.empty()){
System.out.println("ERROR : Image cannot be loaded..!!");
System.exit(-1);
}
Mat imgCoherency = new Mat(),imgOrientation = new Mat();
calcGst(imgIn, imgCoherency, imgOrientation, W);
Mat imgCoherencyBin = new Mat();
Core.compare(imgCoherency, new Scalar(C_Thr), imgCoherencyBin, Core.CMP_GT);
Mat imgOrientationBin = new Mat();
Core.inRange(imgOrientation, new Scalar(LowThr), new Scalar(HighThr), imgOrientationBin );
Mat imgBin = new Mat();
Core.bitwise_and(imgCoherencyBin, imgOrientationBin, imgBin);
Core.normalize(imgCoherency, imgCoherency, 0, 255, Core.NORM_MINMAX);
Core.normalize(imgOrientation, imgOrientation, 0, 255, Core.NORM_MINMAX);
Core.add(imgIn, imgBin,imgIn);
Core.multiply(imgIn, new Scalar(0.5), imgIn);
HighGui.imshow("result", imgIn);
HighGui.imshow("Coherency", imgCoherency);
HighGui.imshow("Orientation", imgOrientation);
HighGui.waitKey(0);
System.exit(0);
}
void calcGst(Mat inputImg, Mat imgCoherencyOut, Mat imgOrientationOut, int w){
Mat img = new Mat();
inputImg.convertTo(img, CvType.CV_64F);
// GST components calculation (start)
// J = (J11 J12; J12 J22) - GST
Mat imgDiffX = new Mat(), imgDiffY = new Mat(), imgDiffXY = new Mat();
Imgproc.Sobel(img, imgDiffX, CvType.CV_64F, 1, 0, 3);
Imgproc.Sobel(img, imgDiffY, CvType.CV_64F, 0, 1, 3);
Core.multiply(imgDiffX, imgDiffY, imgDiffXY);
Mat imgDiffXX = new Mat(), imgDiffYY = new Mat();
Core.multiply(imgDiffX, imgDiffX, imgDiffXX);
Core.multiply(imgDiffY, imgDiffY, imgDiffYY);
// J11, J22 and J12 are GST components
Mat J11 = new Mat(), J22 = new Mat(), J12 = new Mat();
Imgproc.boxFilter(imgDiffXX, J11, CvType.CV_64F, new Size(w, w));
Imgproc.boxFilter(imgDiffYY, J22, CvType.CV_64F, new Size(w, w));
Imgproc.boxFilter(imgDiffXY, J12, CvType.CV_64F, new Size(w, w));
// GST components calculation (stop)
// eigenvalue calculation (start)
// lambda1 = J11 + J22 + sqrt((J11-J22)^2 + 4*J12^2)
// lambda2 = J11 + J22 - sqrt((J11-J22)^2 + 4*J12^2)
Mat tmp1 = new Mat(), tmp2 = new Mat(), tmp3 = new Mat(), tmp4 = new Mat();
Core.add(J11, J22, tmp1);
Core.subtract(J11, J22, tmp2);
Core.multiply(tmp2, tmp2, tmp2);
Core.multiply(J12, J12, tmp3);
Mat tmp3Mul4 = new Mat() , tmp2AddTmp3Mul4 = new Mat();
//4.0*tmp3
Core.multiply(tmp3, new Scalar(4.0), tmp3Mul4);
//tmp2 + 4.0*tmp3
Core.add(tmp3Mul4, tmp2, tmp2AddTmp3Mul4);
Core.sqrt(tmp2AddTmp3Mul4, tmp4);
Mat lambda1 = new Mat(), lambda2 = new Mat();
Core.add(tmp1, tmp4, lambda1);// biggest eigenvalue
Core.subtract(tmp1, tmp4, lambda2);// smallest eigenvalue
// eigenvalue calculation (stop)
// Coherency calculation (start)
// Coherency = (lambda1 - lambda2)/(lambda1 + lambda2)) - measure of anisotropism
// Coherency is anisotropy degree (consistency of local orientation)
Mat lambda1SubLambda2 = new Mat(), lambda1AddLambda2 = new Mat();
Core.subtract(lambda1, lambda2 ,lambda1SubLambda2);
Core.add(lambda1, lambda2, lambda1AddLambda2);
Core.divide(lambda1SubLambda2, lambda1AddLambda2, imgCoherencyOut);
//System.out.println(imgCoherencyOut.dump());
// Coherency calculation (stop)
// orientation angle calculation (start)
// tan(2*Alpha) = 2*J12/(J22 - J11)
// Alpha = 0.5 atan2(2*J12/(J22 - J11))
Mat J22_J11 = new Mat(), J12Mul2 = new Mat();
Core.subtract(J22, J11, J22_J11);
Core.multiply ...
@berak I have added the lines where the error has occurred
^^ yep, thanks, helpful ! ;)