Joseph Redmon
2016-02-29 16d06ec0db241261d0d030722e440206ed8aad77
src/image.c
@@ -4,11 +4,6 @@
#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
@@ -330,6 +325,16 @@
}
#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);
@@ -459,6 +464,39 @@
    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) ;
@@ -788,8 +826,12 @@
    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);