diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-02-01 13:23:34 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-02-01 15:06:59 +0100 |
commit | 04f2f3d766d6ceb2b5f4120be28cab04816e048b (patch) | |
tree | 12117cd7df8aaa860963702b3da520be908d4f01 | |
parent | c050f52cba0b72fb5759e88b41db8bd700cd9bc3 (diff) | |
download | advtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.tar.gz advtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.tar.bz2 advtime-04f2f3d766d6ceb2b5f4120be28cab04816e048b.zip |
util: Add sobel operator
-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_ */ |