From 1276f9f494d64254eb3778987df4e68533f556a8 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Fri, 6 Sep 2019 09:44:19 +0200 Subject: [PATCH] per_xxx_function accept bool value to indicate abort #330 --- imageai/Detection/Custom/__init__.py | 28 ++++++++------ imageai/Detection/__init__.py | 56 +++++++++++++++++----------- 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/imageai/Detection/Custom/__init__.py b/imageai/Detection/Custom/__init__.py index 6768fd7d..7b86a11c 100644 --- a/imageai/Detection/Custom/__init__.py +++ b/imageai/Detection/Custom/__init__.py @@ -1095,10 +1095,12 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f if (counting == 1 or check_frame_interval == 0): if (per_frame_function != None): if (return_detected_frame == True): - per_frame_function(counting, output_objects_array, output_objects_count, - detected_frame) + if(per_frame_function(counting, output_objects_array, output_objects_count, + detected_frame)): + break elif (return_detected_frame == False): - per_frame_function(counting, output_objects_array, output_objects_count) + if(per_frame_function(counting, output_objects_array, output_objects_count)): + break if (per_second_function != None): if (counting != 1 and (counting % frames_per_second) == 0): @@ -1125,14 +1127,16 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f eachCountingItem] / frames_per_second if (return_detected_frame == True): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting, detected_frame) + this_second_counting, detected_frame)): + break elif (return_detected_frame == False): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting) + this_second_counting)): + break if (per_minute_function != None): @@ -1161,14 +1165,16 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f frames_per_second * 60) if (return_detected_frame == True): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting, detected_frame) + this_minute_counting, detected_frame)): + break elif (return_detected_frame == False): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting) + this_minute_counting)): + break else: diff --git a/imageai/Detection/__init__.py b/imageai/Detection/__init__.py index b7a9a3d2..76e8de5e 100644 --- a/imageai/Detection/__init__.py +++ b/imageai/Detection/__init__.py @@ -1227,10 +1227,12 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f if (counting == 1 or check_frame_interval == 0): if (per_frame_function != None): if (return_detected_frame == True): - per_frame_function(counting, output_objects_array, output_objects_count, - detected_copy) + if(per_frame_function(counting, output_objects_array, output_objects_count, + detected_copy)): + break elif (return_detected_frame == False): - per_frame_function(counting, output_objects_array, output_objects_count) + if(per_frame_function(counting, output_objects_array, output_objects_count)): + break if (per_second_function != None): if (counting != 1 and (counting % frames_per_second) == 0): @@ -1257,14 +1259,16 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f eachCountingItem] / frames_per_second if (return_detected_frame == True): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting, detected_copy) + this_second_counting, detected_copy)): + break elif (return_detected_frame == False): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting) + this_second_counting)): + break if (per_minute_function != None): @@ -1293,14 +1297,16 @@ def detectObjectsFromVideo(self, input_file_path="", camera_input=None, output_f frames_per_second * 60) if (return_detected_frame == True): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting, detected_copy) + this_minute_counting, detected_copy)): + break elif (return_detected_frame == False): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting) + this_minute_counting)): + break else: @@ -1610,10 +1616,12 @@ def detectCustomObjectsFromVideo(self, custom_objects=None, input_file_path="", if (counting == 1 or check_frame_interval == 0): if (per_frame_function != None): if (return_detected_frame == True): - per_frame_function(counting, output_objects_array, output_objects_count, - detected_copy) + if(per_frame_function(counting, output_objects_array, output_objects_count, + detected_copy)): + break elif (return_detected_frame == False): - per_frame_function(counting, output_objects_array, output_objects_count) + if(per_frame_function(counting, output_objects_array, output_objects_count)): + break if (per_second_function != None): if (counting != 1 and (counting % frames_per_second) == 0): @@ -1640,14 +1648,16 @@ def detectCustomObjectsFromVideo(self, custom_objects=None, input_file_path="", eachCountingItem] / frames_per_second if (return_detected_frame == True): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting, detected_copy) + this_second_counting, detected_copy)): + break elif (return_detected_frame == False): - per_second_function(int(counting / frames_per_second), + if(per_second_function(int(counting / frames_per_second), this_second_output_object_array, this_second_counting_array, - this_second_counting) + this_second_counting)): + break if (per_minute_function != None): @@ -1676,14 +1686,16 @@ def detectCustomObjectsFromVideo(self, custom_objects=None, input_file_path="", frames_per_second * 60) if (return_detected_frame == True): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting, detected_copy) + this_minute_counting, detected_copy)): + break elif (return_detected_frame == False): - per_minute_function(int(counting / (frames_per_second * 60)), + if(per_minute_function(int(counting / (frames_per_second * 60)), this_minute_output_object_array, this_minute_counting_array, - this_minute_counting) + this_minute_counting)): + break else: