Ask Your Question
-1

how to resolve (-215:Assertion failed) !_src.empty() in function 'cv::boxFilter'

asked 2020-07-11 06:51:59 -0600

Menna gravatar image

updated 2020-07-11 07:23:44 -0600

berak gravatar image

Hello everyone, I am creating a system for object recognition, more precisely for license plates, it is for a control system for the beach in my city. I'm using Java and the latest version of OpenCv 4.3.0, I can open the camera without errors. The problem is in the code for plate recognition, it's giving errors, but it's about the version or something. I will leave the code of the classes, and the errors, I hope someone can help me. ENTRY CLASS

public class entrada {
    public static void main(String[] args) {
        try {
            // carregando a biblioteca
            System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
            System.out.println("começando");
            int[] mm = { 10,100 };
            int[] nn = { 10,100,300 };
            int[] aa = { 1 };
            int[] bb = { 5};
            int[] cc = { 5,10,15 };
            int[] dd = { 3 };
            int[] ee = {200};
            for (int m = 0; m < mm.length; m++) {
             for (int n = 0; n < nn.length; n++) {
              for (int a = 0; a < aa.length; a++) {
               for (int b = 0; b < bb.length; b++) {
                for (int c = 0; c < cc.length; c++) {
                 for (int d = 0; d < dd.length; d++) {
                  for(int e = 0; e < ee.length;e++){
                     // carregando a imagem original, ja em escala de cinza
                     Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");
                     BufferedImage temp = reconhecimento.reconhecedorPlaca(imageGray, 
                            mm[m], nn[n], aa[a], bb[b], cc[c], dd[d],ee[e]);

                      File outputfile = new File("final" + aa[a]
                       + "x" + bb[b] + "x" + cc[c] + "x" + dd[d] + "x" +ee[e]
                        +"x"+ ".jpg");

                       ImageIO.write(temp, "jpg", outputfile);
            }}}}}}}
        } catch (IOException e) {
        System.out.println("Error: " + e.getMessage());
    }
}

CLASSE 2

public class reconhecimento {


 public static int ver =0;
 public static BufferedImage reconhecedorPlaca(Mat matrix,int m,int n,int a,int b,int c,int d,int e ) {

     int cols = matrix.cols();
     int rows = matrix.rows();

     int elemSize = (int)matrix.elemSize();

     byte[] data = new byte[cols * rows * elemSize];

     int type;

     Mat imagemResultanteCanny = new  Mat(matrix.rows(),matrix.cols(),CvType.CV_8UC1);

     Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3));
     Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true);
     Imgcodecs.imwrite("canny"+m+"x"+n+"x3ver"+ver+".jpg", imagemResultanteCanny);
     ver++;

     Mat lines = new Mat();
     Imgproc.HoughLinesP(imagemResultanteCanny, lines, 2, Math.PI/180, b, c, d);
     System.out.println(lines.size());

     for (int x = 0; x < lines.cols(); x++)
     {
         double[] vec = lines.get(0, x);

         org.opencv.core.Point start = new org.opencv.core.Point();
         start.x = (int) vec[0];
         start.y = (int) vec[1];

         org.opencv.core.Point end = new org.opencv.core.Point();
         end.x = (int) vec[2];
         end.y = (int) vec[3];

         Imgproc.line(matrix, start, end, new Scalar(255,255,255), 2); 
     }



    Mat imagemResultanteCorner = new Mat();

     Imgproc.cornerHarris(imagemResultanteCanny, imagemResultanteCorner, 2, 3, 0.04, 1);

     Mat n_norm = new Mat();
     normalize(imagemResultanteCorner, n_norm,0,255,Core.compareTo(Core),CvType.CV_32FC1);
    Mat s_norm = new Mat();
     //Imgproc.conveScaleAbs(n_norm, s_norm);
     Imgcodecs.imwrite("corner"+m+"x"+n+"x"+a+"x"+b+"x"+c+"x"+d+"x"+e+"ver"+ver+".jpg",s_norm ...
(more)
edit retag flag offensive close merge delete

Comments

try again in english, please

also, please do not throw your whole app at us, but try to come up with a minimal reproducing example, thank you.

berak gravatar imageberak ( 2020-07-11 06:53:23 -0600 )edit
1

It is in english

Menna gravatar imageMenna ( 2020-07-11 07:02:49 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2020-07-11 07:13:16 -0600

berak gravatar image

updated 2020-07-11 08:15:46 -0600

Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg\"");

this did not work, imageGray is empty.

your filename is already invalid, since \" will resolve to a trailing \

try:

 Mat imageGray = Imgcodecs.imread("C:\\Users\\PC\\Desktop\\placa.jpg");

tips for the future:

  • ALWAYS check like if (image.empty()) when using imread(), using VideoCapture, etc. IO can never be trusted
  • if you get an assertion, follow it upwards in your code, use a lot of print statements, Mat.dump(),... the actual reason for your problem is mostly a few layers up, not where the assert happens
  • never use your native language for variable names, comments and such, stick with (whatever broken, it does not matter !!) english, the day will come, when you will need help from the internet community...
edit flag offensive delete link more

Comments

I changed where it is empty, but still the error continues:

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.3.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\canny.cpp:834: error: (-215:Assertion failed) (_dst.getObj() != _src.getObj() || _src.type() == CV_8UC1) && "Inplace parameters are not supported" in function 'cv::Canny']
at org.opencv.imgproc.Imgproc.Canny_2(Native Method)
at org.opencv.imgproc.Imgproc.Canny(Imgproc.java:2662)
Menna gravatar imageMenna ( 2020-07-11 11:30:53 -0600 )edit

line of errors:

Imgproc.blur(matrix, imagemResultanteCanny,new Size(3,3));
 Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true);
Menna gravatar imageMenna ( 2020-07-11 11:36:42 -0600 )edit

that's a different error (expect any noob's prog to have like 20 hidden more...)

berak gravatar imageberak ( 2020-07-11 11:37:59 -0600 )edit

what is it, you don't understand here ?

"Inplace parameters are not supported" in function 'cv::Canny'

given:

Imgproc.Canny(imagemResultanteCanny, imagemResultanteCanny, m, n, 3, true);

(you need another new Mat() for the result, can't re-use imagemResultanteCanny for it)

berak gravatar imageberak ( 2020-07-11 11:48:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-07-11 06:51:59 -0600

Seen: 3,119 times

Last updated: Jul 11 '20