當前位置: 首頁>>代碼示例>>Java>>正文


Java Frame類代碼示例

本文整理匯總了Java中com.google.android.gms.vision.Frame的典型用法代碼示例。如果您正苦於以下問題:Java Frame類的具體用法?Java Frame怎麽用?Java Frame使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Frame類屬於com.google.android.gms.vision包,在下文中一共展示了Frame類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: detectText

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
public void detectText(View view) {
    Bitmap textBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cat);

    TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();

    if (!textRecognizer.isOperational()) {
        new AlertDialog.Builder(this)
                .setMessage("Text recognizer could not be set up on your device :(")
                .show();
        return;
    }

    Frame frame = new Frame.Builder().setBitmap(textBitmap).build();
    SparseArray<TextBlock> text = textRecognizer.detect(frame);

    for (int i = 0; i < text.size(); ++i) {
        TextBlock item = text.valueAt(i);
        if (item != null && item.getValue() != null) {
            detectedTextView.setText(item.getValue());
        }
    }
}
 
開發者ID:moyheen,項目名稱:text-detector,代碼行數:23,代碼來源:MainActivity.java

示例2: detectTextBlocks

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
List<TextBlock> detectTextBlocks(UQI uqi) {
    List<TextBlock> result = new ArrayList<>();
    Bitmap bitmap = this.getBitmap(uqi);
    if (bitmap == null) return result;
    TextRecognizer textRecognizer = new TextRecognizer.Builder(uqi.getContext()).build();
    if (!textRecognizer.isOperational()) {
        Logging.warn("TextRecognizer is not operational");
        textRecognizer.release();
        return result;
    }
    Frame imageFrame = new Frame.Builder().setBitmap(bitmap).build();
    SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);
    for (int i = 0; i < textBlocks.size(); i++) {
        TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
        result.add(textBlock);
    }
    textRecognizer.release();
    return result;
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:20,代碼來源:ImageData.java

示例3: getDetectorOrientation

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
private int getDetectorOrientation(int sensorOrientation) {
    switch (sensorOrientation) {
        case 0:
            return Frame.ROTATION_0;
        case 90:
            return Frame.ROTATION_90;
        case 180:
            return Frame.ROTATION_180;
        case 270:
            return Frame.ROTATION_270;
        case 360:
            return Frame.ROTATION_0;
        default:
            return Frame.ROTATION_90;
    }
}
 
開發者ID:EzequielAdrianM,項目名稱:Camera2Vision,代碼行數:17,代碼來源:Camera2Source.java

