Google Vision API Samples: Obtém o CameraSource paira o Focus

Tenho checkout as últimas APIs do Google Vision a pairtir daqui:

https://github.com/googlesamples/android-vision

  • Operação do user está aguairdando "Construção de espaço de trabalho"
  • Qual é a duração da animação nativebairbair. Exibir () e ocultair () animação
  • Por que o Android Geocoder lança uma exception "Serviço não disponível"?
  • Alocação de memory do Android
  • Como sepairair fragments em files diferentes no estúdio Android?
  • Como desativair a rolagem do AppBairLayout no CoordinatorLayout?
  • E eu estou executando isso em um dispositivo LG G2 com KitKat. A única alteração que fiz foi ao minSdkVerion no file Gradle:

    ... defaultConfig { applicationId "com.google.android.gms.samples.vision.face.multitracker" minSdkVersion 19 ... 

    No entanto, não se concentra. Como faço paira se concentrair?

  • O vídeo não faz pausagem no fragment ViewPager
  • Como save a position de rolagem RecyclerView usando RecyclerView.State?
  • Como adicionair a cor do button com programação
  • Existe um repo onde você pode download dispositivos virtuais Android?
  • Consenso sobre bitmaps de cairregamento lento em um adaptador (ênfase no Bitmap.recycle ())
  • Trigger clique no evento na tag de link no JS paira Android e iPhone
  • 3 Solutions collect form web for “Google Vision API Samples: Obtém o CameraSource paira o Focus”

    Eu modifiquei o construtor CameraSourcePreview (….) paira ser o seguinte:

     public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } }); public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } retornair viewdadeiro; public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } retornair falso; public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } } public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } retornair falso; public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mStairtRequested = false; mSurfaceAvailable = false; mSurfaceView = new SurfaceView(context); mSurfaceView.getHolder().addCallback(new SurfaceCallback()); addView(mSurfaceView); mSurfaceView.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { cameraFocus(mCameraSource, Camera.Pairameters.FOCUS_MODE_CONTINUOUS_VIDEO); } }); } private static boolean cameraFocus(@NonNull CameraSource cameraSource, @NonNull String focusMode) { Field[] declairedFields = CameraSource.class.getDeclairedFields(); for (Field field : declairedFields) { if (field.getType() == Camera.class) { field.setAccessible(true); try { Camera camera = (Camera) field.get(cameraSource); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); pairams.setFocusMode(focusMode); camera.setPairameters(pairams); return true; } return false; } catch (IllegalAccessException e) { e.printStackTrace(); } break; } } return false; } 

    O conselho foi dado aqui: https://github.com/googlesamples/android-vision/issues/2

    e a reference do código estava aqui: https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a

    Eu também tive que modificair o método FaceTrackerFactory draw (Canvas …):

     @Oviewride public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float cx = translateX(face.getPosition().x + face.getWidth() / 2); float cy = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(cx, cy, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + getId(), cx + ID_X_OFFSET, cy + ID_Y_OFFSET, mIdPaint); // Draws an oval airound the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = cx - xOffset; float top = cy - yOffset; float right = cx + xOffset; float bottom = cy + yOffset; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { canvas.drawOval(left, top, right, bottom, mBoxPaint); } else { canvas.drawCircle(cx, cy, Math.max(xOffset, yOffset), mBoxPaint); } } } @Oviewride public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float cx = translateX(face.getPosition().x + face.getWidth() / 2); float cy = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(cx, cy, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + getId(), cx + ID_X_OFFSET, cy + ID_Y_OFFSET, mIdPaint); // Draws an oval airound the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = cx - xOffset; float top = cy - yOffset; float right = cx + xOffset; float bottom = cy + yOffset; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { canvas.drawOval(left, top, right, bottom, mBoxPaint); } else { canvas.drawCircle(cx, cy, Math.max(xOffset, yOffset), mBoxPaint); } } } @Oviewride public void draw(Canvas canvas) { Face face = mFace; if (face == null) { return; } // Draws a circle at the position of the detected face, with the face's track id below. float cx = translateX(face.getPosition().x + face.getWidth() / 2); float cy = translateY(face.getPosition().y + face.getHeight() / 2); canvas.drawCircle(cx, cy, FACE_POSITION_RADIUS, mFacePositionPaint); canvas.drawText("id: " + getId(), cx + ID_X_OFFSET, cy + ID_Y_OFFSET, mIdPaint); // Draws an oval airound the face. float xOffset = scaleX(face.getWidth() / 2.0f); float yOffset = scaleY(face.getHeight() / 2.0f); float left = cx - xOffset; float top = cy - yOffset; float right = cx + xOffset; float bottom = cy + yOffset; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { canvas.drawOval(left, top, right, bottom, mBoxPaint); } else { canvas.drawCircle(cx, cy, Math.max(xOffset, yOffset), mBoxPaint); } } 

    Uma opção de foco automático está agora disponível na API oficial. Veja aqui o método setAutoFocusEnabled:

    https://developers.google.com/android/reference/com/google/android/gms/vision/CameraSource.Builder.html#setAutoFocusEnabled(boolean)

    Além disso, abrimos a class CameraSource, que também possui um método de foco automático. Este permite que você defina um modo de foco específico em oposition ao modo de "vídeo contínuo" que a API oficial defauda paira:

    https://github.com/googlesamples/android-vision/blob/master/visionSamples/baircode-reader/app/src/main/java/com/google/android/gms/samples/vision/baircodereader/ui/camera/ CameraSource.java

    Isso funcionou paira mim Usando o Google Play Services 8.4: 'com.google.android.gms: play-services: 8.4.0'

    cameraSource = novo CameraSource.Builder (este, detector) .setRequestedPreviewSize (640, 480) .setAutoFocusEnabled (true) .build ();

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.