private async Task FinalProcessing(CameraParameters cameraParameters, string name) { var fileName = Path.GetRandomFileName().Replace(".", "") + Path.GetRandomFileName().Replace(".", ""); var FolderName = "/DetectedFaces/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + DateTime.Now.DayOfWeek + "/"; var FinalPath = Application.StartupPath + FolderName; Directory.CreateDirectory(FinalPath); cameraParameters.minimizedFrame.Save(FinalPath + fileName + ".bmp"); // End local saving and begin sending data to portal if app is online if (AppIsOnline) { var newDetection = new LastDetected() { CameraId = cameraParameters.CameraName, DetectedAt = DateTime.Now.ToString(), UserName = name }; var serializedData = JsonConvert.SerializeObject(newDetection); // convert it to json var oldDetections = lastDetecteds.Where(x => x.CameraId == cameraParameters.CameraName && x.UserName == name).ToList(); foreach (var item in oldDetections) { lastDetecteds.Remove(item); } lastDetecteds.Add(newDetection); HttpClient client = new HttpClient(); var Url = "https://localhost:44324/api/detectedfaces/PostImages"; // client.BaseAddress = new Uri("http://localhost:4354/api/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ""); var multipartContent = new MultipartFormDataContent(); //var content = new StringContent(serializedData, Encoding.UTF8, "application/json"); //multipartContent.Add(content); byte[] file = File.ReadAllBytes(FinalPath + fileName + ".bmp"); Stream stream = new MemoryStream(file); using (var mem = new MemoryStream()) { await stream.CopyToAsync(mem); var byteContent = new ByteArrayContent(mem.ToArray()); multipartContent.Add(byteContent, "detectedFace", fileName + ".bmp"); multipartContent.Add(new StringContent(newDetection.CameraId), "CameraId"); multipartContent.Add(new StringContent(newDetection.UserName), "UserName"); multipartContent.Add(new StringContent(newDetection.DetectedAt), "DetectedAt"); var response = await client.PostAsync(Url, multipartContent); } } }
void detecteGesture() { float diffLeft = 0; float diffRight = 0; int numberRight = 0; int numberLeft = 0; LastDetected lastDetected = LastDetected.Nothing; int indexLast = 0; bool toFront = false; bool punch = false; bool leftMove = false; for (int i = 0; i < tailleTab; i++) { diffLeft = diffLeft + difPosZLeft[(tailleTab + index - 1 - i) % tailleTab]; diffRight = diffRight + difPosZRight[(tailleTab + index - 1 - i) % tailleTab]; if (diffLeft < -seuilDetection && diffRight > seuilDetection) { if ((lastDetected == LastDetected.Nothing || lastDetected == LastDetected.Left) && (i - indexLast) >= minTimeBetweenHands && (i - indexLast) <= maxTimeBetweenHands) { indexLast = i; numberRight++; lastDetected = LastDetected.Right; } } else if (diffRight < -seuilDetection && diffLeft > seuilDetection) { if ((lastDetected == LastDetected.Nothing || lastDetected == LastDetected.Right) && (i - indexLast) >= minTimeBetweenHands && (i - indexLast) <= maxTimeBetweenHands) { indexLast = i; numberLeft++; lastDetected = LastDetected.Left; } } if (i < tailleTabPunch) { if (diffLeft > seuilZoneMorte || diffLeft < -seuilZoneMorte) { leftMove = true; } if (!toFront) { if (diffRight < -seuilDetectionPunch) { toFront = true; } } else if (diffRight < seuilZoneMorte && diffRight > -seuilZoneMorte) { punch = true; } } } if (numberRight > 1 && numberLeft > 1) { print("RUN"); gestureDetectedRun = true; timerCooldown = 0f; generalCooldown.setIsOnCooldown(); } else if (punch && !leftMove) { print("PUNCH"); gestureDetectedPunch = true; timerCooldown = 0f; generalCooldown.setIsOnCooldown(); } }