From 76c7490265074fc14d5e60f34b5c20e1d2a221cd Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Wed, 25 Jan 2023 14:09:50 -0600 Subject: [PATCH 01/11] removed dependency to show image --- TFLite_detection_webcam.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 78cc5d33..1c0ac594 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -15,6 +15,7 @@ # Import packages import os +import uuid import argparse import cv2 import numpy as np @@ -79,10 +80,16 @@ def stop(self): default='1280x720') parser.add_argument('--edgetpu', help='Use Coral Edge TPU Accelerator to speed up detection', action='store_true') +parser.add_argument('--noshow_results', help='Don\'t show result images (only use this if --save_results is enabled)', + action='store_false') +parser.add_argument('--save_results', help='Save labeled images and annotation data to a results folder', + action='store_true') args = parser.parse_args() MODEL_NAME = args.modeldir +show_results = args.noshow_results # Defaults to True +save_results = args.save_results # Defaults to False GRAPH_NAME = args.graph LABELMAP_NAME = args.labels min_conf_threshold = float(args.threshold) @@ -220,17 +227,38 @@ def stop(self): cv2.putText(frame,'FPS: {0:.2f}'.format(frame_rate_calc),(30,50),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,0),2,cv2.LINE_AA) # All the results have been drawn on the frame, so it's time to display it. - cv2.imshow('Object detector', frame) + if show_results: + cv2.imshow('Object detector', frame) + # Press 'q' to quit + if cv2.waitKey(1) == ord('q'): + break + + # Save the labeled image to results folder if desired + if save_results: + + # Get filenames and paths + fake_file_name = uuid.uuid4() + image_fn = os.path.basename("./results/"+fake_file_name+".jpg") + image_savepath = os.path.join(CWD_PATH,"results",image_fn) + + base_fn, ext = os.path.splitext(image_fn) + txt_result_fn = base_fn +'.txt' + txt_savepath = os.path.join(CWD_PATH,"results",txt_result_fn) + + # Save image + cv2.imwrite(image_savepath, frame) + + # Write results to text file + # (Using format defined by https://github.com/Cartucho/mAP, which will make it easy to calculate mAP) + with open(txt_savepath,'w') as f: + for detection in detections: + f.write('%s %.4f %d %d %d %d\n' % (detection[0], detection[1], detection[2], detection[3], detection[4], detection[5])) # Calculate framerate t2 = cv2.getTickCount() time1 = (t2-t1)/freq frame_rate_calc= 1/time1 - # Press 'q' to quit - if cv2.waitKey(1) == ord('q'): - break - # Clean up cv2.destroyAllWindows() videostream.stop() From 6d0bd8b7612dd947195e8603b7c629bc56246c9a Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Wed, 25 Jan 2023 15:53:03 -0600 Subject: [PATCH 02/11] string issue --- TFLite_detection_webcam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 1c0ac594..74748ae0 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -237,7 +237,7 @@ def stop(self): if save_results: # Get filenames and paths - fake_file_name = uuid.uuid4() + fake_file_name = f'{uuid.uuid4()}' image_fn = os.path.basename("./results/"+fake_file_name+".jpg") image_savepath = os.path.join(CWD_PATH,"results",image_fn) From 6b8dafd6fa635a11fb46578b48adfd3367d39afc Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Wed, 25 Jan 2023 15:56:34 -0600 Subject: [PATCH 03/11] adding detections array --- TFLite_detection_webcam.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 74748ae0..a31d9faf 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -203,6 +203,7 @@ def stop(self): scores = interpreter.get_tensor(output_details[scores_idx]['index'])[0] # Confidence of detected objects # Loop over all detections and draw detection box if confidence is above minimum threshold + detections = [] for i in range(len(scores)): if ((scores[i] > min_conf_threshold) and (scores[i] <= 1.0)): @@ -222,6 +223,7 @@ def stop(self): label_ymin = max(ymin, labelSize[1] + 10) # Make sure not to draw label too close to top of window cv2.rectangle(frame, (xmin, label_ymin-labelSize[1]-10), (xmin+labelSize[0], label_ymin+baseLine-10), (255, 255, 255), cv2.FILLED) # Draw white box to put label text in cv2.putText(frame, label, (xmin, label_ymin-7), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 0), 2) # Draw label text + detections.append([object_name, scores[i], xmin, ymin, xmax, ymax]) # Draw framerate in corner of frame cv2.putText(frame,'FPS: {0:.2f}'.format(frame_rate_calc),(30,50),cv2.FONT_HERSHEY_SIMPLEX,1,(255,255,0),2,cv2.LINE_AA) From 9f1069e7bfe35b550f3b037234d7c6e65dd78788 Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Wed, 25 Jan 2023 16:23:57 -0600 Subject: [PATCH 04/11] modified readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index cf4fb032..ca366535 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +### CHANGES of this repo +This repo contains a modification for the detection_webcam file. +In essence it let's you run the python script on a headless raspberry, to avoid issues with the desktop libs and dependencies + # TensorFlow Lite Object Detection on Android and Raspberry Pi Train your own TensorFlow Lite object detection models and run them on the Raspberry Pi, Android phones, and other edge devices! From d105e33a2e31ae30b9087587e3cf39b559bda663 Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Sun, 29 Jan 2023 09:43:53 -0600 Subject: [PATCH 05/11] added minum detections --- TFLite_detection_webcam.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index a31d9faf..72903544 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -237,24 +237,24 @@ def stop(self): # Save the labeled image to results folder if desired if save_results: - - # Get filenames and paths - fake_file_name = f'{uuid.uuid4()}' - image_fn = os.path.basename("./results/"+fake_file_name+".jpg") - image_savepath = os.path.join(CWD_PATH,"results",image_fn) - - base_fn, ext = os.path.splitext(image_fn) - txt_result_fn = base_fn +'.txt' - txt_savepath = os.path.join(CWD_PATH,"results",txt_result_fn) - - # Save image - cv2.imwrite(image_savepath, frame) - - # Write results to text file - # (Using format defined by https://github.com/Cartucho/mAP, which will make it easy to calculate mAP) - with open(txt_savepath,'w') as f: - for detection in detections: - f.write('%s %.4f %d %d %d %d\n' % (detection[0], detection[1], detection[2], detection[3], detection[4], detection[5])) + if len(detections) > 0: + # Get filenames and paths + fake_file_name = f'{uuid.uuid4()}' + image_fn = os.path.basename("./results/"+fake_file_name+".jpg") + image_savepath = os.path.join(CWD_PATH,"results",image_fn) + + base_fn, ext = os.path.splitext(image_fn) + txt_result_fn = base_fn +'.txt' + txt_savepath = os.path.join(CWD_PATH,"results",txt_result_fn) + + # Save image + cv2.imwrite(image_savepath, frame) + + # Write results to text file + # (Using format defined by https://github.com/Cartucho/mAP, which will make it easy to calculate mAP) + with open(txt_savepath,'w') as f: + for detection in detections: + f.write('%s %.4f %d %d %d %d\n' % (detection[0], detection[1], detection[2], detection[3], detection[4], detection[5])) # Calculate framerate t2 = cv2.getTickCount() From 57f05a192ac467749f18331b96873c5bcd59d5a3 Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Sun, 29 Jan 2023 12:16:20 -0600 Subject: [PATCH 06/11] added avoid some objects from the sky --- TFLite_detection_webcam.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 72903544..31af98db 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -238,6 +238,9 @@ def stop(self): # Save the labeled image to results folder if desired if save_results: if len(detections) > 0: + for detection in detections: + if detection[0] == "boat" or detection[0] == "airplane" + break # Get filenames and paths fake_file_name = f'{uuid.uuid4()}' image_fn = os.path.basename("./results/"+fake_file_name+".jpg") From 9547272abce8c97f356643cdf9ee9b21fc7bc135 Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Sun, 29 Jan 2023 12:20:10 -0600 Subject: [PATCH 07/11] added avoid some objects from the sky --- TFLite_detection_webcam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 31af98db..49ebad44 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -239,7 +239,7 @@ def stop(self): if save_results: if len(detections) > 0: for detection in detections: - if detection[0] == "boat" or detection[0] == "airplane" + if detection[0] == "boat" or detection[0] == "airplane": break # Get filenames and paths fake_file_name = f'{uuid.uuid4()}' From 602c44ef3f1e16780b9e88c6ac48098b35fad26d Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Sun, 29 Jan 2023 12:26:11 -0600 Subject: [PATCH 08/11] added avoid some objects from the sky --- TFLite_detection_webcam.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index 49ebad44..e15f46f3 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -239,25 +239,24 @@ def stop(self): if save_results: if len(detections) > 0: for detection in detections: - if detection[0] == "boat" or detection[0] == "airplane": - break - # Get filenames and paths - fake_file_name = f'{uuid.uuid4()}' - image_fn = os.path.basename("./results/"+fake_file_name+".jpg") - image_savepath = os.path.join(CWD_PATH,"results",image_fn) - - base_fn, ext = os.path.splitext(image_fn) - txt_result_fn = base_fn +'.txt' - txt_savepath = os.path.join(CWD_PATH,"results",txt_result_fn) - - # Save image - cv2.imwrite(image_savepath, frame) - - # Write results to text file - # (Using format defined by https://github.com/Cartucho/mAP, which will make it easy to calculate mAP) - with open(txt_savepath,'w') as f: - for detection in detections: - f.write('%s %.4f %d %d %d %d\n' % (detection[0], detection[1], detection[2], detection[3], detection[4], detection[5])) + if detection[0] != 'boat' and detection[0] != 'airplane': + # Get filenames and paths + fake_file_name = f'{uuid.uuid4()}' + image_fn = os.path.basename("./results/"+fake_file_name+".jpg") + image_savepath = os.path.join(CWD_PATH,"results",image_fn) + + base_fn, ext = os.path.splitext(image_fn) + txt_result_fn = base_fn +'.txt' + txt_savepath = os.path.join(CWD_PATH,"results",txt_result_fn) + + # Save image + cv2.imwrite(image_savepath, frame) + + # Write results to text file + # (Using format defined by https://github.com/Cartucho/mAP, which will make it easy to calculate mAP) + with open(txt_savepath,'w') as f: + for detection in detections: + f.write('%s %.4f %d %d %d %d\n' % (detection[0], detection[1], detection[2], detection[3], detection[4], detection[5])) # Calculate framerate t2 = cv2.getTickCount() From cdcc0496ee1d0cf0570d41b47bbccb12e77dcdee Mon Sep 17 00:00:00 2001 From: Andres Santos Date: Sat, 4 Feb 2023 20:05:32 -0600 Subject: [PATCH 09/11] Added only bird detection --- TFLite_detection_webcam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TFLite_detection_webcam.py b/TFLite_detection_webcam.py index e15f46f3..66a4281d 100644 --- a/TFLite_detection_webcam.py +++ b/TFLite_detection_webcam.py @@ -239,7 +239,7 @@ def stop(self): if save_results: if len(detections) > 0: for detection in detections: - if detection[0] != 'boat' and detection[0] != 'airplane': + if detection[0] == 'bird': # Get filenames and paths fake_file_name = f'{uuid.uuid4()}' image_fn = os.path.basename("./results/"+fake_file_name+".jpg") From 39cb4bb85cc572a2a6319da473308d6856b5032b Mon Sep 17 00:00:00 2001 From: beckmx Date: Mon, 28 Oct 2024 14:18:43 -0600 Subject: [PATCH 10/11] added --- some.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 some.txt diff --git a/some.txt b/some.txt new file mode 100644 index 00000000..e69de29b From 32bb898a9020f4384a98721c970e388eaad4a537 Mon Sep 17 00:00:00 2001 From: beckmx Date: Mon, 28 Oct 2024 14:21:16 -0600 Subject: [PATCH 11/11] cambios --- some.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/some.txt b/some.txt index e69de29b..59027d32 100644 --- a/some.txt +++ b/some.txt @@ -0,0 +1 @@ +dfdfd \ No newline at end of file