| | |
| | | #include <stdio.h> |
| | | #include <math.h> |
| | | |
| | | #ifdef OPENCV |
| | | #include "opencv2/highgui/highgui_c.h" |
| | | #include "opencv2/imgproc/imgproc_c.h" |
| | | #endif |
| | | |
| | | #define STB_IMAGE_IMPLEMENTATION |
| | | #include "stb_image.h" |
| | | #define STB_IMAGE_WRITE_IMPLEMENTATION |
| | |
| | | } |
| | | |
| | | #ifdef OPENCV |
| | | image get_image_from_stream(CvCapture *cap) |
| | | { |
| | | IplImage* src = cvQueryFrame(cap); |
| | | image im = ipl_to_image(src); |
| | | rgbgr_image(im); |
| | | return im; |
| | | } |
| | | #endif |
| | | |
| | | #ifdef OPENCV |
| | | void save_image_jpg(image p, char *name) |
| | | { |
| | | image copy = copy_image(p); |
| | |
| | | return out; |
| | | } |
| | | |
| | | image make_random_image(int w, int h, int c) |
| | | { |
| | | image out = make_empty_image(w,h,c); |
| | | out.data = calloc(h*w*c, sizeof(float)); |
| | | int i; |
| | | for(i = 0; i < w*h*c; ++i){ |
| | | out.data[i] = (rand_normal() * .25) + .5; |
| | | } |
| | | return out; |
| | | } |
| | | |
| | | image float_to_image(int w, int h, int c, float *data) |
| | | { |
| | | image out = make_empty_image(w,h,c); |
| | |
| | | return cropped; |
| | | } |
| | | |
| | | image resize_min(image im, int min) |
| | | { |
| | | int w = im.w; |
| | | int h = im.h; |
| | | if(w < h){ |
| | | h = (h * min) / w; |
| | | w = min; |
| | | } else { |
| | | w = (w * min) / h; |
| | | h = min; |
| | | } |
| | | image resized = resize_image(im, w, h); |
| | | return resized; |
| | | } |
| | | |
| | | image random_crop_image(image im, int low, int high, int size) |
| | | { |
| | | int r = rand_int(low, high); |
| | | image resized = resize_min(im, r); |
| | | int dx = rand_int(0, resized.w - size); |
| | | int dy = rand_int(0, resized.h - size); |
| | | image crop = crop_image(resized, dx, dy, size, size); |
| | | |
| | | /* |
| | | show_image(im, "orig"); |
| | | show_image(crop, "cropped"); |
| | | cvWaitKey(0); |
| | | */ |
| | | |
| | | free_image(resized); |
| | | return crop; |
| | | } |
| | | |
| | | float three_way_max(float a, float b, float c) |
| | | { |
| | | return (a > b) ? ( (a > c) ? a : c) : ( (b > c) ? b : c) ; |
| | |
| | | return resized; |
| | | } |
| | | |
| | | #include "cuda.h" |
| | | |
| | | void test_resize(char *filename) |
| | | { |
| | | image im = load_image(filename, 0,0, 3); |
| | | float mag = mag_array(im.data, im.w*im.h*im.c); |
| | | printf("L2 Norm: %f\n", mag); |
| | | image gray = grayscale_image(im); |
| | | |
| | | image sat2 = copy_image(im); |
| | |
| | | image exp5 = copy_image(im); |
| | | exposure_image(exp5, .5); |
| | | |
| | | image r = resize_image(im, im.w/2, im.h/2); |
| | | #ifdef GPU |
| | | image r = resize_image(im, im.w, im.h); |
| | | image black = make_image(im.w*2 + 3, im.h*2 + 3, 9); |
| | | image black2 = make_image(im.w, im.h, 3); |
| | | |
| | | image black = make_image(im.w, im.h, im.c); |
| | | shortcut_cpu(black.data, im.w, im.h, im.c, 1, 2, r.data, 1, r.c); |
| | | float *r_gpu = cuda_make_array(r.data, r.w*r.h*r.c); |
| | | float *black_gpu = cuda_make_array(black.data, black.w*black.h*black.c); |
| | | float *black2_gpu = cuda_make_array(black2.data, black2.w*black2.h*black2.c); |
| | | shortcut_gpu(3, r.w, r.h, 1, r_gpu, black.w, black.h, 3, black_gpu); |
| | | //flip_image(r); |
| | | //shortcut_gpu(3, r.w, r.h, 1, r.data, black.w, black.h, 3, black.data); |
| | | |
| | | shortcut_gpu(3, black.w, black.h, 3, black_gpu, black2.w, black2.h, 1, black2_gpu); |
| | | cuda_pull_array(black_gpu, black.data, black.w*black.h*black.c); |
| | | cuda_pull_array(black2_gpu, black2.data, black2.w*black2.h*black2.c); |
| | | show_image_layers(black, "Black"); |
| | | show_image(black2, "Recreate"); |
| | | #endif |
| | | |
| | | show_image(im, "Original"); |
| | | show_image(gray, "Gray"); |
| | | show_image(black, "Black"); |
| | | show_image(sat2, "Saturation-2"); |
| | | show_image(sat5, "Saturation-.5"); |
| | | show_image(exp2, "Exposure-2"); |
| | |
| | | |
| | | if( (src = cvLoadImage(filename, flag)) == 0 ) |
| | | { |
| | | printf("Cannot load image \"%s\"\n", filename); |
| | | exit(0); |
| | | fprintf(stderr, "Cannot load image \"%s\"\n", filename); |
| | | char buff[256]; |
| | | sprintf(buff, "echo %s >> bad.list", filename); |
| | | system(buff); |
| | | return make_image(10,10,3); |
| | | //exit(0); |
| | | } |
| | | image out = ipl_to_image(src); |
| | | cvReleaseImage(&src); |