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;
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) {
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;
}
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;
}
}
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;
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) {
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);