Ask Your Question
1

Image read and display android

asked 2013-02-05 23:18:07 -0600

muthu gravatar image

I want to read an image from sdcard to Mat object and use it...here's the snippet

            inputFrame.copyTo(mRgba);
            Rect roi=new Rect(10, 10, 128, 128);
            Mat sm=new Mat(m2,roi);
            sm=Highgui.imread("/mnt/sdcard/coke.bmp");
            Core.addWeighted(mRgba,0.5, m2,0.5,0, mRgba);

The image i read is of size 128*128 ...so i defined a submat with the exact ROI range... I mounted the sd-card image and also included the file in it.... Yet the uotput doesnt show the imaeg... The Mat m2 is empty

I also wanna know if the image can be of larger size than the Mat to which i read??If so will it be rescaled automatically??

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-08 10:07:38 -0600

Andrey Pavlenko gravatar image

The imread() functions allocates a new Mat, so the code should be like:

Mat cokeBGR = Highgui.imread("/mnt/sdcard/coke.bmp");
Mat cokeRGBA = new Mat();
Imgproc.cvtColor(cokeBGR, cokeRGBA, Imgproc.COLOR_BGR2RGBA);
Imgproc.resize(cokeRGBA, sm, sm.size());
edit flag offensive delete link more
0

answered 2013-02-06 00:30:34 -0600

Mat object uses reference counting approach, Mat has reference to real image data. When you select submat of another Mat object new Mat will share the same frame data. When you read image that is grater then destination Mat data is relocated. In your case sm object reallocates it buffer after image reading and does not reference to part of original frame.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-05 23:18:07 -0600

Seen: 4,744 times

Last updated: Feb 08 '13