성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div><p> 주간 닷넷에 소개된,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 주간닷넷 2016년 8월 2일 ; <a target='tab' href='https://learn.microsoft.com/en-us/archive/blogs/eva/%EC%A3%BC%EA%B0%84%EB%8B%B7%EB%84%B7-2016%EB%85%84-8%EC%9B%94-2%EC%9D%BC'>https://learn.microsoft.com/en-us/archive/blogs/eva/%EC%A3%BC%EA%B0%84%EB%8B%B7%EB%84%B7-2016%EB%85%84-8%EC%9B%94-2%EC%9D%BC</a> </pre> <br /> 내용 중에 다음의 것을 한번 실습해 보았습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Detect and Blur Faces with .NET Core and Face API ; <a target='tab' href='https://carlos.mendible.com/2016/07/30/detect-and-blur-faces-with-dotnetcore-and-face-api/'>https://carlos.mendible.com/2016/07/30/detect-and-blur-faces-with-dotnetcore-and-face-api/</a> </pre> <br /> 위의 내용에 소개된 Face API는 마이크로소프트가 Azure를 통해 서비스하는 "Cognitive Services" 중의 하나입니다. 따라서 이 API를 사용하려면 APIKey를 받아야 하고 그러려면 다음의 페이지에서 구독 신청을 해야 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Cognitive Services - Get started for free ; <a target='tab' href='https://www.microsoft.com/cognitive-services/en-us/sign-up'>https://www.microsoft.com/cognitive-services/en-us/sign-up</a> </pre> <br /> 그럼 다양한 서비스를 신청할 수 있는데, <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Cognitive Services - Request new trials ; <a target='tab' href='https://azure.microsoft.com/en-us/services/cognitive-services/'>https://azure.microsoft.com/en-us/services/cognitive-services/</a> </pre> <br /> Face API의 경우 (분당 20건의 제한으로) 월 3만 건의 호출을 무료로 사용할 수 있습니다.<br /> <br /> 어쨌든, 신청을 하면 API Key를 받았을 테고 시작해 보겠습니다. ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> 사실 모든 순서는 "<a target='tab' href='https://carlos.mendible.com/2016/07/30/detect-and-blur-faces-with-dotnetcore-and-face-api/'>Detect and Blur Faces with .NET Core and Face API</a>" 글에 잘 나와 있습니다. 하지만, .NET Core를 바탕으로 하고 있는데, 그냥 윈도우 응용 프로그램에도 쉽게 적용할 수 있습니다.<br /> <br /> 제 경우에는 윈도우 콘솔 프로그램으로 시작해 보겠습니다. 프로젝트 만든 후, NuGet을 통해 "Microsoft Cognitive Services Face API"와 함께 관련 라이브러리를 참조 추가합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > PM> Install-Package Microsoft.ProjectOxford.Face PM> Install-Package ChyImageProcessorCore -Pre PM> Install-Package System.Numerics.Vectors -Pre PM> Install-Package System.Runtime.CompilerServices.Unsafe </pre> <br /> 그다음 App.config에 Face API Key를 입력해 설정해 두고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <appSettings> <span style='color: blue; font-weight: bold'><add key="FaceAPIKey" value="...[your_face_api_key]..." /></span> </appSettings> </configuration> </pre> <br /> "<a target='tab' href='https://carlos.mendible.com/2016/07/30/detect-and-blur-faces-with-dotnetcore-and-face-api/'>Detect and Blur Faces with .NET Core and Face API</a>" 글의 소스 코드를 그대로 적용하시면 됩니다.<br /> <br /> <pre style='height: 400px; margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using System; using System.IO; using System.Linq; using System.Threading.Tasks; using ImageProcessorCore; using Microsoft.ProjectOxford.Face; using Microsoft.ProjectOxford.Face.Contract; using System.Configuration; public class Program { const string sourceImage = "face_blur_1.png"; public static void Main(string[] args) { const string destinationImage = "detectedfaces.jpg"; var detects = DetectFaces(sourceImage, ConfigurationManager.AppSettings["FaceAPIKey"]); var faceRects = detects.Result; Console.WriteLine($"Detected {faceRects.Length} faces"); BlurFaces(faceRects, sourceImage, destinationImage); Console.WriteLine($"Done!!!"); } private static void BlurFaces(FaceRectangle[] faceRects, string sourceImage, string destinationImage) { if (File.Exists(destinationImage)) { File.Delete(destinationImage); } if (faceRects.Length > 0) { using (FileStream stream = File.OpenRead(sourceImage)) using (FileStream output = File.OpenWrite(destinationImage)) { var image = new Image<Color, uint>(stream); foreach (var faceRect in faceRects) { var rectangle = new Rectangle( faceRect.Left, faceRect.Top, faceRect.Width, faceRect.Height); image = image.BoxBlur(20, rectangle); } image.SaveAsJpeg(output); } } } private static async Task<FaceRectangle[]> DetectFaces(string imageFilePath, string apiKey) { var faceServiceClient = new FaceServiceClient(apiKey); try { using (Stream imageFileStream = File.OpenRead(imageFilePath)) { var faces = await faceServiceClient.DetectAsync(imageFileStream); var faceRects = faces.Select(face => face.FaceRectangle); return faceRects.ToArray(); } } catch (Exception) { return new FaceRectangle[0]; } } } </pre> <br /> 직접 실습을 해봤는데, 좀 실망(?!)스럽군요. 아래는 원본 사진에서 위의 프로그램을 돌려 얼굴을 인식해 흐림 처리한 결과입니다. 그런데... 요즘 핫한 사람의 얼굴조차 인식하지 못하고 있습니다. ^^;<br /> <br /> <img alt='face_blur_0.jpg' src='/SysWebRes/bbs/face_blur_0.jpg' /><br /> <br /> (<a target='tab' href='https://www.sysnet.pe.kr/bbs/DownloadAttachment.aspx?fid=1079&boardid=331301885'>첨부 파일은 이 글의 예제 코드를 포함</a>합니다.)<br /> </p><br /> </div>
첨부파일
스팸 방지용 인증 번호
5764
(왼쪽의 숫자를 입력해야 합니다.)