summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEunki, Hong <eunkiki.hong@samsung.com>2022-08-01 19:45:07 +0900
committerEunki, Hong <eunkiki.hong@samsung.com>2022-08-04 14:06:16 +0900
commit6b0bacc94ed86cee56be7657dfa6da596114c2d9 (patch)
tree346a835b7d22fd64d5e2b27edb447e42d690cdeb
parentc7851039cb1d06ba2841d5518f4a52005058fbe4 (diff)
downloadmediavision-6b0bacc94ed86cee56be7657dfa6da596114c2d9.tar.gz
mediavision-6b0bacc94ed86cee56be7657dfa6da596114c2d9.tar.bz2
mediavision-6b0bacc94ed86cee56be7657dfa6da596114c2d9.zip
[Test] Facial landmark return float coordinate
Due to the facial landmarks are dense, We'd better use float value, not integer. Change-Id: I56bd5ea146e64c96671c8f9c74a41a208409dc66 Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
-rw-r--r--include/mv_common.h11
-rw-r--r--include/mv_inference.h13
-rw-r--r--mv_machine_learning/mv_inference/inference/include/mv_inference_open.h5
-rwxr-xr-xmv_machine_learning/mv_inference/inference/src/Inference.cpp2
-rw-r--r--mv_machine_learning/mv_inference/inference/src/PoseDecoder.cpp16
-rw-r--r--mv_machine_learning/mv_inference/inference/src/mv_inference.c21
-rw-r--r--mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp41
7 files changed, 104 insertions, 5 deletions
diff --git a/include/mv_common.h b/include/mv_common.h
index 090ff8f1..2c8024aa 100644
--- a/include/mv_common.h
+++ b/include/mv_common.h
@@ -45,6 +45,17 @@ typedef struct {
} mv_point_s;
/**
+ * @brief Point in 2D space.
+ *
+ * @since_tizen @if MOBILE 2.4 @else 3.0 @endif
+ */
+typedef struct {
+ float x; /**< X-axis coordinate of the point in 2D space */
+ float y; /**< Y-axis coordinate of the point in 2D space */
+ float z; //int z;
+} mv_point_f;
+
+/**
* @brief Location of the object bounded by quadrangle defined by four 2D points.
*
* @since_tizen @if MOBILE 2.4 @else 3.0 @endif
diff --git a/include/mv_inference.h b/include/mv_inference.h
index 2b8e0547..80283ca2 100644
--- a/include/mv_inference.h
+++ b/include/mv_inference.h
@@ -659,6 +659,12 @@ typedef void (*mv_inference_facial_landmark_detected_cb)(
const mv_point_s *locations,
void *user_data);
+typedef void (*mv_inference_facial_landmark_detected2_cb)(
+ mv_source_h source,
+ int number_of_landmarks,
+ const mv_point_f *locations,
+ void *user_data);
+
/**
* @brief Performs facial landmarks detection on the @a source.
* @details Use this function to launch facial landmark detection.
@@ -701,6 +707,13 @@ int mv_inference_facial_landmark_detect(
mv_inference_facial_landmark_detected_cb detected_cb,
void *user_data);
+int mv_inference_facial_landmark_detect2(
+ mv_source_h source,
+ mv_inference_h infer,
+ mv_rectangle_s *roi,
+ mv_inference_facial_landmark_detected2_cb detected_cb,
+ void *user_data);
+
/**
* @brief Called when poses in @a source are detected.
* @details This type callback is invoked each time when
diff --git a/mv_machine_learning/mv_inference/inference/include/mv_inference_open.h b/mv_machine_learning/mv_inference/inference/include/mv_inference_open.h
index 7f22ac98..1c20e515 100644
--- a/mv_machine_learning/mv_inference/inference/include/mv_inference_open.h
+++ b/mv_machine_learning/mv_inference/inference/include/mv_inference_open.h
@@ -491,6 +491,11 @@ extern "C"
mv_inference_facial_landmark_detected_cb detected_cb,
void *user_data);
+ int mv_inference_facial_landmark_detect2_open(
+ mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi,
+ mv_inference_facial_landmark_detected2_cb detected_cb,
+ void *user_data);
+
/**
* @brief Performs pose landmarks detection on the @a source.
* @details Use this function to launch pose landmark detection.
diff --git a/mv_machine_learning/mv_inference/inference/src/Inference.cpp b/mv_machine_learning/mv_inference/inference/src/Inference.cpp
index a92290ce..2a43efdd 100755
--- a/mv_machine_learning/mv_inference/inference/src/Inference.cpp
+++ b/mv_machine_learning/mv_inference/inference/src/Inference.cpp
@@ -86,7 +86,7 @@ namespace inference
mSupportedInferenceBackend.insert(std::make_pair(
MV_INFERENCE_BACKEND_OPENCV, std::make_pair("opencv", false)));
mSupportedInferenceBackend.insert(std::make_pair(
- MV_INFERENCE_BACKEND_TFLITE, std::make_pair("tflite", false)));
+ MV_INFERENCE_BACKEND_TFLITE, std::make_pair("tflite", true)));
mSupportedInferenceBackend.insert(std::make_pair(
MV_INFERENCE_BACKEND_ARMNN, std::make_pair("armnn", false)));
mSupportedInferenceBackend.insert(std::make_pair(
diff --git a/mv_machine_learning/mv_inference/inference/src/PoseDecoder.cpp b/mv_machine_learning/mv_inference/inference/src/PoseDecoder.cpp
index 308005f1..e04ae74b 100644
--- a/mv_machine_learning/mv_inference/inference/src/PoseDecoder.cpp
+++ b/mv_machine_learning/mv_inference/inference/src/PoseDecoder.cpp
@@ -351,20 +351,28 @@ namespace inference
landmarkOffset = mMeta.GetLandmarkOffset();
}
+ LOGE("landmark count : %d", mNumberOfLandmarks);
LOGE("landmark offset: %d", landmarkOffset);
LOGE("scale width x height: %.3fx%.3f", scaleWidth, scaleHeight);
for (int idx = 0; idx < mNumberOfLandmarks; ++idx) {
float px = mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset);
- float py = mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset + 1);
- float pz = mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset + 2);
+ float py = landmarkOffset >= 2 ? mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset + 1) : 0.0f;
+ float pz = landmarkOffset >= 3 ? mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset + 2) : 0.0f;
- mPoseLandmarks[0].landmarks[idx].score = poseScore;
+ mPoseLandmarks[0].landmarks[idx].score = landmarkOffset < 5 ? poseScore : mTensorBuffer.getValue<float>(mMeta.GetLandmarkName(), idx * landmarkOffset + 4);
mPoseLandmarks[0].landmarks[idx].heatMapLoc = cv::Point(-1, -1);
mPoseLandmarks[0].landmarks[idx].decodedLoc = cv::Point3f(px/scaleWidth, py/scaleHeight, pz);
mPoseLandmarks[0].landmarks[idx].id = idx;
mPoseLandmarks[0].landmarks[idx].valid = true;
- LOGI("idx[%d]: %.4f, %.4f, %.4f", idx, px, py, pz);
+ if(idx < 2)
+ {
+ LOGI("idx[%d]: %.4f, %.4f, %.4f", idx, px, py, pz);
+ }
+ else if(idx == 2)
+ {
+ LOGI("...");
+ }
}
mPoseLandmarks[0].score = poseScore;
diff --git a/mv_machine_learning/mv_inference/inference/src/mv_inference.c b/mv_machine_learning/mv_inference/inference/src/mv_inference.c
index 84c9b7d4..1d30619e 100644
--- a/mv_machine_learning/mv_inference/inference/src/mv_inference.c
+++ b/mv_machine_learning/mv_inference/inference/src/mv_inference.c
@@ -207,6 +207,27 @@ int mv_inference_face_detect(mv_source_h source, mv_inference_h infer,
return ret;
}
+int mv_inference_facial_landmark_detect2(
+ mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi,
+ mv_inference_facial_landmark_detected2_cb detected_cb, void *user_data)
+{
+ MEDIA_VISION_SUPPORT_CHECK(
+ __mv_inference_face_check_system_info_feature_supported());
+ MEDIA_VISION_INSTANCE_CHECK(source);
+ MEDIA_VISION_INSTANCE_CHECK(infer);
+ MEDIA_VISION_NULL_ARG_CHECK(detected_cb);
+
+ MEDIA_VISION_FUNCTION_ENTER();
+
+ int ret = MEDIA_VISION_ERROR_NONE;
+
+ ret = mv_inference_facial_landmark_detect2_open(source, infer, roi,
+ detected_cb, user_data);
+
+ MEDIA_VISION_FUNCTION_LEAVE();
+
+ return ret;
+}
int mv_inference_facial_landmark_detect(
mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi,
diff --git a/mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp b/mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp
index 8ba5f87e..353f8a95 100644
--- a/mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp
+++ b/mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp
@@ -762,6 +762,47 @@ int mv_inference_face_detect_open(mv_source_h source, mv_inference_h infer,
return ret;
}
+int mv_inference_facial_landmark_detect2_open(
+ mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi,
+ mv_inference_facial_landmark_detected2_cb detected_cb, void *user_data)
+{
+ Inference *pInfer = static_cast<Inference *>(infer);
+ std::vector<mv_source_h> sources;
+ std::vector<mv_rectangle_s> rects;
+
+ sources.push_back(source);
+
+ if (roi != NULL)
+ rects.push_back(*roi);
+
+ int ret = pInfer->Run(sources, rects);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to run inference");
+ return ret;
+ }
+
+ FacialLandMarkDetectionResults facialLandMarkDetectionResults;
+
+ ret = pInfer->GetFacialLandMarkDetectionResults(&facialLandMarkDetectionResults);
+ if (ret != MEDIA_VISION_ERROR_NONE) {
+ LOGE("Fail to get inference results");
+ return ret;
+ }
+
+ int numberOfLandmarks = facialLandMarkDetectionResults.number_of_landmarks;
+ std::vector<mv_point_f> locations(numberOfLandmarks);
+
+ for (int landmark_idx = 0; landmark_idx < numberOfLandmarks; ++landmark_idx) {
+ locations[landmark_idx].x = facialLandMarkDetectionResults.locations[landmark_idx].x;
+ locations[landmark_idx].y = facialLandMarkDetectionResults.locations[landmark_idx].y;
+ locations[landmark_idx].z = facialLandMarkDetectionResults.locations[landmark_idx].z;
+ }
+
+ detected_cb(source, numberOfLandmarks, locations.data(), user_data);
+
+ return ret;
+}
+
int mv_inference_facial_landmark_detect_open(
mv_source_h source, mv_inference_h infer, mv_rectangle_s *roi,
mv_inference_facial_landmark_detected_cb detected_cb, void *user_data)