Ask Your Question
0

OPENCV and JAVA erode

asked 2016-11-15 15:28:24 -0500

sArA gravatar image

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-16 08:06:52 -0500

berak gravatar image

updated 2016-11-17 03:57:39 -0500

please check source.empty() after imread() (most probably your image did not load)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-15 15:28:24 -0500

Seen: 1,152 times

Last updated: Nov 17 '16