hi

I am working on an android program to process multiple frames
of camera images. I used the setPreviewCallbackWithBuffer
function and process the data inside the PreviewCallback. The
code works generally ok, except the resulting data have weird
values.

I set the camera picture format to RGB565, and then create
an int[] buffer, with the same size of the byte[] in a frame, and
taking accumulated image of the red-channel.

The following is my code:

public class NIRSActivity extends Activity {

   int[] avg; // integer buffer to accumulate the red channel
   int frame; // frame counter

   public void onCreate(Bundle savedInstanceState) {
         avg=new int[320*480]; // do I need to do Array.fill?
         frame=0;
         ....
        param.setPreviewSize(320,480);
         ....
        camera.setPreviewCallbackWithBuffer(onPreviewFrame);
        camera.startPreview();
   }
   public void onPreviewFrame(byte[] data, Camera camera) {
         // extract the red channel from RGB565

         for(int i=0;i<data.length;i+=2){
byte red=(byte) ((data[i] >> 3 ) & 0x1F); // RRRRRGGG | GGGBBBBB
             avg[i>>1]+=red;
         }
ByteBuffer byteBuf = ByteBuffer.allocate(2 * data.length); //data.length is 2*320*480
         IntBuffer intBuf = byteBuf.asIntBuffer();
         intBuf.put(avg);

FileOutputStream out = new FileOutputStream( "/sdcard/nirs_avg_"+Integer.toString(frame)+".raw");
         out.write(byteBuf.array());
         out.flush();
         out.close();
         frame++;
   }
}

if I plot the data, converted to a 2D image in matlab, the
images look like wrapped phase maps, with large numbers
around 10^8 ~ 10^9.

I am not familiar with Java. Can someone please give me a
hint which part of my code is wrong? I really appreciate
your input.

thank you in advance.

Qianqian

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to