Esempio n. 1
0
    public bool changeAndroidCameraAPI(out int apiLevel, out int hwFeature, out bool canChangeNewAPI)
    {
        //// get current status
        //cameraDevice_.GetAndroidCameraAPIFeature(out apiLevel, out hwFeature);
        //int oldApiLevel = apiLevel;
        //int oldHwFeature = hwFeature;

        bool success = false;

        canChangeNewAPI = cameraDevice_.IsAndroidCamera2Available(smart_, isFront_, out apiLevel, out hwFeature);
        if (canChangeNewAPI)
        {
            // change API
            DoDisable();
            forceOldAndroidCameraAPI_ = !forceOldAndroidCameraAPI_;
            DoEnable();
            success = true;
        }

        // get latest status
        cameraDevice_.GetAndroidCameraAPIFeature(out apiLevel, out hwFeature);
        return(success);
    }
Esempio n. 2
0
    protected override void DoEnable()
    {
        if (enabled_)
        {
            return;
        }

        if (smartInitFailed_)
        {
            return;
        }
        if (self_ == IntPtr.Zero)
        {
            return;
        }

        // Create CameraDevice
        cameraDevice_ = new smartar.CameraDevice(smart_, cameraDeviceSettings.cameraId, forceOldAndroidCameraAPI_);

        cameraDevice_.GetRotation(out cameraRotation_);
        int frontCameraId;

        smartar.CameraDevice.GetDefaultCameraId(smart_, smartar.Facing.FACING_FRONT, out frontCameraId, forceOldAndroidCameraAPI_);
        isFront_ = frontCameraId != smartar.CameraDevice.INVALID_CAMERA_ID && cameraDeviceSettings.cameraId == frontCameraId;

#if UNITY_ANDROID && !UNITY_EDITOR
        // get camera hw support
        int apiLevel = 0;
        int feature  = -1;
        androidCameraFeature.androidCanUseNewAPI_ = cameraDevice_.IsAndroidCamera2Available(smart_, isFront_, out apiLevel, out feature);
        cameraDevice_.GetAndroidCameraAPIFeature(out apiLevel, out feature);
        androidCameraFeature.androidCameraApiLevel_  = apiLevel;
        androidCameraFeature.androidCameraHwFeature_ = feature;
#endif

        if (cameraDeviceSettings.videoImageSize.x != 0 && cameraDeviceSettings.videoImageSize.y != 0)
        {
            cameraDevice_.SetVideoImageSize((int)cameraDeviceSettings.videoImageSize.x, (int)cameraDeviceSettings.videoImageSize.y);
        }
        ConfigCameraDevice(cameraDeviceSettings, true);

        isFlipX_ = false;
        isFlipY_ = false;
        if (isFront_)
        {
#if UNITY_IOS && !UNITY_EDITOR
            isFlipY_ = true;
#elif UNITY_EDITOR || UNITY_STANDALONE_WIN
            // NOOP
#else
            if (cameraRotation_ == smartar.Rotation.ROTATION_0 || cameraRotation_ == smartar.Rotation.ROTATION_90)
            {
                isFlipX_ = true;
            }
            else
            {
                isFlipY_ = true;
            }
#endif
        }
        cameraImageDrawer_.SetFlipX(isFlipX_);
        cameraImageDrawer_.SetFlipY(isFlipY_);

        // Setup Recognizer
        smartar.CameraDeviceInfo cameraInfo = new smartar.CameraDeviceInfo();
        cameraDevice_.GetDeviceInfo(cameraInfo);
        recognizer_.SetCameraDeviceInfo(cameraInfo);

        // Enable native instance
        sarSmartar_SarSmartARController_sarDoEnable(self_, cameraDevice_.self_);

        // set listener
        cameraDevice_.SetStillImageListener(new StillImageListener(createCaptureImagePath(), smart_));
        cameraDevice_.SetAutoFocusListener(new AutoFocusListener());
        cameraDevice_.SetAutoExposureListener(new AutoExposureListener());
        cameraDevice_.SetAutoWhiteBalanceListener(new AutoWhiteBalanceListener());

        // Start components
        cameraImageDrawer_.Start();
        landmarkDrawer_.Start();
        cameraDevice_.Start();
        sensorDevice_.Start();

        if (GetComponent <Camera>().clearFlags != CameraClearFlags.Depth && GetComponent <Camera>().clearFlags != CameraClearFlags.Nothing)
        {
            GetComponent <Camera>().clearFlags = CameraClearFlags.Depth;
        }

        enabled_ = true;
    }