// ------------------------------------------------------------------------------------------------------------- void OnDisable() { #if (UNITY_STANDALONE || UNITY_EDITOR || UNITY_WEBGL) RigidFaceTrackingBridge.xzimgReleaseRigidTracking(); myWebCamEngine.ReleaseVideoCapturePlane(); #elif UNITY_ANDROID RigidFaceTrackingBridge.Release(); #elif UNITY_IOS RigidFaceTrackingBridge.xzimgFaceApiReleaseRigidTracking(); #endif DisposeObjects(); }
// ------------------------------------------------------------------------------------------------------------- void Awake() { CheckeParameters(); double fovx = (double)CameraFOVX * 3.1415 / 180.0; if (!useNativeCapture) { if (myWebCamEngine == null) { myWebCamEngine = (xmgWebCamTexture)gameObject.AddComponent(typeof(xmgWebCamTexture)); myWebCamEngine.CaptureWidth = GetVideoCaptureWidth(); myWebCamEngine.CaptureHeight = GetVideoCaptureHeight(); myWebCamEngine.MirrorVideo = MirrorVideo; myWebCamEngine.CameraFOVX = CameraFOVX; myWebCamEngine.UseFrontal = UseFrontal; m_WebcamTexture = myWebCamEngine.CreateVideoCapturePlane(1.0f, videoPlaneFittingMode, videoCaptureIndex); } if (m_WebcamTexture) { int captureWidth = m_WebcamTexture.width, captureHeight = m_WebcamTexture.height; if (captureWidth < 100) { // Unity BUG MACOSX captureWidth = m_WebcamTexture.requestedWidth; captureHeight = m_WebcamTexture.requestedHeight; } // Image has the size of obtained video capture resolution image.m_width = captureWidth; image.m_height = captureHeight; image.m_colorType = 3; image.m_type = 0; image.m_flippedH = true; RigidFaceTrackingBridge.xzimgInitializeRigidTracking(new StringBuilder(), new StringBuilder(), new StringBuilder()); trackingParams.m_size.w = GetProcessingWidth(); trackingParams.m_size.h = GetProcessingHeight(); trackingParams.m_rotate_mode = (int)captureDeviceOrientation; RigidFaceTrackingBridge.xzimgSetCalibration(fovx, GetProcessingWidth(image.m_width), GetProcessingHeight(image.m_height), 0, trackingParams.m_rotate_mode); trackingParams.m_detect_without_eyes = 1; } else { Debug.Log("No camera detected with Unity webcamTexture!"); } } else { // __Prepare Video Capture videoOptions.resolution_mode = videoCaptureMode; videoOptions.frontal = UseFrontal ? 1 : 0; videoOptions.focus_mode = 1; videoOptions.exposure_mode = 1; videoOptions.while_balance_mode = 1; // Create a plane and get back its texture ID PrepareBackgroundPlane(); trackingParams.m_detect_without_eyes = 1; #if UNITY_ANDROID // Create the texture for video stream imgTexture = new Texture2D(GetVideoCaptureWidth(), GetVideoCaptureHeight(), TextureFormat.RGB24, false); gameObject.GetComponent <Renderer>().material.mainTexture = imgTexture; videoOptions.texture_ptr = imgTexture.GetNativeTexturePtr(); int rotateMode = 1; if (Screen.orientation == ScreenOrientation.LandscapeRight) { rotateMode = 2; } else if (Screen.orientation == ScreenOrientation.Portrait) { rotateMode = UseFrontal?1:3; } else if (Screen.orientation == ScreenOrientation.LandscapeLeft) { rotateMode = 0; } else if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) { rotateMode = UseFrontal?3:1; } currentDeviceOrientation = (DeviceOrientation)Screen.orientation; RigidFaceTrackingBridge.StartCameraAndInitialize(videoOptions.resolution_mode, UseFrontal, fovx, rotateMode, false); #elif UNITY_IOS // Create the texture for video stream imgTexture = new Texture2D(GetVideoCaptureWidth(), GetVideoCaptureHeight(), TextureFormat.BGRA32, false); gameObject.GetComponent <Renderer>().material.mainTexture = imgTexture; videoOptions.texture_ptr = imgTexture.GetNativeTexturePtr(); int status = RigidFaceTrackingBridge.xzimgFaceApiInitializeRigidTracking(ref videoOptions); if (status != 1) { Debug.Log("Initialization is impossible!"); } trackingParams.m_size.w = GetProcessingWidth(); trackingParams.m_size.h = GetProcessingHeight(); trackingParams.m_rotate_mode = 0; trackingParams.m_rotate_mode = GetScreenOrientationIndex(); //Debug.Log(trackingParams.m_rotate_mode); RigidFaceTrackingBridge.xzimgSetCalibration(fovx, GetProcessingWidth(), GetProcessingHeight(), trackingParams.m_rotate_mode, trackingParams.m_rotate_mode); trackingParams.m_detect_without_eyes = 1; //trackingParams.m_non_rigid_init_quality = 0; RigidFaceTrackingBridge.xzimgFaceApiReleaseRigidTracking(); status = RigidFaceTrackingBridge.xzimgFaceApiInitializeRigidTracking(ref videoOptions); RigidFaceTrackingBridge.xzimgSetCalibration(fovx, GetProcessingWidth(), GetProcessingHeight(), trackingParams.m_rotate_mode, trackingParams.m_rotate_mode); #endif } }