Revert "Revert "mv_inference: Add Post Estimation feature support""
authorInki Dae <inki.dae@samsung.com>
Mon, 1 Jun 2020 02:13:46 +0000 (11:13 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 1 Jun 2020 02:13:46 +0000 (11:13 +0900)
This reverts commit ddfddc6f6a0a1730558f0874ae3d44a7cbaf5d00.

Change-Id: I8586fe69d258f04b1b6bd0a26085366509c5514d
Signed-off-by: Inki Dae <inki.dae@samsung.com>
include/mv_inference.h
mv_inference/inference/include/Inference.h
mv_inference/inference/include/mv_inference_open.h
mv_inference/inference/src/Inference.cpp
mv_inference/inference/src/mv_inference.c
mv_inference/inference/src/mv_inference_open.cpp

index 878c19bef4c052f9ce8823287598b004e47812b7..a30a7c8af2b8b4c9bf68941650622d1a5693fe9a 100644 (file)
@@ -635,6 +635,12 @@ typedef void (*mv_inference_facial_landmark_detected_cb)(
        const mv_point_s *locations,
        void *user_data);
 
+typedef void (*mv_inference_pose_estimation_detected_cb)(
+       mv_source_h source,
+       int number_of_landmarks,
+       const mv_point_s *locations,
+       void *user_data);
+
 /**
  * @brief Performs facial landmarks detection on the @a source.
  * @details Use this function to launch facial landmark detection.
@@ -676,6 +682,49 @@ int mv_inference_facial_landmark_detect(
        mv_rectangle_s *roi,
        mv_inference_facial_landmark_detected_cb detected_cb,
        void *user_data);
+
+/**
+ * @brief Performs pose estimation detection on the @a source.
+ * @details Use this function to launch pose estimation detection.
+ *          Each time when mv_inference_pose_estimation_detect() is
+ *          called, @a detected_cb will receive a list pose estimation's locations
+ *          in the media source.
+ *
+ * @since_tizen 6.0
+ * @remarks This function is synchronous and may take considerable time to run.
+ *
+ * @param[in] source         The handle to the source of the media
+ * @param[in] infer          The handle to the inference
+ * @param[in] roi            Rectangular area including a face in @a source which
+ *                           will be analyzed. If NULL, then the whole source will be
+ *                           analyzed.
+ * @param[in] detected_cb    The callback which will receive the detection results.
+ * @param[in] user_data      The user data passed from the code where
+ *                           mv_inference_pose_estimation_detect() is invoked.
+ *                           This data will be accessible in @a detected_cb callback.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_VISION_ERROR_INTERNAL          Internal error
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace
+ *                                                  isn't supported
+ *
+ * @pre Create a source handle by calling mv_create_source()
+ * @pre Create an inference handle by calling mv_inference_create()
+ * @pre Configure an inference handle by calling mv_inference_configure()
+ * @pre Prepare an inference by calling mv_inference_prepare()
+ * @post @a detected_cb will be called to provide detection results
+ *
+ * @see mv_inference_pose_estimation_detected_cb()
+ */
+int mv_inference_pose_estimation_detect(
+       mv_source_h source,
+       mv_inference_h infer,
+       mv_rectangle_s *roi,
+       mv_inference_pose_estimation_detected_cb detected_cb,
+       void *user_data);
+
 /**
  * @}
  */
index f96184499cb2cfe58a8b4c047296e4e3cc0ee731..c2a7b2e3ededc91d6c6482573919994c2140e65e 100755 (executable)
@@ -60,6 +60,11 @@ typedef struct _FacialLandMarkDetectionResults {
     std::vector<cv::Point> locations;
 } FacialLandMarkDetectionResults;  /**< structure FacialLandMarkDetectionResults */
 
+typedef struct _PoseEstimationResults {
+    int number_of_pose_estimation;
+    std::vector<cv::Point> locations;
+} PoseEstimationResults;  /**< structure PoseEstimationResults */
+
 namespace mediavision {
 namespace inference {
 
@@ -297,6 +302,14 @@ public:
         */
        int GetFacialLandMarkDetectionResults(FacialLandMarkDetectionResults* results);
 
+       /**
+        * @brief       Gets the PoseEstimationDetectionResults
+        *
+        * @since_tizen 6.0
+        * @return @c true on success, otherwise a negative error value
+        */
+       int GetPoseEstimationDetectionResults(PoseEstimationResults* results);
+
        int GetResults(std::vector<std::vector<int>>* dimInfo, std::vector<float*> *results);
 
        mv_engine_config_h GetEngineConfig(void) { return engine_config; }
index 5477b3fbc825856ff9539a4522caef986d771333..e3140524580737958b3e4be7d919460cf5f88e6c 100755 (executable)
@@ -487,6 +487,52 @@ int mv_inference_facial_landmark_detect_open(
         mv_rectangle_s *roi,
        mv_inference_facial_landmark_detected_cb detected_cb,
        void *user_data);
+
+/**
+ * @brief Performs pose estimation detection on the @a source
+ * @details Use this function to launch pose estimation detection.
+ *          Each time when mv_inference_pose_estimation_detect() is
+ *          called, @a detected_cb will receive a list pose estimation's locations
+ *          on the media source.
+ *
+ * @since_tizen 5.5
+ *
+ * @param [in] source         The handle to the source of the media
+ * @param [in] infer          The handle to the inference
+ * @param[in] roi            Rectangular box bounding face image on the
+ *                           @a source. If NULL, then full source will be
+ *                           analyzed.
+ * @param [in] detected_cb    The callback which will be called for
+ *                            detecting facial landmark on media source.
+ *                            This callback will receive the detection results.
+ * @param [in] user_data      The user data passed from the code where
+ *                            @ref mv_inference_facial_landmark_detect() is invoked.
+ *                            This data will be accessible from @a detected_cb callback.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MEDIA_VISION_ERROR_INTERNAL          Internal error
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT Source colorspace
+ *                                                  isn't supported
+ * @retval #MEDIA_VISION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ *
+ * @pre Create a source handle by calling @ref mv_create_source()
+ * @pre Create an inference handle by calling @ref mv_inference_create()
+ * @pre Configure an inference handle by calling @ref mv_inference_configure()
+ * @pre Prepare an inference by calling @ref mv_inference_prepare()
+ * @post @a detected_cb will be called to process detection results
+ *
+ * @see mv_inference_pose_estimation_detected_cb
+ */
+int mv_inference_pose_estimation_detect_open(
+       mv_source_h source,
+       mv_inference_h infer,
+    mv_rectangle_s *roi,
+       mv_inference_pose_estimation_detected_cb detected_cb,
+       void *user_data);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 99628624e4434c0fc6f51b7404dfdf842dd2f7bc..5a12b350ce5eb509ebef856e1b55673e587c0a6a 100755 (executable)
@@ -1238,5 +1238,57 @@ int Inference::GetFacialLandMarkDetectionResults(FacialLandMarkDetectionResults
        return MEDIA_VISION_ERROR_NONE;
 }
 
+int Inference::GetPoseEstimationDetectionResults(PoseEstimationResults *detectionResults)
+{
+       tensor_t outputData;
+
+       // Get inference result and contain it to outputData.
+       int ret = FillOutputResult(outputData);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to get output result.");
+               return ret;
+       }
+
+       std::vector<std::vector<int>> inferDimInfo(outputData.dimInfo);
+       std::vector<void*> inferResults(outputData.data.begin(), outputData.data.end());
+
+       long number_of_pose = inferDimInfo[0][3];
+       float * tmp = static_cast<float*>(inferResults[0]);
+       cv::Size heatMapSize(inferDimInfo[0][1], inferDimInfo[0][2]);
+
+       cv::Point loc;
+       double score;
+       cv::Mat blurredHeatMap;
+
+       cv::Mat reShapeTest( cv::Size(inferDimInfo[0][2], inferDimInfo[0][1]), CV_32FC(inferDimInfo[0][3]), (void*)tmp);
+
+       cv::Mat multiChannels[inferDimInfo[0][3]];
+       split(reShapeTest, multiChannels);
+
+       float ratioX = (float)mSourceSize.width / (float)inferDimInfo[0][2];
+       float ratioY = (float)mSourceSize.height / (float)inferDimInfo[0][1];
+
+       PoseEstimationResults results;
+       results.number_of_pose_estimation = 0;
+       for (int poseIdx = 0; poseIdx < number_of_pose; poseIdx++) {
+               cv::Mat heatMap = multiChannels[poseIdx];
+
+               cv::GaussianBlur(heatMap, blurredHeatMap, cv::Size(), 5.0, 5.0);
+               cv::minMaxLoc(heatMap, NULL, &score, NULL, &loc);
+
+               LOGI("PoseIdx[%2d]: x[%2d], y[%2d], score[%.3f]", poseIdx, loc.x, loc.y, score);
+               LOGI("PoseIdx[%2d]: x[%2d], y[%2d], score[%.3f]", poseIdx, (int)((float)(loc.x+1) * ratioX), (int)((float)(loc.y+1) * ratioY), score);
+
+               loc.x = (int)((float)(loc.x+1) * ratioX);
+               loc.y = (int)((float)(loc.y+1) * ratioY);
+               results.locations.push_back(loc);
+               results.number_of_pose_estimation++;
+       }
+
+       *detectionResults = results;
+       LOGE("Inference: PoseEstimationResults: %d\n", results.number_of_pose_estimation);
+       return MEDIA_VISION_ERROR_NONE;
+}
+
 } /* Inference */
 } /* MediaVision */
