From: Tae-Young Chung Date: Fri, 17 Jul 2020 06:26:58 +0000 (+0900) Subject: [Bug] fix bug to apply roi when it is given X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=32cb58637a80a53222fce45e89be57f7763bb53d;p=platform%2Fcore%2Fapi%2Fmediavision.git [Bug] fix bug to apply roi when it is given Signed-off-by: Tae-Young Chung --- diff --git a/mv_inference/inference/src/mv_inference_open.cpp b/mv_inference/inference/src/mv_inference_open.cpp index 5d1f2eee..5063625e 100755 --- a/mv_inference/inference/src/mv_inference_open.cpp +++ b/mv_inference/inference/src/mv_inference_open.cpp @@ -800,7 +800,7 @@ int mv_inference_pose_landmark_detect_open( std::vector sources; std::vector rects; - unsigned int width, height; + unsigned int width, height, offsetX, offsetY; ret = mv_source_get_width(source, &width); if (ret != MEDIA_VISION_ERROR_NONE) { LOGE("Fail to get width"); @@ -813,10 +813,17 @@ int mv_inference_pose_landmark_detect_open( return ret; } + offsetX = offsetY = 0; + sources.push_back(source); - if (roi != NULL) + if (roi != NULL) { rects.push_back(*roi); + width = roi->width; + height = roi->height; + offsetX = roi->point.x; + offsetY = roi->point.y; + } ret = pInfer->Run(sources, rects); if (ret != MEDIA_VISION_ERROR_NONE) { @@ -856,18 +863,19 @@ int mv_inference_pose_landmark_detect_open( LOGE("user_data is NULL"); } - LOGE("W: %d, H:%d", width, height); + LOGE("W: %d, H:%d, offsetX: %d, offsetY: %d ", width, height, offsetX, offsetY); /* poseLandMarkDetection results includes location as float between 0 ~ 1 */ for (int n = 0; n < pose->number_of_landmarks; ++n) { if (poseLandMarkDetectionResults.score[n] < 0.0f) { pose->landmarks[n].point.x = -1; pose->landmarks[n].point.y = -1; + pose->landmarks[n].score = -1.0f; pose->landmarks[n].label = NULL; } else { pose->landmarks[n].point.x = static_cast(static_cast(width) * - poseLandMarkDetectionResults.locations[n].x); + poseLandMarkDetectionResults.locations[n].x) + offsetX; pose->landmarks[n].point.y = static_cast(static_cast(height) * - poseLandMarkDetectionResults.locations[n].y); + poseLandMarkDetectionResults.locations[n].y) + offsetY; pose->landmarks[n].score = poseLandMarkDetectionResults.score[n]; pose->landmarks[n].label = NULL; diff --git a/test/testsuites/stream_infer/stream_infer.c b/test/testsuites/stream_infer/stream_infer.c index d6e5ca25..6610a556 100644 --- a/test/testsuites/stream_infer/stream_infer.c +++ b/test/testsuites/stream_infer/stream_infer.c @@ -396,24 +396,13 @@ void _human_pose_cb ( float score = 0.0f; int cnt = 0; for (int n = 0; n < number_of_pose_estimation; ++n) { - humanSkeleton.pose[n].x = locations->landmarks[n].point.x; - humanSkeleton.pose[n].y = locations->landmarks[n].point.y; + + humanSkeleton.pose[n].x = (int)(640.f*(float)(locations->landmarks[n].point.x)/192.f); + humanSkeleton.pose[n].y = (int)(480.f*(float)(locations->landmarks[n].point.y)/192.f); humanSkeleton.scores[n] = locations->landmarks[n].score; - if (score >= 0.0 ) { - score += humanSkeleton.scores[n]; - cnt++; - } - //printf("(%d,%d): %f\n", humanSkeleton.pose[n].x, humanSkeleton.pose[n].y, confidences[n]); - //printf("(%d,%d)\n", humanSkeleton.pose[n].x, humanSkeleton.pose[n].y); - } - score /= (float)cnt; - if (score >= 0.5) { - humanSkeleton.IsDetected = true; - } else { - humanSkeleton.IsDetected = false; - humanSkeleton.label = -1; } + humanSkeleton.IsDetected = true; } static gboolean @@ -438,7 +427,7 @@ run_pose (void *user_data) clock_gettime(CLOCK_MONOTONIC, &s_tspec); - mv_inference_pose_landmark_detect(mv_src_p, hp_mv_infer, NULL, _human_pose_cb, NULL); + mv_inference_pose_landmark_detect(mv_src_p, hp_mv_infer, &poseRoi, _human_pose_cb, NULL); clock_gettime(CLOCK_MONOTONIC, &e_tspec); struct timespec diffspec = diff(s_tspec, e_tspec); @@ -552,9 +541,12 @@ draw_overlay_pose (GstElement * overlay, cairo_t * cr, guint64 timestamp, cairo_set_line_width(cr, 2.0); + float poseWeight = 0.7f; + float prevPoseWeight = 0.3f; if (!humanSkeleton.IsDetected) return; + /* // if (humanSkeleton.isPrevPose == false) { humanSkeleton.prevPose[1] = humanSkeleton.pose[1]; @@ -728,7 +720,26 @@ draw_overlay_pose (GstElement * overlay, cairo_t * cr, guint64 timestamp, } } } +*/ + for (int k = 0; k < 16; ++k) { + if (humanSkeleton.isPrevPose == false) { + humanSkeleton.prevPose[k] = humanSkeleton.pose[k]; + } else { + + humanSkeleton.prevPose[k].x = (poseWeight * humanSkeleton.pose[k].x + + prevPoseWeight * humanSkeleton.prevPose[k].x); + humanSkeleton.prevPose[k].y = (poseWeight * humanSkeleton.pose[k].y + + prevPoseWeight * humanSkeleton.prevPose[k].y); + } + } + for (int k = 0; k < 16; ++k) { + if (humanSkeleton.scores[k] > 0.0f) { + cairo_arc(cr, humanSkeleton.prevPose[k].x, humanSkeleton.prevPose[k].y, 3,0, 2*M_PI); + cairo_stroke(cr); + } + } +/* // //draw.. // head - neck @@ -801,6 +812,7 @@ draw_overlay_pose (GstElement * overlay, cairo_t * cr, guint64 timestamp, } } cairo_stroke(cr); + */ } static void @@ -914,6 +926,11 @@ int perform_armnn_human_pose_cpm_configure(mv_engine_config_h mv_engine_cfg) MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, PE_TFLITE_CPM_WEIGHT_PATH); + mv_engine_config_set_string_attribute( + mv_engine_cfg, + MV_INFERENCE_MODEL_USER_FILE_PATH, + PE_POSE_LABEL_PATH); + mv_engine_config_set_int_attribute(mv_engine_cfg, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32); @@ -1800,7 +1817,7 @@ static int app_create(void *data) g_object_set(G_OBJECT(vrsink), "signal-handoffs", TRUE, NULL); if (ad->modelType == MODEL_TYPE_POSE_CPM) { - handler_p = g_signal_connect (vrsink, "handoff", G_CALLBACK(_pose_est_handoff), outputTensorData); + handler_p = g_signal_connect (vrsink, "handoff", G_CALLBACK(_pose_est_handoff), NULL); } else { handler_p = g_signal_connect (vrsink, "handoff", G_CALLBACK(_hand_est_handoff), outputTensorData); } @@ -1982,10 +1999,10 @@ int main (int argc, char *argv[]) thValArm = (float)atoi(argv[3])/100.f; thValLeg = (float)atoi(argv[4])/100.f; - poseRoi.point.x = 0; + poseRoi.point.x = 50; poseRoi.point.y = 0; - poseRoi.width = 0; - poseRoi.height = 0; + poseRoi.width = 100; + poseRoi.height = 192; } else { if (argc > 2) { ad.filename2 = g_strdup(argv[2]);