Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi All,

I am using OpenCV 2.4.6.1 on OSX 10.8.4 using the Java API with IntelliJ. I am developing a very simple application that works on a 640x480 24bpp Mat object which is an image read in from disk.

I have code to draw rectangles and lines, but despite changing the point coordinates for start and end only a single pixel is drawn at 0,0 of the Mat. The lines and rectangles seem to ignore any combination of coordinates I give and always result in this strange result. Here is some code:

Mat color_origImg = Highgui.imread("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg");
Core.line(color_origImg, new Point(50,50), new Point(10, 100), new Scalar(255,0,0), 1);
Highgui.imwrite("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg", color_origImg);

The image is definitely being read in correctly but I can't for the life of me figure out why plotting lines, rectangles or other sorts of shapes on a Mat object doesn't work as expected. I've tried black and white images, using CvtColor too ... all to no avail.

Can anyone offer some advice?

Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi All,

I am using OpenCV 2.4.6.1 on OSX 10.8.4 using the Java API with IntelliJ. I am developing a very simple application that works on a 640x480 24bpp Mat object which is an image read in from disk.

I have code to draw rectangles and lines, but despite changing the point coordinates for start and end only a single pixel is drawn at 0,0 of the Mat. The lines and rectangles seem to ignore any combination of coordinates I give and always result in this strange result. Here is some code:

Mat color_origImg = Highgui.imread("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg");
Core.line(color_origImg, new Point(50,50), new Point(10, 100), new Scalar(255,0,0), 1);
Highgui.imwrite("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg", color_origImg);

The image is definitely being read in correctly but I can't for the life of me figure out why plotting lines, rectangles or other sorts of shapes on a Mat object doesn't work as expected. I've tried black and white images, using CvtColor too ... all to no avail.

Can anyone offer some advice?