最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android人臉識別Demo豎屏YUV方向調(diào)整和圖片保存(分享)

 更新時間:2017年12月22日 14:15:16   作者:iblade  
下面小編就為大家分享一篇Android人臉識別Demo實(shí)現(xiàn)豎屏YUV方向調(diào)整和圖片保存的方法。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

本博客包含三個常用方法,用于盛開Android版人臉識別Demo中豎屏使用時送入yuv數(shù)據(jù),但一直無法識別的情況。

1.首先可以嘗試順時針旋轉(zhuǎn)90°或270°,然后送入識別SDK。

2.旋轉(zhuǎn)方向后依然無法識別時,可以嘗試saveImg( ),保存本地檢查圖片是否符合要求。

 /**
  * 視頻順時針旋轉(zhuǎn)90
  * 該方法僅僅在豎屏?xí)r候使用
  * */
 public static byte[] rotateYUV420Degree90(byte[] data, int imageWidth,
          int imageHeight) {
  byte[] yuv = new byte[imageWidth * imageHeight * 3 / 2];
  int i = 0;
  for (int x = 0; x < imageWidth; x++) {
   for (int y = imageHeight - 1; y >= 0; y--) {
    yuv[i] = data[y * imageWidth + x];
    i++;
   }
  }
  i = imageWidth * imageHeight * 3 / 2 - 1;
  for (int x = imageWidth - 1; x > 0; x = x - 2) {
   for (int y = 0; y < imageHeight / 2; y++) {
    yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x];
    i--;
    yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth)
      + (x - 1)];
    i--;
   }
  }
  return yuv;
 }

 public static byte[] YUV420spRotate270(byte[] src, int width, int height) {
  int count = 0;
  int uvHeight = height >> 1;
  int imgSize = width * height;
  byte[] des = new byte[imgSize * 3 >> 1];
  //copy y
  for (int j = width - 1; j >= 0; j--) {
   for (int i = 0; i < height; i++) {
    des[count++] = src[width * i + j];
   }
  }
  //u,v
  for (int j = width - 1; j > 0; j -= 2) {
   for (int i = 0; i < uvHeight; i++) {
    des[count++] = src[imgSize + width * i + j - 1];
    des[count++] = src[imgSize + width * i + j];
   }
  }
  return des;
 }
 private int i = 1;
 private String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/0Face/";
 private Calendar now = new GregorianCalendar();
 private SimpleDateFormat simpleDate = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
 private String fileName = simpleDate.format(now.getTime());

 /**
  * @param data yuv圖像數(shù)據(jù)
  * @param width 
  * @param height
  */
 public void saveImg(byte[] data, int width, int height) {
  File dir = new File(path);
  if (!dir.exists()) dir.mkdirs();
  File f = new File(path + (fileName + "-" + i++) + ".jpg");
  FileOutputStream fOut = null;
  try {
   //yuv轉(zhuǎn)成bitmap
   YuvImage image = new YuvImage(data, ImageFormat.NV21, width, height, null);
   ByteArrayOutputStream stream = new ByteArrayOutputStream();
   image.compressToJpeg(new Rect(0, 0, width, height), 80, stream);
   Bitmap bmp = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
   //bitmap保存至本地
   fOut = new FileOutputStream(f);
   bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
   fOut.flush();
   fOut.close();
   bmp.recycle();
   stream.close();
  } catch (Exception ex) {
   Log.e("Sys", "Error:" + ex.getMessage());
  }
 }

以上這篇Android人臉識別Demo豎屏YUV方向調(diào)整和圖片保存(分享)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

彭泽县| 阜城县| 亚东县| 牡丹江市| 乌恰县| 徐水县| 阜康市| 九寨沟县| 三明市| 塘沽区| 宣汉县| 金门县| 塔河县| 邯郸市| 呈贡县| 巫溪县| 敦化市| 平凉市| 达州市| 稷山县| 汕尾市| 昔阳县| 湘潭市| 密云县| 德阳市| 柳林县| 石城县| 石家庄市| 宜阳县| 布拖县| 延庆县| 莆田市| 巴中市| 尖扎县| 长子县| 安义县| 民勤县| 宁安市| 永丰县| 巩义市| 陆河县|