cmauri / eva_facial_mouse

Camera based mouse emulator for Android
122 stars 47 forks source link

Image in the camera upside down (inverted) #27

Open ghost opened 6 years ago

ghost commented 6 years ago

Good afternoon. The program is installed on TV box (H96 max, Rockchip RK 3399, Android 7.1.2), connected web camera via USB (tried on different models of cameras - Logitech, Genius, ...). In Skype and other programs the picture is normal - not inverted (at least on a vertical - horizontal inverted in some). The program EVA mouse image in the camera is inverted (upside down) and the program can't recognize the face. If physically flip the camera-the face is recognized and the program works fine vertically, but turned horizontally (when you turn the head to the right the cursor goes to the left). Tell me how to correct: change the settings in your operating system or configuration files of the program EVA a mouse... or can you add a configuration possibility of the inversion of the mouse pointer can travel separately along different axes?! Goodbye Vlad

ghost commented 6 years ago

Okay, I will answer myself. The author in the code separately handles some devices with one camera that flip the camera... but in my case with one webcam just do not need to turn. Just to comment for himself a coup and put together app. On good it is necessary switch in settings to display... but skills and time now there is no. Maybe with the next version the author will finish.

CameraListener(@NonNull Context c, @NonNull FrameProcessor fp, int desiredCaptureWidth, int desiredCaptureHeight) throws CameraException { mFrameProcessor= fp;

    /*
     * For some devices, notably the Lenovo YT3-X50L, have only one camera that can
     * be rotated to frame the user's face. In this case the camera is reported as
     * facing back. Therefore, we try to detect all cameras of the device and pick
     * the facing front one, if any. Otherwise, we pick the first facing back camera
     * and report that the image needs a vertical flip before fixing the orientation.
     *
     * The orientation of the camera is the angle that the camera image needs
     * to be rotated clockwise so it shows correctly on the display in its natural orientation.
     * It should be 0, 90, 180, or 270.
     *
     * For example, suppose a device has a naturally tall screen. The back-facing camera sensor
     * is mounted in landscape. You are looking at the screen. If the top side of the camera
     * sensor is aligned with the right edge of the screen in natural orientation, the value
     * should be 90. If the top side of a front-facing camera sensor is aligned with the right
     * of the screen, the value should be 270.
     */
    final int numCameras= Camera.getNumberOfCameras();
    if (numCameras< 1) {
        Log.e(EVIACAM.TAG, "No cameras available");
        throw new CameraException(CameraException.NO_CAMERAS_AVAILABLE,
                c.getResources().getString(R.string.service_camera_no_available));
    }

    // Pick the best available camera
    int bestCamera= 0;  // pick the first one if no facing front camera available
    Camera.CameraInfo cameraInfo= new CameraInfo();
    for (int i= 0; i< numCameras; i++) {
        Camera.getCameraInfo (i, cameraInfo);
        if (cameraInfo.facing== CameraInfo.CAMERA_FACING_FRONT) {
            bestCamera= i;
            break;
        }
    }

    // Get camera features
    Camera.getCameraInfo (bestCamera, cameraInfo);
    FlipDirection flip= FlipDirection.NONE;                // no flip needed by default
    int cameraId = MyCameraBridgeViewBase.CAMERA_ID_FRONT; // front camera by default

    if (cameraInfo.facing== CameraInfo.CAMERA_FACING_BACK) {
        // When the best available camera faces back
        /////////////////////////////////////
        //flip= FlipDirection.VERTICAL;//
        ////////////////////////////////////
        cameraId= MyCameraBridgeViewBase.CAMERA_ID_BACK;

        Log.i(EVIACAM.TAG, "Back camera detected. Orientation: " + cameraInfo.orientation);
    }
    else {
        Log.i(EVIACAM.TAG, "Front camera detected. Orientation: " + cameraInfo.orientation);
    }

    mCameraOrientation= cameraInfo.orientation;
    mCameraFlip= flip;

    /*
     * Create a capture view which carries the responsibilities of
     * capturing and displaying frames.
     */
cmauri commented 6 years ago

In our tests we had similar issues with an Android set-top-box. With the aim of non breaking backwards compatibility with some devices (e.g. the aforementioned Lenovo) and assuming that using a set-top-box for interacting with EVA is, perhaps, not as common as using a smart-phone or a tablet, we decided to keep the same behaviour in code and add a setting to manually flip the image. Such an option will be available since EVA versions >=2.X (we expect to publish it this week).