Skip to content

Instantly share code, notes, and snippets.

@seven1240
Created April 12, 2015 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1240/90ea297d5a9dfc570fb2 to your computer and use it in GitHub Desktop.
Save seven1240/90ea297d5a9dfc570fb2 to your computer and use it in GitHub Desktop.
cv diff with scale
diff --git a/src/mod/applications/mod_cv/mod_cv.cpp b/src/mod/applications/mod_cv/mod_cv.cpp
index faee56f..f12ad00 100644
--- a/src/mod/applications/mod_cv/mod_cv.cpp
+++ b/src/mod/applications/mod_cv/mod_cv.cpp
@@ -96,7 +96,7 @@ typedef struct cv_context_s {
struct detect_stats nestDetected;
int detect_event;
int nest_detect_event;
- switch_png_t *png;
+ switch_image_t *png;
struct shape shape[MAX_SHAPES];
int shapeidx;
int x_off;
@@ -121,7 +121,7 @@ static void uninit_context(cv_context_t *context)
}
if (context->png) {
- switch_png_free(&context->png);
+ switch_img_free(&context->png);
}
}
@@ -137,7 +137,8 @@ static void init_context(cv_context_t *context, const char *cascade_name, const
if (nested_cascade_name) {
if (switch_stristr(".png", nested_cascade_name)) {
- switch_png_open(&context->png, nested_cascade_name);
+ // switch_png_open(&context->png, nested_cascade_name);
+ context->png = switch_img_read_png(nested_cascade_name, SWITCH_IMG_FMT_ARGB);
context->x_off = x_off;
context->y_off = y_off;
} else {
@@ -609,11 +610,15 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
if (context->png && context->detect_event && context->shape[0].cx) {
int x = 0, y = 0;
+ switch_image_t *img = NULL;
- x = context->shape[0].cx - (context->png->w / 2) + context->x_off;
- y = context->shape[0].cy - (context->png->h / 2) + context->y_off;
+ x = context->shape[0].cx - (context->png->d_w / 4) + context->x_off;
+ y = context->shape[0].cy - (context->png->d_h / 4) + context->y_off;
- switch_png_patch_img(context->png, frame->img, x, y);
+ switch_img_scale(context->png, &img, context->png->d_w/2, context->png->d_h/2);
+ switch_img_patch(frame->img, img, x, y);
+ switch_img_free(&img);
+ // switch_png_patch_img(context->png, frame->img, x, y);
} else {
libyuv::RGB24ToI420((uint8_t *)context->rawImage->imageData, w * 3,
frame->img->planes[0], frame->img->stride[0],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment