Ask Your Question
0

Rectangle Issues

asked 2017-05-10 00:34:03 -0600

zenty gravatar image

So I am trying to draw rectangles from contours and then save them as an image but whenever i use Imgproc.rectangle() the resulting Mat always comes out empty, my code is basically just...

       private Mat rectOut = new Mat();
       for(MatOfPoint contour : contours){
        Rect rect = Imgproc.boundingRect(contour);
        Imgproc.rectangle(rectOut, rect.tl(), rect.br(), new Scalar(50,50,50));
       }

The rect seems to be fine and has the points I want but the result always leaves me with an Empty mat, does anyone know what I am doing wrong?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-10 00:38:57 -0600

berak gravatar image

the proble is here:

private Mat rectOut = new Mat();

that is an empty Mat, with no pixels, of size (0,0)

if you want to draw something, you need to allocate pixels:

private Mat rectOut = new Mat(480, 640, CvType.CV_8UC3, Scalar.all(0));
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-10 00:32:53 -0600

Seen: 322 times

Last updated: May 10 '17