private void AddToFaceCaptureQueue(FaceFrameResult frameResult, RectF colorBoundingBox, byte[] face) { Joint head = _LastKnownJoints[JointType.Head]; if (head.IsTracked() && _HighQualityFaceCaptures.Count < MaxHighQualityFaceCaptures && _FaceCaptureQueue.Count < MaxFaceQueueSize) { int pitch; int yaw; int roll; frameResult.FaceRotationQuaternion.ExtractFaceRotationInDegrees(out pitch, out yaw, out roll); _Yaw = yaw; _Roll = roll; _Pitch = pitch; FaceCapture capture = new FaceCapture(face, Convert.ToInt32(colorBoundingBox.Width), Convert.ToInt32(colorBoundingBox.Height)) { Distance = Convert.ToInt32(head.Position.DistanceToCamera() * 1000), Pitch = pitch, Yaw = yaw, Roll = roll, Left = Convert.ToInt32(colorBoundingBox.X), Top = Convert.ToInt32(colorBoundingBox.Y) }; //Console.WriteLine("Face Capture Created! Current Face Capture Count : {0}", _HighQualityFaceCaptures.Count); _FaceCaptureQueue.Enqueue(capture); } }
private void AddHighQualityFaceCapture(FaceCapture capture) { if (_HighQualityFaceCaptures.Count < MaxHighQualityFaceCaptures) { _HighQualityFaceCaptures.Add(capture); this.NotifyPropertyChanged(PropertyChanged, "ColorPhoto"); } }
public SetDrivenKeyMapper(TextAsset SDK_Definition, List <Transform> faceJoints, Transform headJoint, Transform leftEyeJoint, Transform rightEyeJoint, FaceCapture faceCapture) { this.SDK_Definition = SDK_Definition; this.faceJoints = faceJoints; this.headJoint = headJoint; this.leftEye = leftEyeJoint; this.rightEye = rightEyeJoint; initialTranslation = new Dictionary <Transform, Vector3>(); initialRotation = new Dictionary <Transform, Vector3>(); initialScale = new Dictionary <Transform, Vector3>(); foreach (Transform j in faceJoints) { initialTranslation.Add(j, j.localPosition); initialRotation.Add(j, j.localEulerAngles); initialScale.Add(j, j.localScale); } faceCapture.OnChannelsUpdated += SolveSetDrivenKeys; }
void CameraSelectGUI() //handles camera selection { bool changeFlag = false; EditorGUILayout.BeginHorizontal(); GUILayout.Label("Camera:", GUILayout.Width(100)); //Camera selection dropdown int cameraCount = FacePlus.GetCameraCount(); cams = new string[cameraCount]; for (int j = 0; j < cameraCount; j++) { cams[j] = FacePlus.GetCameraDeviceName(j); } if (cams == null || cams.Length < 1) { cams = new string[] { "No Cameras detected" } } ; if (currentCamIndex > cams.Length - 1) { currentCamIndex = 0; } //check for changes in status if (!string.IsNullOrEmpty(currentCam)) { if (currentCam.CompareTo(cams[currentCamIndex]) != 0) { int j; for (j = 0; j < cameraCount; j++) { if (cams[j].CompareTo(currentCam) == 0) { currentCamIndex = j; break; } } //camera no longer exists if (j == cameraCount) { options.cameraLost = true; } } } int index = EditorGUILayout.Popup(currentCamIndex, cams); currentCam = cams[index]; if (index < cams.Length + 1) { //if the camera has changed or been lost if ((index != currentCamIndex) || options.cameraLost) { options.cameraLost = false; options.changeCamera = true; Debug.Log("New Camera Device Selected."); } currentCamIndex = index; } FacePlus.DeviceID = index; EditorGUILayout.EndHorizontal(); } void RealtimeCaptureGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Microphone:", GUILayout.Width(100)); //Microphone selection dropdown string[] devices = Microphone.devices; mics = new string[devices.Length + 1]; mics[0] = "Disabled"; for (int i = 0; i < devices.Length; i++) { mics[i + 1] = devices[i]; } if (mics == null || mics.Length <= 1) { mics = new string[] { "No microphones detected" } } ; if (EditorPrefs.HasKey("FacePlus.Microphone")) { currentMicIndex = EditorPrefs.GetInt("FacePlus.Microphone"); } if (currentMicIndex > mics.Length - 1) { currentMicIndex = 0; } int index = EditorGUILayout.Popup(currentMicIndex, mics); if (index < mics.Length) { currentMic = mics[index]; currentMicIndex = index; } EditorPrefs.SetInt("FacePlus.Microphone", currentMicIndex); if (currentMic == "No microphones detected" || currentMic == "Disabled") { options.recordAudio = false; } else { options.recordAudio = true; } EditorGUILayout.EndHorizontal(); //camera selection GUI CameraSelectGUI(); // track EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); // record or stop recording if (character.State == CaptureState.Recording) { if (GUILayout.Button(stop, GUILayout.Width(60)) || SpacePressed()) { if (options.recordAudio) { Microphone.End(currentMic); } character.StopRecording(() => { SaveClip(); SaveAudioClip(); Repaint(); }); } } else { GUI.enabled = character.CanRecord; if (GUILayout.Button(record, GUILayout.Width(60)) || SpacePressed()) { if (!character.Live) { character.StartLiveTracking(); } if (clip != null && clip.length > 1.00f && options.requiresConfirmation) { overwrite = EditorUtility.DisplayDialog("This take will be overwritten!", "You can create a new take to avoid overwriting.", "Record anyway", "Cancel"); if (!overwrite) { return; } overwrite = false; } character.OnStartRecording += StartRecordAudio; //add audiorecord to event so it doesn't go too early character.StartRecording(); Repaint(); } } if (character.State == CaptureState.Playing) { if (GUILayout.Button(stopPlaying, GUILayout.Width(60))) { character.StopPlayback(); PlayBackAudio(false); Repaint(); } } else { GUI.enabled = character.CanPlay; if (GUILayout.Button(play, GUILayout.Width(60))) { character.StartPlayback(); PlayBackAudio(true); Repaint(); } } if (options.changeCamera) { options.changeCamera = false; if (character.State == CaptureState.Live) { FacePlus.StopTracking(); } character.StartLiveTracking(); } if (character != null && character.State == CaptureState.BakingAnimation) { ProgressBar(character.Progress, "Baking Animation"); } else { TimeSliderGUI(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // GUILayout.Label ("Record Audio:"); // options.recordAudio = EditorGUILayout.Toggle (options.recordAudio, GUILayout.Width (15)); if (character != null) { if (options.mode == Mode.Realtime && !character.Live && Authentication.CanUseFacePlus) { Logger.Info("start live tracking - toggled checkbox"); if (character.Movie != null) { character.Movie.Dispose(); } character.StartLiveTracking(); Logger.Info("done calling startlivetracking"); } } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Check Minimum Requirements")) { Application.OpenURL("http://hubs.ly/y02VLJ0"); } } void OfflineCaptureGUI() { /*EditorGUILayout.BeginHorizontal(); //Titles Grouping Start * EditorGUILayout.LabelField("Animate from imported movie", EditorStyles.boldLabel); * EditorGUILayout.EndHorizontal(); // Titles Grouping End */ EditorGUILayout.BeginHorizontal(); // Video Select Grouping Start GUILayout.Label("Video:", GUILayout.Width(100)); if (GUILayout.Button("Browse...", GUILayout.Width(70))) { videoPath = EditorUtility.OpenFilePanel("Select your Video", "", ""); } GUILayout.Label(Path.GetFileName(videoPath)); // TODO: Clip the path! EditorGUILayout.EndHorizontal(); // Video Select Grouping End EditorGUILayout.BeginHorizontal(); GUILayout.Label("Frame Rate: ", GUILayout.Width(100)); frameRate = EditorGUILayout.FloatField(frameRate, GUILayout.Width(35)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (character.State == CaptureState.RecordingFromVideo) { if (GUILayout.Button(stop, GUILayout.Width(60)) || SpacePressed() || character.videoFinished) //if video finishes { character.StopRecordingFromVideo(() => { character.videoFinished = false; SaveClip(); Repaint(); }); } } else { GUI.enabled = character.CanRecord; if (GUILayout.Button(record, GUILayout.Width(60)) || SpacePressed()) { if (clip != null && clip.length > 0f && options.requiresConfirmation) { Logger.Info("overwriting"); overwrite = EditorUtility.DisplayDialog("This take will be overwritten!", "You can create a new take to avoid overwriting", "Record anyway", "Cancel"); if (!overwrite) { return; } overwrite = false; } if (!string.IsNullOrEmpty(videoPath)) { var videoFolder = Path.GetDirectoryName(videoPath); var videoFilename = Path.GetFileName(videoPath); character.SetImportMovie(videoFolder, videoFilename); } else // TODO: error about no file selected { } Repaint(); } } if (character.State == CaptureState.PlayingWithVideo) { if (GUILayout.Button(stopPlaying, GUILayout.Width(60))) { character.StopPlaybackWithVideo(); Repaint(); } } else { GUI.enabled = character.CanPlayWithVideo; if (GUILayout.Button(play, GUILayout.Width(60))) { character.StartPlaybackWithVideo(); Repaint(); } } if (character != null && character.State == CaptureState.RecordingFromVideo) { GUI.enabled = true; ProgressBar(character.Progress, "Processing Video: " + character.CurrentVideoFrame + " / " + character.TotalVideoFrames); } else if (character != null && character.State == CaptureState.BakingAnimation) { GUI.enabled = true; ProgressBar(character.Progress, "Baking Animation"); } else { TimeSliderGUI(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUI.enabled = true; } void TimeSliderGUI() { GUILayout.BeginVertical(); timeSlider = character.Progress; timeSlider = GUILayout.HorizontalSlider(timeSlider, 0.0f, 1.0f); // 0 - 1 so you can force normalized playback across the timeline GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); var tmp = GUI.enabled; GUI.enabled = true; GUILayout.Label(string.Format("Time: {0,5:##0.0} / {1,2:0.0}", character.ClipPosition, character.ClipLength)); GUI.enabled = tmp; GUILayout.EndHorizontal(); GUILayout.EndVertical(); } void FacePlusErrorGUI() { Color previousContent = GUI.contentColor; EditorGUILayout.BeginHorizontal(); GUI.contentColor = Color.red; GUILayout.Label("Faceplus Error: " + FacePlus.GetError()); EditorGUILayout.EndHorizontal(); GUI.contentColor = previousContent; } void FacePlusMessageGUI() { GUILayout.BeginHorizontal(); GUIStyle style = new GUIStyle(EditorStyles.label); style.wordWrap = true; style.padding = new RectOffset(5, 5, 5, 5); GUILayout.Label(_login_str, style); if (GUILayout.Button("Dismiss")) { _login_str = null; } GUILayout.EndHorizontal(); Divider(); EditorGUILayout.Space(); } void MainGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(displayName, EditorStyles.miniButton)) { Authentication.Logout(); _login_str = null; EditorPrefs.DeleteKey("FacePlus.Password"); password = ""; if (character.State == CaptureState.Live) { character.StopLiveTracking(); } needsRepainting = true; } EditorGUILayout.EndHorizontal(); Divider(); EditorGUILayout.Space(); //Errors if (FacePlus.HasError && FacePlus.GetError() != "") { FacePlusErrorGUI(); } //Messages if (_login_str != null && _login_str != "") { FacePlusMessageGUI(); } //Takes GUILayout.BeginHorizontal(); GUILayout.Label("Current Take:", GUILayout.Width(100)); var newClip = (AnimationClip)EditorGUILayout.ObjectField(clip, typeof(AnimationClip)); GUILayout.EndHorizontal(); // load a clip if the clip changes if (newClip != clip && newClip != null) { clip = newClip; if (character != null && character.channelMapping != null) { character.Load(clip); } } // load a clip if we don't have one already if (character != null && clip != null && !character.HasClip && character.channelMapping != null) { character.Load(clip); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(100)); if (GUILayout.Button("Create New")) { clip = CreateClip(); } // Disable following buttons when there's no clip. GUI.enabled = clip != null; if (GUILayout.Button("Find in Assets")) { //Find the clip within the Project window in Unity. EditorGUIUtility.PingObject(clip); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); EditorGUILayout.BeginVertical(); //Super V EditorGUILayout.Space(); if (!EditorApplication.isPlaying) { needsLoginStringCleared = true; if (GUILayout.Button("Start Scene")) { EditorApplication.isPlaying = true; Repaint(); } EditorGUILayout.Space(); } else if (character == null) { GUILayout.Label("Please attach a FaceCapture component to your Character."); } else { Divider(); // Mode Selection Dropdown EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Capture Mode:", GUILayout.Width(100)); int newMode = EditorGUILayout.Popup((int)options.mode, modes); if ((Mode)newMode != options.mode) { // TODO: do cleanup when switching modes if (newMode != (int)Mode.Realtime) { character.StopLiveTracking(); } options.mode = (Mode)newMode; } EditorGUILayout.EndHorizontal(); if (options.mode == Mode.Realtime) { /*if(character.State != CaptureState.Live){ * character.Movie.Dispose(); * }*/ RealtimeCaptureGUI(); } else { OfflineCaptureGUI(); } EditorGUILayout.Space(); } //Divider(); OptionsGUI(); EditorGUILayout.Space(); Divider(); CalibrateGUI(); FuseGUI(); LinkGUI(); } void OnGUI() { autoRepaintOnSceneChange = true; var c = FaceCapture.Instance; if (character == null && c != null && Authentication.CanUseFacePlus) { if (options.mode == Mode.Realtime) { Logger.Info("Starting tracking..."); c.StartLiveTracking(); } } character = c; if (character) { character.OnStopPlayback -= OnPlaybackStopped; character.OnStopPlayback += OnPlaybackStopped; } EditorGUILayout.Space(); GUILayout.BeginVertical(); // 1 if (!Authentication.CanUseFacePlus) { LoginWindow(); } else { MainGUI(); } EditorGUILayout.EndVertical(); } private AnimationClip CreateClip() { string path = EditorUtility.SaveFilePanelInProject("New Animation Clip", FirstAvailableClipName(), "anim", "Where would you like to save this?"); Logger.Info("Got this path to create clip in: " + path); if (!string.IsNullOrEmpty(path)) { AnimationClip emptyClip = new AnimationClip(); #if !UNITY_4_2 AnimationUtility.SetAnimationType(emptyClip, ModelImporterAnimationType.Generic); #endif AssetDatabase.CreateAsset(emptyClip, path); AssetDatabase.Refresh(); Logger.Info("Clip is null? " + (emptyClip == null)); return(emptyClip); } return(null); }
public PlantLifeForm() { Console.WriteLine("PlantLifeForm main window starting constructor!!!"); InitializeComponent(); this.PlantLifePicture.Size=this.DesktopBounds.Size; var uri = new System.Uri("ms-appx:///images/logo.png"); //var file = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri); //ImageMain.Source= ImageSource plantlifeImages = new PlantLifeImagesService(); plantlifeImages.frameSize = this.PlantLifePicture.Size; plantlifeImages.initializeJSONFile(); ConfigLoad(); FaceCapture.HasCuda = HasCuda; var oclptr = OclInvoke.GetPlatformInfo(); if (oclptr.Size < 1) { Console.WriteLine("NO OCL GPUs FOUND!!!"); } else { var myb = oclptr[0]; var myb1 = oclptr[oclptr.Size - 1]; //OclPlatformInfo opi = (OclPlatformInfo)listinfo; Console.WriteLine("GPU CUDA OCL checker size=" + oclptr.Size + " GPU0= " + myb + " GPU1=" + myb1); // size=2 GPU0= Intel(R) OpenCL GPU1=NVIDIA CUDA } if (HasCuda) { faceTrainingFile = faceTrainingFileCuda; eyeTrainingFile = eyeTrainingFileCuda; Console.WriteLine("HasCuda overwriten haar training files =" + HasCuda); } this.faceCapture = new FaceCapture(faceTrainingFile, eyeTrainingFile,FaceScale, FaceNieghbors, FaceMinSize); this.faceCapture.Scale = FaceScale; this.faceCapture.Neighbors = FaceNieghbors; this.faceCapture.FaceMinSize = FaceMinSize; this.faceCapture.FaceMaxSize = FaceMaxSize; this.faceCapture.FaceCaptured += FaceCapture_FaceCaptured; this.faceCapture.ImageCaptured += faceCapture_ImageCaptured; // start off with default plant image: updatePlantImage(); Console.WriteLine("PlantLifeForm constructor completed!!!"); }