Android : Stop Face Tracking from non-activity(Tracker) class

392
April 26, 2017, at 6:25 PM

I have implemented Eye Tracking application and its working fine. Now, after some logical point I want to stop the Face Tracking and start other activity.

please let me know how to pause a camera/Face Tracking from non-activity class.

//Activity class
public class MainActivity extends AppCompatActivity {
  //other coding stuff
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mSwitch = (SwitchCompat) findViewById(R.id.switchButton);
        mLight = findViewById(R.id.light);
        mEmoticon = (TextView) findViewById(R.id.emoticon);
        // check that the play services are installed
        PlayServicesUtil.isPlayServicesAvailable(this, 69);
        // permission granted...?
        if (isCameraPermissionGranted()) {
            // ...create the camera resource
            createCameraResources();
        }
    }
private void createCameraResources() {
        Context context = getApplicationContext();
        // create and setup the face detector
        mFaceDetector = new FaceDetector.Builder(context)
                .setProminentFaceOnly(true) // optimize for single, relatively large face
                .setTrackingEnabled(true) // enable face tracking
                .setClassificationType(/* eyes open and smile */ FaceDetector.ALL_CLASSIFICATIONS)
                .setMode(FaceDetector.FAST_MODE) // for one face this is OK
                .build();
        // now that we've got a detector, create a processor pipeline to receive the detection
        // results
        mFaceDetector.setProcessor(new LargestFaceFocusingProcessor(mFaceDetector, new FaceTracker()));
        // operational...?
        if (!mFaceDetector.isOperational()) {
            Log.w(TAG, "createCameraResources: detector NOT operational");
        } else {
            Log.d(TAG, "createCameraResources: detector operational");
        }
        // Create camera source that will capture video frames
        // Use the front camera
        mCameraSource = new CameraSource.Builder(this, mFaceDetector)
                .setRequestedPreviewSize(640, 480)
                .setFacing(CameraSource.CAMERA_FACING_FRONT)
                .setRequestedFps(30f)
                .build();
    }
}

//Non-activity class
public class FaceTracker extends Tracker<Face> {
   //other coding stuff
    @Override
    public void onUpdate(Detector.Detections<Face> detections, Face face) {
        if (leftClosed && face.getIsLeftEyeOpenProbability() > PROB_THRESHOLD) {
            leftClosed = false;
        } else if (!leftClosed &&  face.getIsLeftEyeOpenProbability() < PROB_THRESHOLD){
            leftClosed = true;
        }
        if (rightClosed && face.getIsRightEyeOpenProbability() > PROB_THRESHOLD) {
            rightClosed = false;
        } else if (!rightClosed && face.getIsRightEyeOpenProbability() < PROB_THRESHOLD) {
            rightClosed = true;
        }
    }
}
READ ALSO
How can one crop an animated GIF on Android?

How can one crop an animated GIF on Android?

This is my first post on Stack Overflow, so I apologize if I am breaking the unwritten rules!! After much searching online I haven't been able to find a tool for cropping a GIF fileMore specifically, I would like to crop a GIF with multiple frames

487
Android app freezes after some seconds of successful audio recording and processing

Android app freezes after some seconds of successful audio recording and processing

my app is freezing after about 10 seconds of expected behavior and I struggle to pinpoint the cause

231
Unable to launch a movie in Netflix app by passing content id from ConnectSDK (DIAL protocol)

Unable to launch a movie in Netflix app by passing content id from ConnectSDK (DIAL protocol)

Using ConnectSDK (DIAL protocol), i am able to discover the samsung smart tv (Tizen OS) and launch Netflix appBut it fails to launch a movie by passing movie id

237
Handle Back of Controllers on Android

Handle Back of Controllers on Android

I'm developing and Android app right now with MVC Architecture and with a router which is responsible for the switch between my ControllersI created a custom ToolBar with a back Button and I have some troubles that I will explains

266