java - Get pixels matrix from YUV byte array -


i need pixels matrix yuv byte[] array obtain camera preview in onpreviewframe function. need pixels in form of matrix in order implement further image processing. i'm doing in following way:

  1. byte[] array yuv image
  2. yuv image jpeg.
  3. jpeg bitmap.
  4. bitmap pixels array.
  5. pixels array pixels matrix.

is there optimal way achieving same results? currently, implementation follow.

@override public void onpreviewframe(byte[] data, camera camera) {  try {     final yuvimage image = new yuvimage(data, imageformat.nv21,             size.width, size.height, null);     final file file = new file(environment.getexternalstoragedirectory()             .getpath() + "/" + string.valueof(br) + "out.jpg");     final fileoutputstream file_o_s = new fileoutputstream(file);     thread comp_thread = new thread(new runnable() {         @override         public void run() {             try {                 image.compresstojpeg(                         new rect(0, 0, size.width, size.height), 40,                         file_o_s);                 file_o_s.flush();                 file_o_s.close();                  bitmap bmap = bitmapfactory.decodefile(file.getpath());                 int[] pixels_array = new int[bmap.getheight()*bmap.getwidth()];                 bmap.getpixels(pixels_array, 0, bmap.getwidth(), 0, 0, bmap.getwidth(), bmap.getheight());                 int[][] pixels_matrix = new int[bmap.getheight()][bmap.getwidth()];                  int start = 0;                 (int r = 0; r < bmap.getheight(); r++) {                     int l = math.min(bmap.getwidth(), pixels_array.length - start);                     pixels_matrix[r] = java.util.arrays.copyofrange(pixels_array, start, start + l);                     start += l;                 }              } catch (ioexception e) {                 e.printstacktrace();             }          }     });     comp_thread.start();  } catch (exception e) {     log.e(tag, e.getmessage()); } } 

just specify camera preview must provide rgb images

i.e. camera.parameters.setpreviewformat(imageformat.rgb_565);


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -