From 4cf0ff9a17f9fea2a8c5a86f3c7d1d4f7d8bce7f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 16 Nov 2016 19:15:41 -0600 Subject: [PATCH] FS-9742 --- .../mod_conference/conference_video.c | 71 ++++++++++++++----- .../mod_conference/mod_conference.h | 1 + src/mod/applications/mod_cv/mod_cv.cpp | 27 +++++-- 3 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index 7363cbcfc0..3450c3c00d 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -365,6 +365,33 @@ void conference_video_reset_layer(mcu_layer_t *layer) switch_img_free(&layer->cur_img); } +static void set_pan(mcu_layer_t *layer, int crop_point, int max_width) +{ + if (layer->crop_point <= 0 || layer->crop_point > max_width) { + layer->crop_point = crop_point; + } else if (crop_point > layer->crop_point) { + if (crop_point - layer->crop_point > 25) { + layer->crop_point += 5; + } else { + layer->crop_point++; + } + + if (crop_point < layer->crop_point) { + layer->crop_point = crop_point; + } + } else if (crop_point < layer->crop_point) { + if (layer->crop_point - crop_point > 25) { + layer->crop_point -= 5; + } else { + layer->crop_point--; + } + + if (crop_point > layer->crop_point) { + layer->crop_point = crop_point; + } + } +} + void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, switch_bool_t freeze) { switch_image_t *IMG, *img; @@ -421,7 +448,7 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, if (layer->last_img_addr != img_addr && layer->geometry.zoom) { uint32_t new_w = 0, new_h = 0; - int cropsize = 0; + int crop_point = 0; double scale = 1; if (screen_aspect < img_aspect) { @@ -434,19 +461,23 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, new_h = (uint32_t)((double)layer->screen_h / scale); if (layer->bug_frame.geometry.w) { - cropsize = layer->bug_frame.geometry.x - (new_w / 2); + //new_w = layer->bug_frame.geometry.w * 2; + //new_h = new_w / screen_aspect; + crop_point = switch_round_to_step(layer->bug_frame.geometry.x - (new_w / 2), 25); } else { - cropsize = (img->d_w - new_w) / 2; + crop_point = (img->d_w - new_w) / 2; } - if (cropsize < 1) { - cropsize = 1; - } else if (cropsize > img->d_w - new_w) { - cropsize = img->d_w - new_w; + if (crop_point < 1) { + crop_point = 1; + } else if (crop_point > img->d_w - new_w) { + crop_point = img->d_w - new_w; } - - if (cropsize > 0) { - switch_img_set_rect(img, cropsize, 0, new_w, new_h); + + set_pan(layer, crop_point, img->d_w - new_w); + + if (layer->crop_point > 0) { + switch_img_set_rect(img, layer->crop_point, 0, new_w, new_h); img_aspect = (double) img->d_w / img->d_h; } @@ -460,20 +491,22 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, new_w = (uint32_t)((double)layer->screen_w / scale); new_h = (uint32_t)((double)layer->screen_h / scale); - if (layer->bug_frame.geometry.y) { - cropsize = layer->bug_frame.geometry.y - (new_h / 2); + if (layer->bug_frame.geometry.w) { + crop_point = layer->bug_frame.geometry.y - (new_h / 2); } else { - cropsize = (img->d_h - new_h) / 2; + crop_point = (img->d_h - new_h) / 2; } - if (cropsize < 1) { - cropsize = 1; - } else if (cropsize > img->d_h - new_h) { - cropsize = img->d_h - new_h; + if (crop_point < 1) { + crop_point = 1; + } else if (crop_point > img->d_h - new_h) { + crop_point = img->d_h - new_h; } - if (cropsize > 0) { - switch_img_set_rect(img, 0, cropsize, (unsigned int)(layer->screen_w/scale), (unsigned int)(layer->screen_h/scale)); + set_pan(layer, crop_point, img->d_h - new_h); + + if (crop_point > 0) { + switch_img_set_rect(img, 0, crop_point, (unsigned int)(layer->screen_w/scale), (unsigned int)(layer->screen_h/scale)); img_aspect = (double) img->d_w / img->d_h; } } diff --git a/src/mod/applications/mod_conference/mod_conference.h b/src/mod/applications/mod_conference/mod_conference.h index cb5c044237..8a03a928e3 100644 --- a/src/mod/applications/mod_conference/mod_conference.h +++ b/src/mod/applications/mod_conference/mod_conference.h @@ -446,6 +446,7 @@ typedef struct mcu_layer_s { int refresh; int clear; int is_avatar; + int crop_point; switch_size_t last_img_addr; switch_img_position_t logo_pos; switch_image_t *img; diff --git a/src/mod/applications/mod_cv/mod_cv.cpp b/src/mod/applications/mod_cv/mod_cv.cpp index bf2aab30d4..42b826e9a8 100644 --- a/src/mod/applications/mod_cv/mod_cv.cpp +++ b/src/mod/applications/mod_cv/mod_cv.cpp @@ -693,7 +693,6 @@ void detectAndDraw(cv_context_t *context) switch_mutex_unlock(context->mutex); } - static switch_status_t video_thread_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data) { cv_context_t *context = (cv_context_t *) user_data; @@ -730,10 +729,27 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi switch_img_to_raw(frame->img, context->rawImage->imageData, context->rawImage->widthStep, SWITCH_IMG_FMT_RGB24); detectAndDraw(context); - if (context->detect_event && context->shape_idx && - abs(context->shape[0].cx - context->last_shape[0].cx) > 200 || abs(context->shape[0].w - context->last_shape[0].w) > 200) { - context->detected.simo_count = 0; - context->detected.simo_miss_count = context->confidence_level; + if (context->shape_idx && context->shape[0].w && context->last_shape[0].w) { + int max, min; + int pct; + + if (context->shape[0].w > context->last_shape[0].w) { + max = context->shape[0].w; + min = context->last_shape[0].w; + } else { + max = context->last_shape[0].w; + min = context->shape[0].w; + } + + pct = 100 - (((double)min / (double)max) * 100.0f ); + + if (pct > 25) { + context->detected.simo_count = 0; + memset(context->last_shape, 0, sizeof(context->last_shape[0]) * MAX_SHAPES); + if (context->detect_event) { + context->detected.simo_miss_count = context->confidence_level; + } + } } if (context->detected.simo_count > context->confidence_level) { @@ -772,6 +788,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi memset(context->shape, 0, sizeof(context->shape[0]) * MAX_SHAPES); + memset(context->last_shape, 0, sizeof(context->last_shape[0]) * MAX_SHAPES); switch_channel_execute_on(channel, "execute_on_cv_detect_off_primary"); reset_stats(&context->nestDetected);