sanks
unread,Oct 3, 2011, 3:17:10 AM10/3/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-opencv
Hello,
I am new to OpenCV android. I downloaded the Android binary package
with Eclipse and got it installed in windows. I then loaded the
examples given (which worked when I ran it on my device perfectly) ,
added OpenCV 2.3.1 Library to my new android project. I am already
calling the camera intent of Android using which I take a photo.
I will now have to process the image using OpenCV.
So after I take the photo (as a JPEG) , a new activity fires up and I
use this
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
to get my bitmap. I would now like to convert it into a Mat for me to
be able to use it, to do further processing.
I have two approaches in mind.
a) save the bitmap and then read it again ( I would preferably like to
save and load from internal phone memory)
b) since I already have the bitmap, might as well convert it to a
matrix and use it directly.
for approach b)
I read another similar thread in this forum and used a function posted
by Mr.Aaron Brown
which is Bitmap JPEGtoRGB888(Bitmap img). It seemed to work when
converting from bitmap -> mat,
but I was not able to convert it back using mat -> bitmap. It either
breaks or returns nothing.
for approach a)
This seemed to work partially,
//get cameraimage
.
.
.
//save it to internal memory
.
.
//load it as a drawable
.
.
.
ImageView image = (ImageView) findViewById(R.id.cameraphotoview);
if(bitmap != null)
{
Mat img;
try {
img = Utils.loadResource(getBaseContext(), R.drawable.im1);
Imgproc.blur(img, img, new Size(30, 30));
Bitmap bmp =
Bitmap.createBitmap(img.cols(),img.rows(),Bitmap.Config.ARGB_8888);
org.opencv.android.Utils.matToBitmap(img, bmp);
image.setImageBitmap(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
by partially I mean, it garbled the output bitmap if my drawable was a
jpeg. if it was a png, I could convert mat to bitmap and see the image
blur, but the color property got messed up, meaning there was a blue
tint over the image. I am sure I am missing the right conversion
parameter here. Just dont know where!
As an other alternate approach, is it a good idea to use JNI and pass
the bit map as a byte array or something and get back the result?
Sorry for such a long post. Been hacking at it all day and it pains me
to not be able to do such a trivial bitmap conversion.
Appreciate for the help in advance,
Thanks,
sanks