|
10 | 10 | #include "feature_hub/feature_hub_db.h" |
11 | 11 | #include "initialization_module/launch.h" |
12 | 12 | #include "initialization_module/resource_manage.h" |
| 13 | +#include "recognition_module/similarity_converter.h" |
13 | 14 |
|
14 | 15 | using namespace inspire; |
15 | 16 |
|
@@ -66,6 +67,74 @@ HYPER_CAPI_EXPORT extern HResult HFCreateImageStream(PHFImageData data, HFImageS |
66 | 67 | return HSUCCEED; |
67 | 68 | } |
68 | 69 |
|
| 70 | +HYPER_CAPI_EXPORT extern HResult HFCreateImageStreamEmpty(HFImageStream *handle) { |
| 71 | + if (handle == nullptr) { |
| 72 | + return HERR_INVALID_IMAGE_STREAM_HANDLE; |
| 73 | + } |
| 74 | + auto stream = new HF_CameraStream(); |
| 75 | + *handle = (HFImageStream)stream; |
| 76 | + return HSUCCEED; |
| 77 | +} |
| 78 | + |
| 79 | +HYPER_CAPI_EXPORT extern HResult HFImageStreamSetBuffer(HFImageStream handle, HPUInt8 buffer, HInt32 width, HInt32 height) { |
| 80 | + if (handle == nullptr) { |
| 81 | + return HERR_INVALID_IMAGE_STREAM_HANDLE; |
| 82 | + } |
| 83 | + ((HF_CameraStream *)handle)->impl.SetDataBuffer(buffer, width, height); |
| 84 | + return HSUCCEED; |
| 85 | +} |
| 86 | + |
| 87 | +HYPER_CAPI_EXPORT extern HResult HFImageStreamSetRotation(HFImageStream handle, HFRotation rotation) { |
| 88 | + if (handle == nullptr) { |
| 89 | + return HERR_INVALID_IMAGE_STREAM_HANDLE; |
| 90 | + } |
| 91 | + switch (rotation) { |
| 92 | + case HF_CAMERA_ROTATION_90: |
| 93 | + ((HF_CameraStream *)handle)->impl.SetRotationMode(inspirecv::ROTATION_90); |
| 94 | + break; |
| 95 | + case HF_CAMERA_ROTATION_180: |
| 96 | + ((HF_CameraStream *)handle)->impl.SetRotationMode(inspirecv::ROTATION_180); |
| 97 | + break; |
| 98 | + case HF_CAMERA_ROTATION_270: |
| 99 | + ((HF_CameraStream *)handle)->impl.SetRotationMode(inspirecv::ROTATION_270); |
| 100 | + break; |
| 101 | + default: |
| 102 | + ((HF_CameraStream *)handle)->impl.SetRotationMode(inspirecv::ROTATION_0); |
| 103 | + break; |
| 104 | + } |
| 105 | + return HSUCCEED; |
| 106 | +} |
| 107 | + |
| 108 | +HYPER_CAPI_EXPORT extern HResult HFImageStreamSetFormat(HFImageStream handle, HFImageFormat format) { |
| 109 | + if (handle == nullptr) { |
| 110 | + return HERR_INVALID_IMAGE_STREAM_HANDLE; |
| 111 | + } |
| 112 | + switch (format) { |
| 113 | + case HF_STREAM_RGB: |
| 114 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::RGB); |
| 115 | + break; |
| 116 | + case HF_STREAM_BGR: |
| 117 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::BGR); |
| 118 | + break; |
| 119 | + case HF_STREAM_RGBA: |
| 120 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::RGBA); |
| 121 | + break; |
| 122 | + case HF_STREAM_BGRA: |
| 123 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::BGRA); |
| 124 | + break; |
| 125 | + case HF_STREAM_YUV_NV12: |
| 126 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::NV12); |
| 127 | + break; |
| 128 | + case HF_STREAM_YUV_NV21: |
| 129 | + ((HF_CameraStream *)handle)->impl.SetDataFormat(inspirecv::NV21); |
| 130 | + break; |
| 131 | + default: |
| 132 | + return HERR_INVALID_IMAGE_STREAM_PARAM; // Assume there's a return code for unsupported |
| 133 | + // formats |
| 134 | + } |
| 135 | + return HSUCCEED; |
| 136 | +} |
| 137 | + |
69 | 138 | HYPER_CAPI_EXPORT extern HResult HFReleaseImageStream(HFImageStream streamHandle) { |
70 | 139 | if (streamHandle == nullptr) { |
71 | 140 | return HERR_INVALID_IMAGE_STREAM_HANDLE; |
@@ -372,6 +441,16 @@ HResult HFQueryExpansiveHardwareRockchipDmaHeapPath(HString path) { |
372 | 441 | return HSUCCEED; |
373 | 442 | } |
374 | 443 |
|
| 444 | +HResult HFSetExpansiveHardwareAppleCoreMLModelPath(HString path) { |
| 445 | + // TODO: Implement this function |
| 446 | + return HSUCCEED; |
| 447 | +} |
| 448 | + |
| 449 | +HResult HFQueryExpansiveHardwareAppleCoreMLModelPath(HString path) { |
| 450 | + // TODO: Implement this function |
| 451 | + return HSUCCEED; |
| 452 | +} |
| 453 | + |
375 | 454 | HResult HFFeatureHubDataEnable(HFFeatureHubConfiguration configuration) { |
376 | 455 | inspire::DatabaseConfiguration param; |
377 | 456 | if (configuration.primaryKeyMode != HF_PK_AUTO_INCREMENT && configuration.primaryKeyMode != HF_PK_MANUAL_INPUT) { |
@@ -447,6 +526,39 @@ HResult HFSessionSetFaceDetectThreshold(HFSession session, HFloat threshold) { |
447 | 526 | return ctx->impl.SetFaceDetectThreshold(threshold); |
448 | 527 | } |
449 | 528 |
|
| 529 | +HResult HFSessionSetTrackModeSmoothRatio(HFSession session, HFloat ratio) { |
| 530 | + if (session == nullptr) { |
| 531 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 532 | + } |
| 533 | + HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session; |
| 534 | + if (ctx == nullptr) { |
| 535 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 536 | + } |
| 537 | + return ctx->impl.SetTrackModeSmoothRatio(ratio); |
| 538 | +} |
| 539 | + |
| 540 | +HResult HFSessionSetTrackModeNumSmoothCacheFrame(HFSession session, HInt32 num) { |
| 541 | + if (session == nullptr) { |
| 542 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 543 | + } |
| 544 | + HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session; |
| 545 | + if (ctx == nullptr) { |
| 546 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 547 | + } |
| 548 | + return ctx->impl.SetTrackModeNumSmoothCacheFrame(num); |
| 549 | +} |
| 550 | + |
| 551 | +HResult HFSessionSetTrackModeDetectInterval(HFSession session, HInt32 num) { |
| 552 | + if (session == nullptr) { |
| 553 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 554 | + } |
| 555 | + HF_FaceAlgorithmSession *ctx = (HF_FaceAlgorithmSession *)session; |
| 556 | + if (ctx == nullptr) { |
| 557 | + return HERR_INVALID_CONTEXT_HANDLE; |
| 558 | + } |
| 559 | + return ctx->impl.SetTrackModeDetectInterval(num); |
| 560 | +} |
| 561 | + |
450 | 562 | HResult HFExecuteFaceTrack(HFSession session, HFImageStream streamHandle, PHFMultipleFaceData results) { |
451 | 563 | if (session == nullptr) { |
452 | 564 | return HERR_INVALID_CONTEXT_HANDLE; |
@@ -648,6 +760,49 @@ HResult HFFaceComparison(HFFaceFeature feature1, HFFaceFeature feature2, HPFloat |
648 | 760 | return ret; |
649 | 761 | } |
650 | 762 |
|
| 763 | +HResult HFGetRecommendedCosineThreshold(HPFloat threshold) { |
| 764 | + if (!INSPIRE_LAUNCH->isMLoad()) { |
| 765 | + INSPIRE_LOGW("Inspireface is not launched, using default threshold 0.48"); |
| 766 | + } |
| 767 | + *threshold = SIMILARITY_CONVERTER_GET_RECOMMENDED_COSINE_THRESHOLD(); |
| 768 | + return HSUCCEED; |
| 769 | +} |
| 770 | + |
| 771 | +HResult HFCosineSimilarityConvertToPercentage(HFloat similarity, HPFloat result) { |
| 772 | + if (!INSPIRE_LAUNCH->isMLoad()) { |
| 773 | + INSPIRE_LOGW("Inspireface is not launched."); |
| 774 | + } |
| 775 | + *result = SIMILARITY_CONVERTER_RUN(similarity); |
| 776 | + return HSUCCEED; |
| 777 | +} |
| 778 | + |
| 779 | +HResult HFUpdateCosineSimilarityConverter(HFSimilarityConverterConfig config) { |
| 780 | + if (!INSPIRE_LAUNCH->isMLoad()) { |
| 781 | + INSPIRE_LOGW("Inspireface is not launched."); |
| 782 | + } |
| 783 | + inspire::SimilarityConverterConfig cfg; |
| 784 | + cfg.threshold = config.threshold; |
| 785 | + cfg.middleScore = config.middleScore; |
| 786 | + cfg.steepness = config.steepness; |
| 787 | + cfg.outputMin = config.outputMin; |
| 788 | + cfg.outputMax = config.outputMax; |
| 789 | + SIMILARITY_CONVERTER_UPDATE_CONFIG(cfg); |
| 790 | + return HSUCCEED; |
| 791 | +} |
| 792 | + |
| 793 | +HResult HFGetCosineSimilarityConverter(PHFSimilarityConverterConfig config) { |
| 794 | + if (!INSPIRE_LAUNCH->isMLoad()) { |
| 795 | + INSPIRE_LOGW("Inspireface is not launched."); |
| 796 | + } |
| 797 | + inspire::SimilarityConverterConfig cfg = SIMILARITY_CONVERTER_GET_CONFIG(); |
| 798 | + config->threshold = cfg.threshold; |
| 799 | + config->middleScore = cfg.middleScore; |
| 800 | + config->steepness = cfg.steepness; |
| 801 | + config->outputMin = cfg.outputMin; |
| 802 | + config->outputMax = cfg.outputMax; |
| 803 | + return HSUCCEED; |
| 804 | +} |
| 805 | + |
651 | 806 | HResult HFGetFeatureLength(HPInt32 num) { |
652 | 807 | *num = 512; |
653 | 808 |
|
|
0 commit comments