we provide information about gadget news and price information and specs samsung, huawei, Tecno Price products, Specifications, Features and more information about software from blackberry and android

Friday, May 1, 2015

Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java - Did you know that every day there is always a new technology that is created? if you want to know please refer to the blog Gadget News well now we will discuss first about Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java as you need now, we have compiled this article carefully, so please see to finish.

Articles : Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java
full Link : Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

You can also see our article on:


Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

Hi techies,

Now iam gonna share a wonderful and efficient way on "How to convert IplImage to byte array in JavaCV" with pure java code.



How to convert IplImage to Android Bitmap

public static Bitmap IplImageToBitmap(IplImage src) {
Bitmap bm=null;
   int width = src.width();
   int height = src.height();
// Unfortunately cvCvtColor will not let us convert in place, so we need to create a new IplImage with matching dimensions.
IplImage frame2 = IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, 4);
opencv_imgproc.cvCvtColor(src, frame2, opencv_imgproc.CV_BGR2RGBA);
                   // Now we make an Android Bitmap with matching size ... Nb. at this point we functionally have 3 buffers == image size. Watch your memory usage!
bm = Bitmap.createBitmap(frame2.width(), frame2.height(), Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(frame2.getByteBuffer());
//src.release();
frame2.release();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return bm;
}


How to convert IplImage to byte[]

public static byte[] IplImageToByteArray(IplImage src) {
Bitmap bm=null;
    int width = src.width();
    int height = src.height();
 // Unfortunately cvCvtColor will not let us convert in place, so we need to create a new IplImage with matching dimensions.
  IplImage frame2 = IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, 4);
  opencv_imgproc.cvCvtColor(src, frame2, opencv_imgproc.CV_BGR2RGBA);
                    // Now we make an Android Bitmap with matching size ... Nb. at this point we functionally have 3 buffers == image size. Watch your memory usage!
  bm = Bitmap.createBitmap(frame2.width(), frame2.height(), Bitmap.Config.ARGB_8888);
  bm.copyPixelsFromBuffer(frame2.getByteBuffer());
  //src.release();
  frame2.release();
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
  return stream.toByteArray();
}

So hope you guys got this helper methods so useful for your JavaCV projects.
And don't forget to use the comment box below.



article Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java has been completed in the discussion

hopefully the information Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java that we provide can be useful for you to know the development of technology in the present

articles Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java we have conveyed to you, if feel this information is useful and you want to bookmark or share so that more people who know please use link https://profsmythe.blogspot.com/2015/05/convert-iplimage-to-byte-array-or.html.

Tag :
Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Convert IplImage to byte array or IplImage to Bitmap in JavaCV - Android Java

0 comments:

Post a Comment