Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OPENCV and JAVA erode

i have a problem with this code help me plz

import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc;

public class main { public static void main( String[] args ) {

  try{  
     System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
     System.out.println(System.getProperty("java.library.path"));
     Mat source = Imgcodecs.imread("moi.jpg",  Imgcodecs.CV_LOAD_IMAGE_COLOR);
     Mat destination = new Mat(source.rows(),source.cols(),source.type());

     destination = source;

     int erosion_size = 5;
     int dilation_size = 5;

     Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*erosion_size + 1, 2*erosion_size+1));
     Imgproc.erode(source, destination, element);
     Imgcodecs.imwrite("erosion.jpg", destination);

     source =Imgcodecs.imread("moi.jpg",  Imgcodecs.CV_LOAD_IMAGE_COLOR);

     destination = source;

     Mat element1 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new  Size(2*dilation_size + 1, 2*dilation_size+1));
     Imgproc.dilate(source, destination, element1);
     Imgcodecs.imwrite("dilation.jpg", destination);

  }catch (Exception e) {
     System.out.println("error: " + e.getMessage());
  }

} } OpenCV Error: Assertion failed (m.dims >= 2) in cv::Mat::Mat, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\core\src\matrix.cpp, line 454 error: cv::Exception: C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\core\src\matrix.cpp:454: error: (-215) m.dims >= 2 in function cv::Mat::Mat