Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thought I could get the data converted from the <code>SurfaceView</code>. But the best method to use is : </p> <ul> <li>Set the camera's orientation to 90 degrees.</li> <li>Set output format to NV21 (which is <a href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setPreviewFormat%28int%29" rel="nofollow">guranteed</a> to be supported on all devices).</li> <li>Set to turn the Flash ON.</li> <li>Start preview in the <code>SurfaceView</code>.</li> </ul> <p>List item</p> <pre><code>camera = Camera.open(); cameraParam = camera.getParameters(); cameraParam.setPreviewFormat(ImageFormat.NV21); camera.setDisplayOrientation(90); camera.setParameters(cameraParam); cameraParam = camera.getParameters(); camera.setPreviewDisplay(surfaceHolder); cameraParam.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(cameraParam); camera.startPreview(); </code></pre> <p>Then, I call the <code>setPreviewCallback</code> and <code>onPreviewFrame</code> to get the incoming frame, and convert it to RGB pixel array. Which I can then get intensity of each color in the picture by averaging all pixels intensity by running myPixels array through a <code>for</code> loop, and checking <code>Color.red(myPixels[i])</code> for each desired color (inside the <code>onPreviewFrame</code>). </p> <pre><code>camera.setPreviewCallback(new PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { int frameHeight = camera.getParameters().getPreviewSize().height; int frameWidth = camera.getParameters().getPreviewSize().width; // number of pixels//transforms NV21 pixel data into RGB pixels int rgb[] = new int[frameWidth * frameHeight]; // convertion int[] myPixels = decodeYUV420SP(rgb, data, frameWidth, frameHeight); } } </code></pre> <p>Where <code>decodeYUV420SP</code> is found <a href="http://www.akeric.com/blog/?p=1342#viewSource" rel="nofollow">here</a>.</p> <p>I timed this operation to take about 200ms for each frame. <em>Is there a faster way of doing it?</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload