diff options
-rw-r--r-- | src/util.c | 42 | ||||
-rw-r--r-- | src/util.h | 3 |
2 files changed, 45 insertions, 0 deletions
@@ -136,3 +136,45 @@ print_time(int64_t msec) { printf("%02d:%02d:%02d.%03jd", hh, mm, ss, msec); } + +int +sobel(struct video_frame *frame, unsigned char **d) +{ + unsigned char *data; + unsigned char *p = frame->data; + int x,y; + int Yx, Yy, Y; + + data = malloc(frame->width * frame->height); + if (data == NULL) + return -1; + + for (y = 1; y < frame->height-1; ++y) { + for (x = 1; x < frame->width-1; ++x) { + Yx = (+1 * p[(y-1) * frame->stride + (x-1)] + -1 * p[(y-1) * frame->stride + (x+1)] + +2 * p[(y ) * frame->stride + (x-1)] + -2 * p[(y ) * frame->stride + (x+1)] + +1 * p[(y+1) * frame->stride + (x-1)] + -1 * p[(y+1) * frame->stride + (x+1)]); + Yx = abs(Yx); + + Yy = (+1 * p[(y-1) * frame->stride + (x-1)] + +2 * p[(y-1) * frame->stride + (x )] + +1 * p[(y-1) * frame->stride + (x+1)] + -1 * p[(y+1) * frame->stride + (x-1)] + -2 * p[(y+1) * frame->stride + (x )] + -1 * p[(y+1) * frame->stride + (x+1)]); + Yy = abs(Yy); + + Y = (Yx > Yy ? Yx : Yy) / 4; + if (Y > 255) Y = 255; + + data[y * frame->width + x] = Y; + } + } + + *d = data; + + return 0; +} @@ -32,4 +32,7 @@ frame_average(struct video_frame *frame); void print_time(int64_t msec); +int +sobel(struct video_frame *frame, unsigned char **d); + #endif /* _UTIL_H_ */ |