Opencv Error: Assertion failed (ssize.area() > 0)

Asked

Viewed 208 times

1

I am having the following error with the Opencv library in Java:

Opencv Error: Assertion failed (ssize.area() > 0) in cv::resize, file ..... opencv modules imgproc src imgwarp.cpp, line 1834

Code:

    Mat img = new Mat();
    // capturar primeiro frame do video 
    VideoCapture cap = new VideoCapture(Options.videoAtual);
    cap.read(img);

    // passar a imagem para tons de cinza
    Mat grayImg = new Mat();
    Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY);

    // aplicar filtro da media para reduzir os ruidos
    Imgproc.medianBlur(grayImg, grayImg, 7);
    Highgui.imwrite("tmp/img1.jpg", grayImg);

    // aplicar transformada circular de hough
    Mat circles = new Mat();
    Imgproc.HoughCircles(grayImg, circles, Imgproc.CV_HOUGH_GRADIENT,1,20, 
            180,18,minRaio,maxRaio);

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

        Point center = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
        int radius = (int) Math.round(vCircle[2]);

        Centro = center;
        Raio = radius;

        // draw the circle outline
        Core.circle(img, center, radius, new Scalar(0, 0, 255), 3, 8, 0);
    }

    Highgui.imwrite("houghcircles.jpg", img);
  • Have you figured out which of the lines in your code is responsible for triggering this error? Use the Debugger.

1 answer

1

This error indicates that the source image is empty (invalid image).

Try to follow the following steps:

  1. Make sure the opencv libraries are properly linked;
  2. Test with an image loaded directly from the disk using imread().
  3. If step 2 worked, add a sleep() or a waitkey() after the cap.read(img) to await a response from the video.

If you have any questions, ask in the comments.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.