本文整理汇总了Java中com.google.android.gms.vision.face.FaceDetector.isOperational方法的典型用法代码示例。如果您正苦于以下问题:Java FaceDetector.isOperational方法的具体用法?Java FaceDetector.isOperational怎么用?Java FaceDetector.isOperational使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.vision.face.FaceDetector
的用法示例。
在下文中一共展示了FaceDetector.isOperational方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
private void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = createFaceDetector(context);
detector.setProcessor(new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());
if (!detector.isOperational()) {
Timber.d("Face detector dependencies are not yet available.");
}
cameraSource = new CameraSource.Builder(context, detector) //
// Camera will decide actual size, and we'll crop accordingly in layout.
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(MAX_FRAME_RATE)
.setAutoFocusEnabled(true)
.build();
}
示例2: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
/**
* 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.
*/
private void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setMode(FaceDetector.ACCURATE_MODE)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例3: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
/**
* 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.
*/
private void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedFps(30.0f)
.build();
}
示例4: setBitmap
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的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();
}
示例5: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
public void createCameraSource(GraphicOverlay overlay) {
mGraphicOverlay = overlay;
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
if (!detector.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.");
}
mCameraSourceBack = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(1980, 1080)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedFps(30.0f)
.build();
mCameraSourceFront = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(1980, 1080)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例6: getFaceBitmap
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
private Bitmap getFaceBitmap(Bitmap bmp,Context context){
FaceDetector faceDetector = new
FaceDetector.Builder(context).setTrackingEnabled(false)
.build();
if(!faceDetector.isOperational()){
System.out.println("Face detector not working");
return null;
}
Bitmap faceBitmap = null;
Frame frame = new Frame.Builder().setBitmap(bmp).build();
SparseArray<Face> faces = faceDetector.detect(frame);
for(int i=0; i<faces.size(); i++) {
Face thisFace = faces.valueAt(i);
int faceWidth=(int)thisFace.getWidth();
int faceHeight=(int)thisFace.getHeight();
int x1 = (int)thisFace.getPosition().x;
int y1 = (int)thisFace.getPosition().y;
faceBitmap=Bitmap.createBitmap(bmp,
x1> (faceWidth/2) ? (x1-faceWidth/2):0,
y1> (faceHeight/2) ? (y1-faceHeight/2):0,
1.5*faceWidth < bmp.getWidth() ? (int)(1.5*faceWidth) : bmp.getWidth(),
1.5*faceHeight < bmp.getWidth() ? (int)(1.5*faceHeight) : bmp.getHeight());
}
if(faceBitmap!=null) return faceBitmap;
return bmp;
}
示例7: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
/**
* 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.
*/
private void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.setProminentFaceOnly(true)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例8: onCreateView
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_face_tracking, container, false);
mPreview = (CameraSourcePreview) view.findViewById(R.id.preview);
mGraphicOverlay = (GraphicOverlay) view.findViewById(R.id.faceOverlay);
Context context = getActivity().getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context).build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
// .setRequestedPreviewSize(640, 480)
// .setFacing(CameraSource.CAMERA_FACING_BACK)
// .setRequestedFps(30.0f)
.build();
return view;
}
示例9: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
public void createCameraSource() {
//Setup the FaceDetector
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
.setProminentFaceOnly(true) //track only one face... makes it faster.
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) //allows for eye and smile detection!
.build();
detector.setProcessor(
new LargestFaceFocusingProcessor(detector, new FaceTracker()));
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例10: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
public void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
//.setProminentFaceOnly(true) //track only one face... makes it faster.
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) //allows for eye and smile detection!
.build();
detector.setProcessor(
//new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());
new LargestFaceFocusingProcessor(detector, new GraphicFaceTracker(mGraphicOverlay)));
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例11: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
public void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
//.setProminentFaceOnly(true) //track only one face... makes it faster.
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) //allows for eye and smile detection!
.build();
//set it up to easily handle more then one face at a time, via the multi processor class.
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory()).build());
//new LargestFaceFocusingProcessor(detector,new GraphicFaceTracker(mGraphicOverlay)));
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
//.setFacing(CameraSource.CAMERA_FACING_BACK)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例12: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
/**
* 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.
*/
private void createCameraSource() {
Context context = getApplicationContext();
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
detector.setProcessor(
new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
.build());
if (!detector.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.");
}
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
}
示例13: createCameraSource
import com.google.android.gms.vision.face.FaceDetector; //导入方法依赖的package包/类
/**
* 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.
*/
private void createCameraSource() {
Context context = mContextWeakReference.get();
FaceDetector detector = new FaceDetector.Builder(context)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
detector.setProcessor(new Detector.Processor<Face>() {
@Override
public void release() {
}
@Override
public void receiveDetections(final Detector.Detections<Face> detections) {
final SparseArray<Face> detectedItems = detections.getDetectedItems();
if (detectedItems.size() != 0) {
final int key = detectedItems.keyAt(0);
final Face face = detectedItems.get(key);
final float isSmilingProbability = face.getIsSmilingProbability();
String feedback = getFeedbackForSmileProbability(isSmilingProbability);
mCallBacks.onShouldGivePositiveAffirmation(feedback);
}
}
});
if (!detector.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.");
}
try {
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_FRONT)
.setRequestedFps(30.0f)
.build();
mCameraSource.start();
} catch (IOException | RuntimeException e) {
Log.e(TAG, "Something went horribly wrong, with your face.", e);
}
}