From 6b38dcdce07b0c082334e7d9e10fe26bc440a347 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Thu, 08 Sep 2016 05:27:56 +0000
Subject: [PATCH] adding new tiny-yolo

---
 src/image.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/image.c b/src/image.c
index de896f2..21c2f8b 100644
--- a/src/image.c
+++ b/src/image.c
@@ -479,7 +479,8 @@
     return out;
 }
 
-image rotate_crop_image(image im, float rad, float s, int w, int h, int dx, int dy)
+
+image rotate_crop_image(image im, float rad, float s, int w, int h, float dx, float dy, float aspect)
 {
     int x, y, c;
     float cx = im.w/2.;
@@ -488,8 +489,8 @@
     for(c = 0; c < im.c; ++c){
         for(y = 0; y < h; ++y){
             for(x = 0; x < w; ++x){
-                float rx = cos(rad)*(x/s + dx/s -cx) - sin(rad)*(y/s + dy/s -cy) + cx;
-                float ry = sin(rad)*(x/s + dx/s -cx) + cos(rad)*(y/s + dy/s -cy) + cy;
+                float rx = cos(rad)*((x - w/2.)/s*aspect + dx/s*aspect) - sin(rad)*((y - h/2.)/s + dy/s) + cx;
+                float ry = sin(rad)*((x - w/2.)/s*aspect + dx/s*aspect) + cos(rad)*((y - h/2.)/s + dy/s) + cy;
                 float val = bilinear_interpolate(im, rx, ry, c);
                 set_pixel(rot, x, y, c, val);
             }
@@ -642,18 +643,23 @@
     return crop;
 }
 
-image random_augment_image(image im, float angle, int low, int high, int size)
+image random_augment_image(image im, float angle, float aspect, int low, int high, int size)
 {
+    aspect = rand_scale(aspect);
     int r = rand_int(low, high);
-    int min = (im.h < im.w) ? im.h : im.w;
+    int min = (im.h < im.w*aspect) ? im.h : im.w*aspect;
     float scale = (float)r / min;
 
     float rad = rand_uniform(-angle, angle) * TWO_PI / 360.;
-    int dx = rand_int(0, scale * im.w - size);
-    int dy = rand_int(0, scale * im.h - size);
-    //printf("%d %d\n", dx, dy);
 
-    image crop = rotate_crop_image(im, rad, scale, size, size, dx, dy);
+    float dx = (im.w*scale/aspect - size) / 2.;
+    float dy = (im.h*scale - size) / 2.;
+    if(dx < 0) dx = 0;
+    if(dy < 0) dy = 0;
+    dx = rand_uniform(-dx, dx);
+    dy = rand_uniform(-dy, dy);
+
+    image crop = rotate_crop_image(im, rad, scale, size, size, dx, dy, aspect);
 
     return crop;
 }
@@ -971,6 +977,11 @@
     show_image(c4, "C4");
 #ifdef OPENCV
     while(1){
+        image aug = random_augment_image(im, 0, 320, 448, 320, .75);
+        show_image(aug, "aug");
+        free_image(aug);
+        
+
         float exposure = 1.15;
         float saturation = 1.15;
         float hue = .05;

--
Gitblit v1.10.0