/// <summary> /// 컬러 프래임 데이터를 비트맵으로 전환 [Save Color Frame to bitmap(jpeg)] /// </summary> /// <param name="slender"></param> /// <param name="e"></param> private async void SaveColorMap(object slender, ColorFrameArrivedEventArgs e) { if (bodyEixst) { using (ColorFrame colorFrame = e.FrameReference.AcquireFrame()) { if (colorFrame != null) { FrameDescription colorFrameDescription = colorFrame.FrameDescription; using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) { this.colorBitmap.Lock(); // verify data and write the new color frame data to the display bitmap if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight)) { colorFrame.CopyConvertedFrameDataToIntPtr( this.colorBitmap.BackBuffer, (uint) (colorFrameDescription.Width*colorFrameDescription.Height*4), ColorImageFormat.Bgra); this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight)); } this.colorBitmap.Unlock(); } } } if (!viewBool) { if (this.alarm_white.Visibility == Visibility.Hidden && alarmCount == 0) { this.alarm_red.Visibility = Visibility.Hidden; this.alarm_white.Visibility = Visibility.Visible; alarmCount = 4; } else if (this.alarm_red.Visibility == Visibility.Hidden && alarmCount == 0) { this.alarm_red.Visibility = Visibility.Visible; this.alarm_white.Visibility = Visibility.Hidden; alarmCount = 4; } else { alarmCount--; } } } else { this.alarm_red.Visibility = Visibility.Hidden; this.alarm_white.Visibility = Visibility.Visible; } // 스냅샷을 찍어야 할 때만 컬러 프래임의 정보를 가져옴 if (this.needSnapShot) { try { if (this.needSnapShot) { if (this.snapShotWait != 0) { this.snapShotWait--; } else { // Jpeg 확장자로 데이터를 인코딩시켜주늩 인코더 객체 생성 BitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(this.colorBitmap)); string date = DateTime.Now.ToString("yyyy'-'MM'-'dd", CultureInfo.CurrentUICulture.DateTimeFormat); string time = DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat); string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); // 지정한 히스토리 폴더 패스에 년-월-일-시-분-초 형식으로 저장 string path = System.IO.Path.Combine(historyFolderPath, "[" + date + "]_" + time + ".jpeg"); string log = string.Format("{0}\t{1}\t{2}", date + time, "스냅샷이 촬영되어 히스토리 파일에 저장 되었습니다.", path); using (FileStream fs = new FileStream(path, FileMode.Create)) { // 이미지 파일 저장 encoder.Save(fs); fs.Close(); // 로그 작성 stringToLog(log); imageListwriter.pushList(path); VisitorInfo VSD = new VisitorInfo(true, path); if (faceAnalysis != null) { faceAnalysis.verify(VSD); } // 변수 초기화 this.needSnapShot = false; this.snapShotWait = 7; } } } } catch (IOException) { } } }
// 저장소에 등록된 사람들인지 아닌지 확인 public async void verify(VisitorInfo info) { IFaceServiceClient faceServiceClient = new FaceServiceClient("e6edd17d1bbd4ca69d14ccf572e9af20"); string date = System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"); if (this.persons == null) return; //Mutex Wait //this.mutex.WaitOne(); string filepath = info.filepath; //List<Result> ret = new List<Result>(); Face[] faces = await this.UploadAndDetectFaces(filepath); List<Result> results = new List<Result>(); //얼굴이 존재하지 않을 경우 if (faces.Length == 0) { //Mutext Relase //this.mutex.Release(); Result result = new Result("No face", filepath, "No face", date); results.Add(result); xmLwriterInstance.HistoryWriting(results.ToArray()); xmLwriterInstance.AlertWriting(results.ToArray()); //xmLwriterInstance.pushXMLQueue(result); return; } Boolean verifed = false; // this.mutex.WaitOne(); // DB에 사람들과 비교하는 부분 foreach (Face face in faces) { foreach (Person person in this.persons) { if (person.faceid != null) { Guid guid = new Guid(person.faceid); /* Important region! * * The free offer provides all Face API operations that include face detection, * face verification, similar face searching, face grouping, and person identification. * With this free plan, calling to the Face APIs limits to 20 transactions * per minute and 5000 transactions per month. * * Face API의 베타 버전으로 인해 최대 1분당 20 전송량이 최대이기 때문에 제한이 걸림. */ VerifyResult verifyresult = null; try { verifyresult = await faceServiceClient.VerifyAsync(face.FaceId, guid); //DB에 저장한 사람들과 일치한 경우 if (verifyresult.IsIdentical) { Result result = new Result(person.name, filepath, person.relation); verifed = true; results.Add(result); } } catch (Exception e) { return; } } } if (verifed == false) { Result result = new Result("Unknown", filepath, "Unknown", date); results.Add(result); } else { verifed = true; } } //this.mutex.Release(); xmLwriterInstance.HistoryWriting(results.ToArray()); xmLwriterInstance.AlertWriting(results.ToArray()); //Mutext Relase //this.mutex.Release(); }