示例4: getFrameRotation

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
private int getFrameRotation() {
    switch (orientation) {
        case 90: {
            return Frame.ROTATION_90;
        }

        case 180: {
            return Frame.ROTATION_180;
        }

        case 270: {
            return Frame.ROTATION_270;
        }

        default: {
            return Frame.ROTATION_0;
        }
    }
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:20,代碼來源:PhotoPaintView.java

示例5: setDetector

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
public void setDetector(){
    FaceDetector detector = new FaceDetector.Builder(this)
            .setTrackingEnabled(true)
            .setLandmarkType(FaceDetector.ALL_LANDMARKS)
            .setMode(FaceDetector.ACCURATE_MODE)
            .build();


    Detector<Face> safeDetector = new SafeFaceDetector(detector);

    if (!safeDetector.isOperational()) {
        Toast.makeText(this, "Detector are having issues", Toast.LENGTH_LONG).show();
    } else {
        Frame frame = new Frame.Builder().setBitmap(mbitmap).build();
        mFaces = safeDetector.detect(frame);
        safeDetector.release();
    }

}
 
開發者ID:doomers,項目名稱:FaceDoSwip,代碼行數:20,代碼來源:MainActivity.java

示例6: detectDocument

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
Document detectDocument(Frame frame){
    Size imageSize = new Size(frame.getMetadata().getWidth(), frame.getMetadata().getHeight());
    Mat src = new Mat();
    Utils.bitmapToMat(frame.getBitmap(), src);
    List<MatOfPoint> contours = CVProcessor.findContours(src);
    src.release();

    if(!contours.isEmpty()){
        CVProcessor.Quadrilateral quad = CVProcessor.getQuadrilateral(contours, imageSize);

        if(quad != null){
            quad.points = CVProcessor.getUpscaledPoints(quad.points, CVProcessor.getScaleRatio(imageSize));
            return new Document(frame, quad);
        }
    }

    return null;
}
 
開發者ID:Credntia,項目名稱:CVScanner,代碼行數:19,代碼來源:DocumentDetector.java

示例7: findLargestFace

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
private Optional<Face> findLargestFace(Bitmap inputImage) {
final FaceDetector detector = createDetector();
      final SparseArray<Face> faces = detector.detect(new Frame.Builder().setBitmap(inputImage).build());

      Face largestFace = null;
float largestSize = 0f;
Timber.d("found " + faces.size() + " faces in photo");

      for (int i = 0; i < faces.size(); ++i) {
          final Face face = faces.valueAt(i);
	final float faceSize = face.getHeight() * face.getWidth();
	if (faceSize > largestSize) {
		largestFace = face;
		largestSize = faceSize;
	}
      }

detector.release();
return Optional.fromNullable(largestFace);
  }
 
開發者ID:FauDroids,項目名稱:BabyFace,代碼行數:21,代碼來源:PhotoProcessor.java

示例8: padFrameRight

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
/**
 * Creates a new frame based on the original frame, with additional width on the right to
 * increase the size to avoid the bug in the underlying face detector.
 */
private Frame padFrameRight( Frame originalFrame, int newWidth ) {
	Frame.Metadata metadata = originalFrame.getMetadata();
	int width = metadata.getWidth();
	int height = metadata.getHeight();

	Log.i( TAG, "Padded image from: " + width + "x" + height + " to " + newWidth + "x" + height );

	ByteBuffer origBuffer = originalFrame.getGrayscaleImageData();
	int origOffset = origBuffer.arrayOffset();
	byte[] origBytes = origBuffer.array();

	// This can be changed to just .allocate in the future, when Frame supports non-direct
	// byte buffers.
	ByteBuffer paddedBuffer = ByteBuffer.allocateDirect( newWidth * height );
	int paddedOffset = paddedBuffer.arrayOffset();
	byte[] paddedBytes = paddedBuffer.array();
	Arrays.fill( paddedBytes, (byte) 0 );

	for( int y = 0; y < height; ++y ) {
		int origStride = origOffset + y * width;
		int paddedStride = paddedOffset + y * newWidth;
		System.arraycopy( origBytes, origStride, paddedBytes, paddedStride, width );
	}

	return new Frame.Builder()
			.setImageData( paddedBuffer, newWidth, height, ImageFormat.NV21 )
			.setId( metadata.getId() )
			.setRotation( metadata.getRotation() )
			.setTimestampMillis( metadata.getTimestampMillis() )
			.build();
}
 
開發者ID:marpies,項目名稱:face-detection-ane,代碼行數:36,代碼來源:SafeFaceDetector.java

示例9: getFaceCount

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
private int getFaceCount(@NonNull Bitmap img) {
    Frame frame = new Frame.Builder()
            .setBitmap(img)
            .build();

    SparseArray<Face> faces = detector.detect(frame);
    log.d("%d faces detected within image %s", faces.size(), img);

    return faces.size();
}
 
開發者ID:BioID-GmbH,項目名稱:BWS-Android,代碼行數:11,代碼來源:FaceDetection.java

示例10: performOCR

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
private String performOCR(Bitmap bitmap) {
    getImageUri(OcrIdActivity.this, bitmap);
    String textResult = "";
    Frame frame = new Frame.Builder().setBitmap(bitmap).build();
    TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();
    SparseArray<TextBlock> textblock = textRecognizer.detect(frame);
    TextBlock tb = null;
    List<Text> texto = new ArrayList<>();
    for (int i = 0; i < textblock.size(); i++) {
        tb = textblock.get(textblock.keyAt(i));
        Log.e("TEXT", tb.toString() + "");
        texto.addAll(tb.getComponents());
    }
    for (Text t : texto) {
        for (Text t2 : t.getComponents()) {
            textResult += t2.getValue() + " ";
        }
        textResult += "\n";
    }

    if (!textResult.equals("")) {
        bitmap.recycle();
        return textResult;
    } else {
        Toast toast = Toast.makeText(this, R.string.ocr_fail, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP, 0, 0);
        toast.show();
        return "";
    }
}
 
開發者ID:BrandonVargas,項目名稱:AndroidOCRFforID,代碼行數:31,代碼來源:OcrIdActivity.java

示例11: scanBitmap

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
public static void scanBitmap(Context context, Bitmap bitmap, int barcodeFormat, BarcodeRetriever barcodeRetriever) {
        BarcodeDetector detector =
                new BarcodeDetector.Builder(context)
                        .setBarcodeFormats(barcodeFormat)
                        .build();
        if (!detector.isOperational()) {
            barcodeRetriever.onRetrievedFailed("Could not set up the detector!");
//            txtView.setText("Could not set up the detector!");
            return;
        }
        Frame frame = new Frame.Builder().setBitmap(bitmap).build();
        barcodeRetriever.onBitmapScanned(detector.detect(frame));
    }
 
開發者ID:KingsMentor,項目名稱:MobileVisionBarcodeScanner,代碼行數:14,代碼來源:BarcodeBitmapScanner.java

示例12: setBitmap

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
public void setBitmap(Bitmap bitmap) {
      mBitmap = bitmap;

      /*開啟人臉檢測*/
      FaceDetector detector = null;
      try {
          detector = new FaceDetector.Builder(getContext())
                  .setTrackingEnabled(false)
                  .setLandmarkType(FaceDetector.ALL_LANDMARKS)
                  .setMode(FaceDetector.ACCURATE_MODE)
                  .build();

      } catch (Exception e) {
          e.printStackTrace();
      }

      /**
       * 你需要檢查FaceDetector是否是可操作的。每當用戶第一次在設備上使用人臉檢測,
       * Play Services服務需要加載一組小型本地庫去處理應用程序的請求。
       * 雖然這些工作一般在應用程序啟動之前就完成了,但是做好失敗處理同樣是必要的。
       如果FaceDetector是可操作的,那麽你需要將位圖數據轉化成Frame對象,
       並通過detect函數傳入用來做人臉數據分析。當完成數據分析後,你需要釋放探測器,
       防止內存泄露。最後調用invalidate()函數來觸發視圖刷新。
       * **/

      //檢測人臉檢測是否可用,如果可用
      if (!detector.isOperational()) {
           //不可以用,重新加載
          Log.i("wangqihui","not initial");
      } else {
          Frame frame =new Frame.Builder().setBitmap(bitmap).build();
          mFaces=detector.detect(frame);
          detector.release();
      }
/*      Frame frame =new Frame.Builder().setBitmap(bitmap).build();
      mFaces=detector.detect(frame);
      detector.release();*/
      invalidate();
  }
 
開發者ID:wangqihui,項目名稱:MyPlay,代碼行數:40,代碼來源:FaceOverlayView.java

示例13: onActivityResult

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
@Override
protected void onActivityResult(int codigoSolicitud, int codigoResultado, Intent datos) {
    if (codigoSolicitud == CODIGO_SOLICITUD_TOMAR_IMAGEN) {
        if (codigoResultado == RESULT_OK) {
            // Guardamos la foto en un objeto Bitmap
            Bitmap foto = (Bitmap) datos.getExtras().get("data");

            // Le pasamos el detector de QR
            Frame frame = new Frame.Builder().setBitmap(foto).build();
            SparseArray<Barcode> barcodes = detectorQR.detect(frame);

            if (barcodes.size() == 0){
                // No detectó QR
                Toast.makeText(MainActivity.this, getString(R.string.no_qr_encontrado), Toast.LENGTH_LONG).show();
            }
            else{
                Barcode codigoQR = barcodes.valueAt(0);
                Toast.makeText(MainActivity.this, codigoQR.rawValue, Toast.LENGTH_LONG).show();

                if(validarMensaje(codigoQR.rawValue)){
                    Intent intent = new Intent(this, NavegacionActivity.class);
                    intent.putExtra(EXTRA_MENSAJE, codigoQR.rawValue);
                    startActivity(intent);
                }
                else{
                    // No detectó la latitud y la longitud en el mensaje
                    Toast.makeText(MainActivity.this, getString(R.string.qr_incorrecto), Toast.LENGTH_LONG).show();
                }
            }


        } else if (codigoResultado == RESULT_CANCELED) {
            // Usuario canceló la imagen
        } else {
            // Captura de imagen fallida
        }
    }
}
 
開發者ID:ranea,項目名稱:AppsAndroid,代碼行數:39,代碼來源:MainActivity.java

示例14: faceDetection

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
/***
 * This method realize the face detection, and this call in another methods
 * for automatice the process
 * @param stroke the bold of line to show around the face
 * @param color the color of rectangle to recognizer the face
 * @param activity the currect activity
 * @param photo your photo
 * @return
 */
private Bitmap faceDetection(int stroke, int color, Activity activity, Bitmap photo){
     this.detector = new FaceDetector.Builder(activity)
            .setMode(FaceDetector.ACCURATE_MODE)
            .setLandmarkType(FaceDetector.ALL_LANDMARKS)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .setTrackingEnabled(false)
            .build();
        try {
            if (false == this.detector.isOperational()) {
                return null;
            }

            //Add the image on a Frame object
            Frame frame = new Frame.Builder()
                    .setBitmap(photo)
                    .build();

            //Detect all faces from Frame object
            SparseArray<Face> faceArray = detector.detect(frame);

            //Do some drawing on faces
            Bitmap outBitmap = drawOnFace(faceArray, photo, stroke, color);

            //Releasing the detector object
            this.detector.release();
            return (outBitmap != null) ? outBitmap : photo;
        }catch(Exception ev){
            return null;
        }
}
 
開發者ID:fabian7593,項目名稱:MagicalCamera,代碼行數:40,代碼來源:FaceRecognition.java

示例15: padFrameBottom

import com.google.android.gms.vision.Frame; //導入依賴的package包/類
/**
 * Creates a new frame based on the original frame, with additional height on the bottom to
 * increase the size to avoid the bug in the underlying face detector.
 */
private Frame padFrameBottom( Frame originalFrame, int newHeight ) {
	Frame.Metadata metadata = originalFrame.getMetadata();
	int width = metadata.getWidth();
	int height = metadata.getHeight();

	Log.i( TAG, "Padded image from: " + width + "x" + height + " to " + width + "x" + newHeight );

	ByteBuffer origBuffer = originalFrame.getGrayscaleImageData();
	int origOffset = origBuffer.arrayOffset();
	byte[] origBytes = origBuffer.array();

	// This can be changed to just .allocate in the future, when Frame supports non-direct
	// byte buffers.
	ByteBuffer paddedBuffer = ByteBuffer.allocateDirect( width * newHeight );
	int paddedOffset = paddedBuffer.arrayOffset();
	byte[] paddedBytes = paddedBuffer.array();
	Arrays.fill( paddedBytes, (byte) 0 );

	// Copy the image content from the original, without bothering to fill in the padded bottom
	// part.
	for( int y = 0; y < height; ++y ) {
		int origStride = origOffset + y * width;
		int paddedStride = paddedOffset + y * width;
		System.arraycopy( origBytes, origStride, paddedBytes, paddedStride, width );
	}

	return new Frame.Builder()
			.setImageData( paddedBuffer, width, newHeight, ImageFormat.NV21 )
			.setId( metadata.getId() )
			.setRotation( metadata.getRotation() )
			.setTimestampMillis( metadata.getTimestampMillis() )
			.build();
}
 
開發者ID:marpies,項目名稱:face-detection-ane,代碼行數:38,代碼來源:SafeFaceDetector.java


注:本文中的com.google.android.gms.vision.Frame類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。