In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how Android realizes face recognition vertical screen YUV orientation adjustment and picture preservation. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. You can first try to rotate 90 °or 270 °clockwise, and then send it to the identification SDK.
two。 When the direction of rotation is still not recognized, you can try saveImg () and save it locally to check whether the picture meets the requirements.
/ * the video is rotated 90 clockwise * this method only uses * * / 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 imageWidth -) {yuv [I] = data [y * imageWidth + x]; iTunes;} 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; Jmuri -) {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 image data * @ 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 + "-" + iTunes +) + ".jpg"); FileOutputStream fOut = null Try {/ / yuv is converted to 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 is saved to local 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 ()) }} this is the end of the article on "how Android implements vertical YUV orientation adjustment and picture preservation for face recognition". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 257
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.