차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
ko:bs2_extracetemplatefaceex [2022/06/27 16:20] mark [샘플코드] |
ko:bs2_extracetemplatefaceex [2024/05/28 19:47] (현재) kkshin |
||
|---|---|---|---|
| 줄 5: | 줄 5: | ||
| ===== BS2_ExtractTemplateFaceEx ===== | ===== BS2_ExtractTemplateFaceEx ===== | ||
| - | [+ 2.7.1] ''FaceStation F2'' 얼굴이 포함된 이미지를 가지고, template을 추출합니다. \\ | + | [+ 2.7.1] ''Visual Face 기반'' 얼굴이 포함된 이미지를 가지고, template을 추출합니다. \\ |
| AOC 카드에 template을 담기 위해 사용합니다. | AOC 카드에 template을 담기 위해 사용합니다. | ||
| + | <callout type="warning" icon="true"> | ||
| + | **주의 사항** \\ | ||
| + | [[BS2_GetNormalizedImageFaceEx]]를 통해 추출된 이미지를 전달하여야 합니다. | ||
| + | </callout> | ||
| + | |||
| ==== 함수 ==== | ==== 함수 ==== | ||
| <code cpp> | <code cpp> | ||
| 줄 27: | 줄 32: | ||
| 성공적으로 수행될 경우 ''BS_SDK_SUCCESS''를 반환하고, 에러가 발생할 경우 상응하는 에러 코드를 반환합니다. | 성공적으로 수행될 경우 ''BS_SDK_SUCCESS''를 반환하고, 에러가 발생할 경우 상응하는 에러 코드를 반환합니다. | ||
| \\ | \\ | ||
| - | ==== 샘플코드 ==== | ||
| - | C++ | ||
| - | <code cpp> | ||
| - | int UserControl::extractTemplateFaceEx(BS2_DEVICE_ID id, BS2TemplateEx& templateEx) | ||
| - | { | ||
| - | BS2SimpleDeviceInfoEx deviceInfoEx = { 0, }; | ||
| - | |||
| - | int sdkResult = BS2_GetDeviceInfoEx(context_, id, NULL, &deviceInfoEx); | ||
| - | if (BS_SDK_SUCCESS != sdkResult) | ||
| - | { | ||
| - | TRACE("BS2_GetDeviceInfoEx call failed: %d", sdkResult); | ||
| - | return sdkResult; | ||
| - | } | ||
| - | |||
| - | bool faceExScanSupported = (deviceInfoEx.supported & BS2SimpleDeviceInfoEx::BS2_SUPPORT_FACE_EX_SCAN) == | ||
| - | BS2SimpleDeviceInfoEx::BS2_SUPPORT_FACE_EX_SCAN; | ||
| - | if (faceExScanSupported) | ||
| - | { | ||
| - | try | ||
| - | { | ||
| - | if (Utility::isYes("Do you want to extract faceEx template from image?")) | ||
| - | { | ||
| - | string imagePath = Utility::getInput<string>("Enter the face image path and name:");//C:\88withphone.jpg | ||
| - | uint32_t size = Utility::getResourceSize(imagePath); | ||
| - | shared_ptr<uint8_t> buffer(new uint8_t[size], ArrayDeleter<uint8_t>()); | ||
| - | |||
| - | size_t dataOffset = offsetof(BS2FaceEx, rawImageData); | ||
| - | size_t faceSize = dataOffset + size; | ||
| - | if (Utility::getResourceFromFile(imagePath, buffer, size)) | ||
| - | { | ||
| - | sdkResult = BS2_ExtractTemplateFaceEx(context_, id, buffer.get(), size, 0, &templateEx); | ||
| - | if (BS_SDK_SUCCESS != sdkResult) | ||
| - | { | ||
| - | TRACE("BS2_ExtractTemplateFaceEx call failed: %d", sdkResult); | ||
| - | return sdkResult; | ||
| - | } | ||
| - | print(templateEx); | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | catch (const std::exception&) | ||
| - | { | ||
| - | |||
| - | } | ||
| - | } | ||
| - | |||
| - | return sdkResult; | ||
| - | } | ||
| - | BS2_ReleaseObject(uidObj); | ||
| - | </code> | ||
| - | C# | ||
| - | <code cpp> | ||
| - | Console.WriteLine("Do you want to register from image? [y/n]"); | ||
| - | Console.Write(">> "); | ||
| - | if (Util.IsYes()) | ||
| - | { | ||
| - | Console.WriteLine("Enter the face image path and name:"); | ||
| - | Console.Write(">> "); | ||
| - | string imagePath = Console.ReadLine(); | ||
| - | |||
| - | if (!File.Exists(imagePath)) | ||
| - | { | ||
| - | Console.WriteLine("Invalid file path"); | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | Image faceImage = Image.FromFile(imagePath); | ||
| - | if (!faceImage.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)) | ||
| - | { | ||
| - | Console.WriteLine("Invalid image file format"); | ||
| - | return; | ||
| - | } | ||
| - | | ||
| - | IntPtr imageData = IntPtr.Zero; | ||
| - | UInt32 imageLen = 0; | ||
| - | if (Util.LoadBinary(imagePath, out imageData, out imageLen)) | ||
| - | { | ||
| - | if (0 == imageLen) | ||
| - | { | ||
| - | Console.WriteLine("Empty image file"); | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | int structHeaderSize = Marshal.SizeOf(typeof(BS2FaceExUnwarped)); | ||
| - | int totalSize = structHeaderSize + (int)imageLen; | ||
| - | userBlob[0].faceExObjs = Marshal.AllocHGlobal(totalSize); | ||
| - | IntPtr curFaceExObjs = userBlob[0].faceExObjs; | ||
| - | |||
| - | BS2FaceExUnwarped unwarped = Util.AllocateStructure<BS2FaceExUnwarped>(); | ||
| - | unwarped.flag = 0; | ||
| - | unwarped.imageLen = imageLen; | ||
| - | |||
| - | Marshal.StructureToPtr(unwarped, curFaceExObjs, false); | ||
| - | curFaceExObjs += structHeaderSize; | ||
| - | |||
| - | Util.CopyMemory(curFaceExObjs, imageData, imageLen); | ||
| - | |||
| - | userBlob[0].user.numFaces = 1; | ||
| - | unwarpedMemory = true; | ||
| - | } | ||
| - | } | ||
| - | </code> | ||