Example #1
0
        public string AnonymizeFaces(string imageName, AnonymizationMethods anonymizationMethod, int blocks = 20, double confidence = 0.5)
        {
            var anonymizationMethodArgument = Enum.GetName(typeof(AnonymizationMethods), anonymizationMethod);
            var pathToImage = Path.Combine(_webHostEnvironment.WebRootPath, "SavedFiles", imageName);

            if (!File.Exists(pathToImage))
            {
                throw new FileNotFoundException();
            }

            ProcessStartInfo processStartInfo = new ProcessStartInfo()
            {
                // Move to config file.
                FileName              = @"C:\Users\Georgi Simeonov\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe",
                UseShellExecute       = false,
                Arguments             = $".\\Python\\blur_face.py --image \"{pathToImage}\" --face .\\Python\\face_detector --method {anonymizationMethodArgument} --blocks {blocks} --confidence {confidence}",
                RedirectStandardError = true
            };

            using (var process = Process.Start(processStartInfo))
            {
                process.WaitForExit();

                using (StreamReader errorStream = process.StandardError)
                {
                    var standardError = errorStream.ReadToEnd();

                    if (process.ExitCode != 0)
                    {
                        throw new System.Exception(standardError);
                    }
                }
            }

            var imageExtension            = Path.GetExtension(pathToImage);
            var imageNameWithoutExtension = Path.GetFileNameWithoutExtension(pathToImage);
            var anonymizedImageName       = imageNameWithoutExtension + "-anonymized" + imageExtension;
            var pathToAnonymizedImage     = Path.Combine(_webHostEnvironment.WebRootPath, "SavedFiles", anonymizedImageName);

            if (!File.Exists(pathToAnonymizedImage))
            {
                return(string.Empty);
            }

            return(anonymizedImageName);
        }
Example #2
0
        public string AnonymizeFaces(string imagePath, AnonymizationMethods anonymizationMethod, int blocks = 20, double confidence = 0.5)
        {
            var anonymizationMethodArgument = Enum.GetName(typeof(AnonymizationMethods), anonymizationMethod);

            if (!File.Exists(imagePath))
            {
                throw new FileNotFoundException();
            }

            ProcessStartInfo processStartInfo = new ProcessStartInfo()
            {
                // Move to config file.
                FileName              = @"C:\Users\Georgi Simeonov\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe",
                UseShellExecute       = false,
                Arguments             = $".\\Python\\test_detection.py --image \"{imagePath}\" --face .\\Python\\face_detector --method {anonymizationMethodArgument} --blocks {blocks} --confidence {confidence}",
                RedirectStandardError = true
            };

            using (var process = Process.Start(processStartInfo))
            {
                process.WaitForExit();

                using (StreamReader errorStream = process.StandardError)
                {
                    var standardError = errorStream.ReadToEnd();

                    if (process.ExitCode == 0)
                    {
                        return("Y");
                    }
                    else if (process.ExitCode == 738)
                    {
                        return("N");
                    }
                    else
                    {
                        throw new System.Exception(standardError);
                    }
                }
            }
        }