def detector(img): ''' ->takes input image from the callback ->YOLOV3 detects the object in the image ->returns the coordinates of the prediction ''' img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.medianBlur( img, 5) # remove noise from the image to reduce false detections pred, img = detect_object(yolo, img, save_img=False) # call the YOLOV3 detector rospy.loginfo('Prediction bounding box coordinates below: ') rospy.loginfo(pred) return pred
def detect(): if request.method == 'POST': file = request.files['file'] basepath = os.path.dirname(__file__) file_path = os.path.join(basepath, 'uploads', file.filename) file.save(file_path) objects = detect_object(file_path) if len(objects) == 0: flash('No objects detected.','primary') else: flash("The predictions are : -",'primary') for x in objects: flash(f"{x[0].capitalize()}, Probability Score - {x[1]:.3f}",'primary') return redirect(url_for('detect')) else: return render_template('object_detect.html')
"score" : FLAGS.score, "gpu_num" : FLAGS.gpu_num, "model_image_size" : (416, 416), } ) # Make a dataframe for the prediction outputs out_df = pd.DataFrame(columns=['image', 'image_path','xmin', 'ymin', 'xmax', 'ymax', 'label','confidence','x_size','y_size']) # labels to draw on images class_file = open(FLAGS.classes_path, 'r') input_labels = [line.rstrip('\n') for line in class_file.readlines()] print('Found {} input labels: {}...'.format(len(input_labels), input_labels)) start = timer() text_out = '' for i, img_path in enumerate(input_image_paths): print(img_path) prediction, image = detect_object(yolo, img_path, save_img = save_img, save_img_path = FLAGS.output, postfix=FLAGS.postfix) y_size,x_size,_ = np.array(image).shape for single_prediction in prediction: out_df=out_df.append(pd.DataFrame([[os.path.basename(img_path.rstrip('\n')),img_path.rstrip('\n')]+single_prediction + [x_size,y_size]],columns=['image','image_path', 'xmin', 'ymin', 'xmax', 'ymax', 'label','confidence','x_size','y_size'])) end = timer() print('Processed {} images in {:.1f}sec - {:.1f}FPS'.format( len(input_image_paths), end-start, len(input_image_paths)/(end-start) )) out_df.to_csv(FLAGS.box,index=False)
len(input_image_paths), [os.path.basename(f) for f in input_image_paths[:5]], ) ) start = timer() text_out = "" # This code is for images counter = 0 for i, img_path in enumerate(input_image_paths): print(img_path) prediction, image, count = detect_object( yolo, img_path, counter, save_img=save_img, save_img_path=FLAGS.output, postfix=FLAGS.postfix, ) counter = count # display an predicted image #prediction = np.asarray(prediction) #cv2.imshow("result", prediction) #cv2.imshow("actual", np.array(image)) y_size, x_size, _ = np.array(image).shape for single_prediction in prediction: out_df = out_df.append( pd.DataFrame( [ [
def predict_input_dir(yolo, classes_path, no_save_img, postfix, box, input_dir, output_dir): """Detect faces in input_dir. Args: classes_path: parsed args from commandline no_save_img: parsed args from commandline postfix: parsed args from commandline box: parsed args from commandline input_dir: input directory with images for detecting faces output_dir: output directory for saving images yolo: initialized yolo model for faster inferring """ # get images paths from input directory input_paths = GetFileList(input_dir) # Split images img_endings = (".jpg", ".jpeg", ".png") input_image_paths = [] for item in input_paths: if item.endswith(img_endings): input_image_paths.append(item) if not os.path.exists(output_dir): os.makedirs(output_dir) save_img = not no_save_img # whether to save detected images # Make a dataframe for the prediction outputs out_df = pd.DataFrame(columns=[ "image", "image_path", "xmin", "ymin", "xmax", "ymax", "label", "confidence", "x_size", "y_size", ]) # labels to draw on check class_file = open(classes_path, "r") input_labels = [line.rstrip("\n") for line in class_file.readlines()] print("Found {} input labels: {} ...".format(len(input_labels), input_labels)) if input_image_paths: print("Found {} input images: {} ...".format( len(input_image_paths), [os.path.basename(f) for f in input_image_paths[:5]], )) start = timer() # predict every images for i, img_path in enumerate(input_image_paths): print(img_path) prediction, image = detect_object( yolo, img_path, save_img=save_img, save_img_path=output_dir, postfix=postfix, ) y_size, x_size, _ = np.array(image).shape for single_prediction in prediction: out_df = out_df.append( pd.DataFrame( [[ os.path.basename(img_path.rstrip("\n")), img_path.rstrip("\n"), ] + single_prediction + [x_size, y_size]], columns=[ "image", "image_path", "xmin", "ymin", "xmax", "ymax", "label", "confidence", "x_size", "y_size", ], )) end = timer() print("Processed {} images in {:.1f}sec - {:.1f}FPS".format( len(input_image_paths), end - start, len(input_image_paths) / (end - start), )) out_df.to_csv(output_dir + '/Detection_Results.csv', index=False)
from tqdm import * x = 1 while x < 300: out_df = pd.DataFrame() image = pyautogui.screenshot(region=(500, 500, 800, 450)) image.save('pic/' + time.strftime('%Y-%m-%d-%H-%M', time.localtime(time.time())) + '.png') img_path = ('pic/' + time.strftime('%Y-%m-%d-%H-%M', time.localtime(time.time())) + '.png') prediction, image = detect_object( yolo, img_path, save_img=time.strftime('%Y-%m-%d-%H-%M', time.localtime(time.time())) + 'test.png', save_img_path='/TrainYourOwnYOLO/Data/Source_Images/Test_Images/', postfix="monkeys", ) y_size, x_size, _ = np.array(image).shape for single_prediction in prediction: out_df = out_df.append( pd.DataFrame( [[ os.path.basename(img_path.rstrip("\n")), img_path.rstrip("\n"), ] + single_prediction + [x_size, y_size]], columns=[ "image", "image_path", "xmin",
if input_image_paths: print("Found {} input images: {} ...".format( len(input_image_paths), [os.path.basename(f) for f in input_image_paths[:5]], )) start = timer() text_out = "" # This is for images for i, img_path in enumerate(input_image_paths): print(img_path) prediction, image = detect_object( yolo, img_path, save_img=save_img, save_img_path="", postfix="", ) y_size, x_size, _ = np.array(image).shape for single_prediction in prediction: out_df = out_df.append( pd.DataFrame( [[ os.path.basename(img_path.rstrip("\n")), img_path.rstrip("\n"), ] + single_prediction + [x_size, y_size]], columns=[ "image", "image_path", "xmin",