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


Java Detector.isOperational方法代碼示例

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


在下文中一共展示了Detector.isOperational方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDetector

import com.google.android.gms.vision.Detector; //導入方法依賴的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

示例2: createCameraSource

import com.google.android.gms.vision.Detector; //導入方法依賴的package包/類
@SuppressLint("InlinedApi")
private void createCameraSource(Detector<Barcode> barcodeDetector, boolean autoFocus, boolean useFlash) {


    // A barcode detector is created to track barcodes.  An associated multi-processor instance
    // is set to receive the barcode detection results, track the barcodes, and maintain
    // graphics for each barcode on screen.  The factory is used by the multi-processor to
    // create a separate tracker instance for each barcode.


    BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay) {
        @Override
        void onCodeDetected(Barcode barcode) {
            if (!isTouchAsCallback() && !supportMultipleScan()) {
                if (!isPause())
                    barcodeRetriever.onRetrieved(barcode);
            }
        }
    };

    barcodeDetector.setProcessor(
            new MultiProcessor.Builder<>(barcodeFactory).build());


    if (!barcodeDetector.isOperational()) {
        // Note: The first time that an app using the barcode or face API is installed on a
        // device, GMS will download a native libraries to the device in order to do detection.
        // Usually this completes before the app is run for the first time.  But if that
        // download has not yet completed, then the above call will not detect any barcodes
        // and/or faces.
        //
        // isOperational() can be used to check if the required native libraries are currently
        // available.  The detectors will automatically become operational once the library
        // downloads complete on device.
        Log.w(TAG, "Detector dependencies are not yet available.");

        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null;

        if (hasLowStorage) {
            Toast.makeText(getContext(), R.string.low_storage_error, Toast.LENGTH_LONG).show();
            Log.w(TAG, getString(R.string.low_storage_error));
        }
    }

    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager()
            .getDefaultDisplay()
            .getMetrics(displayMetrics);
    int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;

    // Creates and starts the camera.  Note that this uses a higher resolution in comparison
    // to other detection examples to enable the barcode detector to detect small barcodes
    // at long distances.
    CameraSource.Builder builder = new CameraSource.Builder(getContext(), barcodeDetector)
            .setFacing(getCameraFacing())
            .setRequestedPreviewSize(height, width)
            .setRequestedFps(15.0f);

    // make sure that auto focus is an available option
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder = builder.setFocusMode(
                autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
    }

    mCameraSource = builder
            .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
            .build();


}
 
開發者ID:KingsMentor,項目名稱:MobileVisionBarcodeScanner,代碼行數:75,代碼來源:BarcodeCapture.java

示例3: onCreate

import com.google.android.gms.vision.Detector; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_viewer);

    InputStream stream = getResources().openRawResource(R.raw.face);
    Bitmap bitmap = BitmapFactory.decodeStream(stream);

    // A new face detector is created for detecting the face and its landmarks.
    //
    // Setting "tracking enabled" to false is recommended for detection with unrelated
    // individual images (as opposed to video or a series of consecutively captured still
    // images).  For detection on unrelated individual images, this will give a more accurate
    // result.  For detection on consecutive images (e.g., live video), tracking gives a more
    // accurate (and faster) result.
    //
    // By default, landmark detection is not enabled since it increases detection time.  We
    // enable it here in order to visualize detected landmarks.
    FaceDetector detector = new FaceDetector.Builder(getApplicationContext())
            .setTrackingEnabled(false)
            .setLandmarkType(FaceDetector.ALL_LANDMARKS)
            .build();

    // This is a temporary workaround for a bug in the face detector with respect to operating
    // on very small images.  This will be fixed in a future release.  But in the near term, use
    // of the SafeFaceDetector class will patch the issue.
    Detector<Face> safeDetector = new SafeFaceDetector(detector);

    // Create a frame from the bitmap and run face detection on the frame.
    Frame frame = new Frame.Builder().setBitmap(bitmap).build();
    SparseArray<Face> faces = safeDetector.detect(frame);

    if (!safeDetector.isOperational()) {
        // Note: The first time that an app using face API is installed on a device, GMS will
        // download a native library to the device in order to do detection.  Usually this
        // completes before the app is run for the first time.  But if that download has not yet
        // completed, then the above call will not detect any faces.
        //
        // isOperational() can be used to check if the required native library is currently
        // available.  The detector will automatically become operational once the library
        // download completes on device.
        Log.w(TAG, "Face detector dependencies are not yet available.");

        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;

        if (hasLowStorage) {
            Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
            Log.w(TAG, getString(R.string.low_storage_error));
        }
    }

    FaceView overlay = (FaceView) findViewById(R.id.faceView);
    overlay.setContent(bitmap, faces);

    // Although detector may be used multiple times for different images, it should be released
    // when it is no longer needed in order to free native resources.
    safeDetector.release();
}
 
開發者ID:ashishsurana,項目名稱:qrcode-reader,代碼行數:62,代碼來源:PhotoViewerActivity.java


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