diff --git a/darknet.py b/darknet.py index 59953bc036f..9ab94fc2bac 100644 --- a/darknet.py +++ b/darknet.py @@ -252,6 +252,7 @@ def detect_image(network, class_names, image, thresh=.5, hier_thresh=.5, nms=.45 predictions = remove_negatives(detections, class_names, num) predictions = decode_detection(predictions) free_detections(detections, num) + free_image(image) return sorted(predictions, key=lambda x: x[1]) diff --git a/darknet_images.py b/darknet_images.py index bfdd88c958a..45a0729c72f 100644 --- a/darknet_images.py +++ b/darknet_images.py @@ -111,7 +111,6 @@ def image_detection(image_or_path, network, class_names, class_colors, thresh): darknet.copy_image_from_bytes(darknet_image, image_resized.tobytes()) detections = darknet.detect_image(network, class_names, darknet_image, thresh=thresh) - darknet.free_image(darknet_image) image = darknet.draw_boxes(detections, image_resized, class_colors) return cv2.cvtColor(image, cv2.COLOR_BGR2RGB), detections diff --git a/darknet_video.py b/darknet_video.py index c6682a24eae..aabe3a8376e 100644 --- a/darknet_video.py +++ b/darknet_video.py @@ -133,7 +133,7 @@ def inference(stop_flag, preprocessed_frame_queue, detections_queue, fps_queue, fps_queue.put(int(fps)) print("FPS: {:.2f}".format(fps)) darknet.print_detections(detections, args.ext_output) - darknet.free_image(darknet_image) + cap.release() def drawing(stop_flag, input_video_fps, queues, preproc_h, preproc_w, vid_h, vid_w):