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?
Possible you are reading it in as a 3 channel color image, and the drawing functions assume a single channel mat element. (just a guess here) Can you try reading your image as grayscale image? Then apply the drawing? If this works, to keep your color image, split the channels first, draw, then recombine. But it seems strange to me .. I thought we could draw on 3 channel images without problems...
Hi Steven, thank you for the reply. I've tried reading the image in as greyscale and drawing. No luck so far!
It is actually pretty weird. I am doing the exact thing and it seems to work for me. However I am using the C++ interface and haven't tested the Java API jet. So no idea what to expect. I will post some dummy code on how I do this in C++.