diff --git a/build/darknet/x64/darknet.py b/build/darknet/x64/darknet.py index 9408aabc..10c9a456 100644 --- a/build/darknet/x64/darknet.py +++ b/build/darknet/x64/darknet.py @@ -202,6 +202,10 @@ predict_image = lib.network_predict_image predict_image.argtypes = [c_void_p, IMAGE] predict_image.restype = POINTER(c_float) +predict_image_letterbox = lib.network_predict_image_letterbox +predict_image_letterbox.argtypes = [c_void_p, IMAGE] +predict_image_letterbox.restype = POINTER(c_float) + def array_to_image(arr): import numpy as np # need to return old values to avoid python freeing memory @@ -251,9 +255,12 @@ def detect_image(net, meta, im, thresh=.5, hier_thresh=.5, nms=.45, debug= False pnum = pointer(num) if debug: print("Assigned pnum") predict_image(net, im) + letter_box = 0 + #predict_image_letterbox(net, im) + #letter_box = 1 if debug: print("did prediction") - #dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, 0) # OpenCV - dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, 0) + #dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, letter_box) # OpenCV + dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, letter_box) if debug: print("Got dets") num = pnum[0] if debug: print("got zeroth index of pnum") diff --git a/build/darknet/x64/darknet_python.cmd b/build/darknet/x64/darknet_python.cmd index d64fe364..b2df11d8 100644 --- a/build/darknet/x64/darknet_python.cmd +++ b/build/darknet/x64/darknet_python.cmd @@ -4,7 +4,7 @@ rem C:\Python27\Scripts\pip install scikit-image rem C:\Python27\Scripts\pip install scipy rem C:\Python27\Scripts\pip install opencv-python -C:\Python27\python.exe darknet.py +rem C:\Python27\python.exe darknet.py @@ -14,6 +14,6 @@ rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install sci rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install scipy rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install opencv-python -rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\python.exe darknet.py +C:\Users\Alex\AppData\Local\Programs\Python\Python36\python.exe darknet.py pause \ No newline at end of file diff --git a/darknet.py b/darknet.py index 9408aabc..10c9a456 100644 --- a/darknet.py +++ b/darknet.py @@ -202,6 +202,10 @@ predict_image = lib.network_predict_image predict_image.argtypes = [c_void_p, IMAGE] predict_image.restype = POINTER(c_float) +predict_image_letterbox = lib.network_predict_image_letterbox +predict_image_letterbox.argtypes = [c_void_p, IMAGE] +predict_image_letterbox.restype = POINTER(c_float) + def array_to_image(arr): import numpy as np # need to return old values to avoid python freeing memory @@ -251,9 +255,12 @@ def detect_image(net, meta, im, thresh=.5, hier_thresh=.5, nms=.45, debug= False pnum = pointer(num) if debug: print("Assigned pnum") predict_image(net, im) + letter_box = 0 + #predict_image_letterbox(net, im) + #letter_box = 1 if debug: print("did prediction") - #dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, 0) # OpenCV - dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, 0) + #dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, letter_box) # OpenCV + dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, letter_box) if debug: print("Got dets") num = pnum[0] if debug: print("got zeroth index of pnum") diff --git a/include/darknet.h b/include/darknet.h index 1584a362..232d0732 100644 --- a/include/darknet.h +++ b/include/darknet.h @@ -833,6 +833,7 @@ LIB_API layer* get_network_layer(network* net, int i); LIB_API detection *make_network_boxes(network *net, float thresh, int *num); LIB_API void reset_rnn(network *net); LIB_API float *network_predict_image(network *net, image im); +LIB_API float *network_predict_image_letterbox(network *net, image im); LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, int letter_box, network *existing_net); LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs); LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh, diff --git a/src/network.c b/src/network.c index 0e655c78..e0be3995 100644 --- a/src/network.c +++ b/src/network.c @@ -842,6 +842,24 @@ float *network_predict_image(network *net, image im) return p; } +float *network_predict_image_letterbox(network *net, image im) +{ + //image imr = letterbox_image(im, net->w, net->h); + float *p; + if (net->batch != 1) set_batch_network(net, 1); + if (im.w == net->w && im.h == net->h) { + // Input image is the same size as our net, predict on that image + p = network_predict(*net, im.data); + } + else { + // Need to resize image to the desired size for the net + image imr = letterbox_image(im, net->w, net->h); + p = network_predict(*net, imr.data); + free_image(imr); + } + return p; +} + int network_width(network *net) { return net->w; } int network_height(network *net) { return net->h; }