index 580facc6759bcd2b1489568cee7fdbd58bb2aedf..56ca9993225d447991f135fe1590de55ee1bb93f 100755 (executable)
@@ -108,6 +108,7 @@ int mv_inference_configure(mv_inference_h infer, mv_engine_config_h engine_confi
        return ret;
 }
 
+
 int mv_inference_prepare(mv_inference_h infer)
 {
        MEDIA_VISION_SUPPORT_CHECK(__mv_inference_check_system_info_feature_supported());
@@ -313,3 +314,33 @@ int mv_inference_facial_landmark_detect(
 
 #endif
 }
+
+int mv_inference_pose_estimation_detect(
+       mv_source_h source,
+       mv_inference_h infer,
+       mv_rectangle_s *roi,
+       mv_inference_pose_estimation_detected_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;
+
+#ifdef MEDIA_VISION_INFERENCE_LICENCE_PORT
+       /*
+       ret = mv_inference_pose_estimation_lic(source, infer, detected_cb, user_data);
+       */
+#else
+
+       ret = mv_inference_pose_estimation_detect_open(source, infer, roi, detected_cb, user_data);
+
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return ret;
+#endif
+}
\ No newline at end of file
index 45679e327643cb6c7373b48176964d16db6c924c..57cdfa92fe2e462e85ba792d8e6dfb371ba0f932 100755 (executable)
@@ -806,3 +806,50 @@ int mv_inference_facial_landmark_detect_open(
 
        return ret;
 }
+
+int mv_inference_pose_estimation_detect_open(
+       mv_source_h source,
+       mv_inference_h infer,
+       mv_rectangle_s *roi,
+       mv_inference_pose_estimation_detected_cb detected_cb,
+       void *user_data)
+{
+       Inference *pInfer = static_cast<Inference *>(infer);
+
+       int ret = MEDIA_VISION_ERROR_NONE;
+       int numberOfPoseEstimation = 0;
+       std::vector<mv_source_h> sources;
+       std::vector<mv_rectangle_s> rects;
+
+       sources.push_back(source);
+
+       if (roi != NULL)
+               rects.push_back(*roi);
+
+       ret = pInfer->Run(sources, rects);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to run inference");
+               return ret;
+       }
+
+       PoseEstimationResults poseEstimationResults;
+       ret = pInfer->GetPoseEstimationDetectionResults(&poseEstimationResults);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to get inference results");
+               return ret;
+       }
+
+       numberOfPoseEstimation = poseEstimationResults.number_of_pose_estimation;
+
+       std::vector<mv_point_s> locations(numberOfPoseEstimation);
+
+       for (int n = 0; n < numberOfPoseEstimation; ++n) {
+
+               locations[n].x = poseEstimationResults.locations[n].x;
+               locations[n].y = poseEstimationResults.locations[n].y;
+       }
+
+       detected_cb(source, numberOfPoseEstimation, locations.data(), user_data);
+
+       return ret;
+}