{"id":308801,"date":"2020-08-21T03:00:10","date_gmt":"2020-08-21T03:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308801"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308801","title":{"rendered":"\u041a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e HUAWEI ML Kit \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0438\u043a\u0435\u0440\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u0446\u0430"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516032\/\">\n<h2>\u041e\u0431\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043f\u043e\u0432\u0441\u044e\u0434\u0443 \u0432\u0438\u0434\u0438\u043c \u043c\u0438\u043b\u044b\u0435 \u0438 \u0441\u043c\u0435\u0448\u043d\u044b\u0435 \u0441\u0442\u0438\u043a\u0435\u0440\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u0446\u0430. \u041e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0434\u043b\u044f \u043a\u0430\u043c\u0435\u0440, \u043d\u043e \u0438 \u0432 \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445 \u0438 \u0440\u0430\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c 2D-\u0441\u0442\u0438\u043a\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 HUAWEI ML Kit. \u0421\u043a\u043e\u0440\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 3D-\u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438!<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0438<\/h2>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u044a\u0435\u043c\u043a\u0438 \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u0435\u043b\u0444\u0438-\u043a\u0430\u043c\u0435\u0440\u044b \u0438 \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 (TikTok, Weibo, WeChat \u0438 \u0434\u0440.), \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043d\u0430\u0431\u043e\u0440 \u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u0438\u0445 \u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438 \u044f\u0440\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0438 \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u043c.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>  <\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 Maven Huawei \u0432 \u0444\u0430\u0439\u043b \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 build.gradle<\/h3>\n<p>  \u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <b>build.gradle<\/b> \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <b>Android Studio<\/b>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/dn\/6g\/wf\/dn6gwftpobrorihpcrcs9dtpsqs.png\" alt=\"image\"><br \/>  \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0430\u0434\u0440\u0435\u0441 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f Maven.  <\/p>\n<pre><code class=\"java\">buildscript {     {               maven {url 'http:\/\/developer.huawei.com\/repo\/'}   }     } allprojects {   repositories {              maven { url 'http:\/\/developer.huawei.com\/repo\/'}   } } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 SDK \u0432 \u0444\u0430\u0439\u043b \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f build.gradle<\/h3>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/iu\/ad\/1z\/iuad1z99oeraz3lhwivqsr0y13c.png\" alt=\"image\"><\/p>\n<pre><code class=\"java\">\/\/ Face detection SDK. implementation 'com.huawei.hms:ml-computer-vision-face:2.0.1.300' \/\/ Face detection model. implementation 'com.huawei.hms:ml-computer-vision-face-shape-point-model:2.0.1.300' <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0417\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u0430\u043c\u0435\u0440\u0435, \u0441\u0435\u0442\u0438 \u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 AndroidManifest.xml<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">&lt;!--Camera permission--&gt;  &lt;uses-feature android:name=&quot;android.hardware.camera&quot; \/&gt; &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; \/&gt; &lt;!--Write permission--&gt;  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; \/&gt; &lt;!--Read permission--&gt;  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; \/&gt; <\/code><\/pre>\n<p>  <\/p>\n<h2>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u0434\u0430<\/h2>\n<p>  <\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u0438\u0446\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">MLFaceAnalyzerSetting detectorOptions; detectorOptions = new MLFaceAnalyzerSetting.Factory()       .setFeatureType(MLFaceAnalyzerSetting.TYPE_UNSUPPORT_FEATURES)       .setShapeType(MLFaceAnalyzerSetting.TYPE_SHAPES)       .allowTracing(MLFaceAnalyzerSetting.MODE_TRACING_FAST)       .create(); detector = MLAnalyzerFactory.getInstance().getFaceAnalyzer(detectorOptions); <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0442\u043e\u0447\u043a\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u043b\u0438\u0446\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u0438\u0445 \u0432 FacePointEngine<\/h3>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043c\u0435\u0440\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u043c\u0435\u0440\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0438\u0442\u0435 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u0438\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u043b\u0438\u0446\u0430, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u044d\u0442\u0438 \u0442\u043e\u0447\u043a\u0438 \u0432 <b>FacePointEngine<\/b>. \u0424\u0438\u043b\u044c\u0442\u0440 \u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432 \u0441\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0437\u0436\u0435.  <\/p>\n<pre><code class=\"java\">@Override public void onPreviewFrame(final byte[] imgData, final Camera camera) {   int width = mPreviewWidth;   int height = mPreviewHeight;    long startTime = System.currentTimeMillis();   \/\/ Set the shooting directions of the front and rear cameras to be the same.   if (isFrontCamera()){       mOrientation = 0;   }else {       mOrientation = 2;   }   MLFrame.Property property =           new MLFrame.Property.Creator()                   .setFormatType(ImageFormat.NV21)                   .setWidth(width)                   .setHeight(height)                   .setQuadrant(mOrientation)                   .create();    ByteBuffer data = ByteBuffer.wrap(imgData);   \/\/ Call the face analyzer API.   SparseArray&lt;MLFace&gt; faces = detector.analyseFrame(MLFrame.fromByteBuffer(data,property));   \/\/ Determine whether face information is obtained.   if(faces.size()&gt;0){       MLFace mLFace = faces.get(0);       EGLFace EGLFace = FacePointEngine.getInstance().getOneFace(0);       EGLFace.pitch = mLFace.getRotationAngleX();       EGLFace.yaw = mLFace.getRotationAngleY();       EGLFace.roll = mLFace.getRotationAngleZ() - 90;       if (isFrontCamera())           EGLFace.roll = -EGLFace.roll;       if (EGLFace.vertexPoints == null) {           EGLFace.vertexPoints = new PointF[131];       }       int index = 0;       \/\/ Obtain the coordinates of a user's face contour points and convert them to the floating point numbers in normalized coordinate system of OpenGL.       for (MLFaceShape contour : mLFace.getFaceShapeList()) {           if (contour == null) {               continue;           }           List&lt;MLPosition&gt; points = contour.getPoints();            for (int i = 0; i &lt; points.size(); i++) {               MLPosition point = points.get(i);               float x = ( point.getY() \/ height) * 2 - 1;               float y = ( point.getX() \/ width ) * 2 - 1;               if (isFrontCamera())                   x = -x;               PointF Point = new PointF(x,y);               EGLFace.vertexPoints[index] = Point;               index++;           }       }       \/\/ Insert a face object.       FacePointEngine.getInstance().putOneFace(0, EGLFace);       \/\/ Set the number of faces.       FacePointEngine.getInstance().setFaceSize(faces!= null ? faces.size() : 0);   }else{       FacePointEngine.getInstance().clearAll();   }   long endTime = System.currentTimeMillis();   Log.d(&quot;TAG&quot;,&quot;Face detect time: &quot; + String.valueOf(endTime - startTime)); } <\/code><\/pre>\n<p>  \u041d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u0442\u043e\u0447\u043a\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u043b\u0438\u0446\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e API ML Kit.<br \/>  <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/f7\/v5\/ms\/f7v5ms7bbwb0x1ihancvh6rio48.jpeg\" height=\"1041\" width=\"480\" alt=\"image\">  <\/p>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0438\u043a\u0435\u0440\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">public class FaceStickerJson {    public int[] centerIndexList;   \/\/ Center coordinate index list. If the list contains multiple indexes, these indexes are used to calculate the central point.   public float offsetX;           \/\/ X-axis offset relative to the center coordinate of the sticker, in pixels.   public float offsetY;           \/\/ Y-axis offset relative to the center coordinate of the sticker, in pixels.   public float baseScale;         \/\/ Base scale factor of the sticker.   public int startIndex;         \/\/ Face start index, which is used for computing the face width.   public int endIndex;           \/\/ Face end index, which is used for computing the face width.   public int width;               \/\/ Sticker width.   public int height;             \/\/ Sticker height.   public int frames;             \/\/ Number of sticker frames.   public int action;             \/\/ Action. 0 indicates default display. This is used for processing the sticker action.   public String stickerName;     \/\/ Sticker name, which is used for marking the folder or PNG file path.   public int duration;           \/\/ Sticker frame displays interval.   public boolean stickerLooping; \/\/ Indicates whether to perform rendering in loops for the sticker.   public int maxCount;           \/\/ Maximum number of rendering times. ... } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0421\u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0441\u0442\u0438\u043a\u0435\u0440 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u0430<\/h3>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <b>JSON<\/b> \u0434\u043b\u044f \u0441\u0442\u0438\u043a\u0435\u0440\u0430 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u043c\u0435\u0436\u0434\u0443 \u0431\u0440\u043e\u0432\u044f\u043c\u0438 (84) \u0438 \u043a\u043e\u043d\u0447\u0438\u043a\u043e\u043c \u043d\u043e\u0441\u0430 (85) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043b\u0438\u0446\u0430. \u0412\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0443\u0448\u0438 \u0438 \u043d\u043e\u0441 \u043a\u043e\u0442\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0444\u0430\u0439\u043b <b>JSON<\/b> \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043f\u043a\u0443 <b>assets<\/b>.  <\/p>\n<pre><code class=\"java\">{   &quot;stickerList&quot;: [{       &quot;type&quot;: &quot;sticker&quot;,       &quot;centerIndexList&quot;: [84],       &quot;offsetX&quot;: 0.0,       &quot;offsetY&quot;: 0.0,       &quot;baseScale&quot;: 1.3024,       &quot;startIndex&quot;: 11,       &quot;endIndex&quot;: 28,       &quot;width&quot;: 495,       &quot;height&quot;: 120,       &quot;frames&quot;: 2,       &quot;action&quot;: 0,       &quot;stickerName&quot;: &quot;nose&quot;,       &quot;duration&quot;: 100,       &quot;stickerLooping&quot;: 1,       &quot;maxcount&quot;: 5   }, {       &quot;type&quot;: &quot;sticker&quot;,       &quot;centerIndexList&quot;: [83],       &quot;offsetX&quot;: 0.0,       &quot;offsetY&quot;: -1.1834,       &quot;baseScale&quot;: 1.3453,       &quot;startIndex&quot;: 11,       &quot;endIndex&quot;: 28,       &quot;width&quot;: 454,       &quot;height&quot;: 150,       &quot;frames&quot;: 2,       &quot;action&quot;: 0,       &quot;stickerName&quot;: &quot;ear&quot;,       &quot;duration&quot;: 100,       &quot;stickerLooping&quot;: 1,       &quot;maxcount&quot;: 5   }] } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0420\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0441\u0442\u0438\u043a\u0435\u0440\u0430 \u0432 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443<\/h3>\n<p>  \u041c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u0441\u0442\u0438\u043a\u0435\u0440\u0430 \u0432 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0430\u0441\u0441\u0430 <b>GLSurfaceView<\/b> \u2014 \u043e\u043d \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c <b>TextureView<\/b>. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432 \u0432 <b>onSurfaceChanged<\/b>, \u043f\u0435\u0440\u0435\u0434\u0430\u0439\u0442\u0435 \u043f\u0443\u0442\u044c \u0441\u0442\u0438\u043a\u0435\u0440\u0430 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u0430\u043c\u0435\u0440\u0443.  <\/p>\n<pre><code class=\"java\">@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) {    GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);   mTextures = new int[1];   mTextures[0] = OpenGLUtils.createOESTexture();   mSurfaceTexture = new SurfaceTexture(mTextures[0]);   mSurfaceTexture.setOnFrameAvailableListener(this);    \/\/ Pass the samplerExternalOES into the texture.   cameraFilter = new CameraFilter(this.context);    \/\/ Set the face sticker path in the assets directory.   String folderPath =&quot;cat&quot;;   stickerFilter = new FaceStickerFilter(this.context,folderPath);    \/\/ Create a screen filter object.   screenFilter = new BaseFilter(this.context);    facePointsFilter = new FacePointsFilter(this.context);   mEGLCamera.openCamera(); } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0438\u043b\u044c\u0442\u0440 \u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432 \u0432 onSurfaceChanged<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">@Override public void onSurfaceChanged(GL10 gl, int width, int height) {   Log.d(TAG, &quot;onSurfaceChanged. width: &quot; + width + &quot;, height: &quot; + height);   int previewWidth = mEGLCamera.getPreviewWidth();   int previewHeight = mEGLCamera.getPreviewHeight();   if (width &gt; height) {       setAspectRatio(previewWidth, previewHeight);   } else {       setAspectRatio(previewHeight, previewWidth);   }   \/\/ Set the image size, create a FrameBuffer, and set the display size.   cameraFilter.onInputSizeChanged(previewWidth, previewHeight);   cameraFilter.initFrameBuffer(previewWidth, previewHeight);   cameraFilter.onDisplaySizeChanged(width, height);    stickerFilter.onInputSizeChanged(previewHeight, previewWidth);   stickerFilter.initFrameBuffer(previewHeight, previewWidth);   stickerFilter.onDisplaySizeChanged(width, height);    screenFilter.onInputSizeChanged(previewWidth, previewHeight);   screenFilter.initFrameBuffer(previewWidth, previewHeight);   screenFilter.onDisplaySizeChanged(width, height);    facePointsFilter.onInputSizeChanged(previewHeight, previewWidth);   facePointsFilter.onDisplaySizeChanged(width, height);   mEGLCamera.startPreview(mSurfaceTexture); } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u041d\u0430\u0440\u0438\u0441\u0443\u0439\u0442\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0441\u0442\u0438\u043a\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e onDrawFrame<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">@Override public void onDrawFrame(GL10 gl) {   int textureId;   \/\/ Clear the screen and depth buffer.   GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT | GLES30.GL_DEPTH_BUFFER_BIT);   \/\/ Update a texture image.   mSurfaceTexture.updateTexImage();   \/\/ Obtain the SurfaceTexture transform matrix.    mSurfaceTexture.getTransformMatrix(mMatrix);   \/\/ Set the camera display transform matrix.   cameraFilter.setTextureTransformMatrix(mMatrix);    \/\/ Draw the camera texture.   textureId = cameraFilter.drawFrameBuffer(mTextures[0],mVertexBuffer,mTextureBuffer);   \/\/ Draw the sticker texture.   textureId = stickerFilter.drawFrameBuffer(textureId,mVertexBuffer,mTextureBuffer);   \/\/ Draw on the screen.   screenFilter.drawFrame(textureId , mDisplayVertexBuffer, mDisplayTextureBuffer);   if(drawFacePoints){       facePointsFilter.drawFrame(textureId, mDisplayVertexBuffer, mDisplayTextureBuffer);   } } <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c! \u0412\u0430\u0448 \u0441\u0442\u0438\u043a\u0435\u0440 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u0446\u0430 \u0433\u043e\u0442\u043e\u0432.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0435\u0433\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438!<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8i\/ml\/gd\/8imlgdjbjiowslncxttxvwjcv3e.gif\" alt=\"image\"><br \/>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 \u043d\u0430\u0448 <a href=\"https:\/\/developer.huawei.com\/consumer\/en\/hms\/huawei-mlkit\" rel=\"nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0430\u0439\u0442<\/a>.<br \/>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/HMS-Core\/hms-ml-demo\" rel=\"nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/a>.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/516032\/\"> https:\/\/habr.com\/ru\/post\/516032\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516032\/\">\n<h2>\u041e\u0431\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043f\u043e\u0432\u0441\u044e\u0434\u0443 \u0432\u0438\u0434\u0438\u043c \u043c\u0438\u043b\u044b\u0435 \u0438 \u0441\u043c\u0435\u0448\u043d\u044b\u0435 \u0441\u0442\u0438\u043a\u0435\u0440\u044b \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u0446\u0430. \u041e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u0434\u043b\u044f \u043a\u0430\u043c\u0435\u0440, \u043d\u043e \u0438 \u0432 \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u044f\u0445 \u0438 \u0440\u0430\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c 2D-\u0441\u0442\u0438\u043a\u0435\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 HUAWEI ML Kit. \u0421\u043a\u043e\u0440\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 3D-\u0441\u0442\u0438\u043a\u0435\u0440\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438!  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308801","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308801"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308801\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}