OpenCV Error: Assertion failed (ssize.area () 0)

1

I'm 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

p>

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);
    
asked by anonymous 24.10.2014 / 04:06

1 answer

1

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

Try the following steps:

  • Make sure the opencv libraries have been properly linked;
  • Test with an image loaded directly from the disk using imread() .
  • If step 2 worked, add sleep() or waitkey() after cap.read(img) to wait for a video response.
  • If you have any questions, please let us know in the comments.

        
    24.10.2014 / 07:22