Jan-01-2019, 06:16 PM
I wrote a function with a for loop for my tensorflow object_detection which shows me the detected images' name inside of my test_images when I press buttons as I see them visually with cv2. However, I cannot return b values when I use return at the end of the function. How can we solve such issue in python (How to return values from For Loop via return in a function) ? thank you very much
def detected_objects_2(): for image_path in TEST_IMAGE_PATHS: image = Image.open(image_path) folder_path = "test_images/" #folder path to your images File_Lst = [] for file in os.listdir(folder_path): File_Lst.append(file) dog_index = File_Lst.index('image1.jpg') dog_str = File_Lst[dog_index] img = cv2.imread(folder_path + dog_str ) cv2.destroyAllWindows() cv2.imshow("Press KEYS to know which direction you want to go with your robot", img) image_np = load_image_into_numpy_array(image) image_np_expanded = np.expand_dims(image_np, axis=0) output_dict = run_inference_for_single_image(image_np, detection_graph) a, b = vis_util.visualize_boxes_and_labels_on_image_array( image_np, output_dict['detection_boxes'], output_dict['detection_classes'], output_dict['detection_scores'], category_index, instance_masks=output_dict.get('detection_masks'), use_normalized_coordinates=True, line_thickness=8) plt.figure(figsize=IMAGE_SIZE) cv2.destroyAllWindows() cv2.imshow("Object Detector", image_np) #print(b) #if b == 'turnLeft': #print("Turn Left !!!") #elif b == 'turnRight': #print("Turn Right !!!") #else: #print("NO DETECTION !!!") k = cv2.waitKey(0) if k == ord('a'): # wait for 'a' key to upload traffic signs one by one cv2.destroyAllWindows() cv2.imshow("Object Detector", image_np) elif k == ord('s'): cv2.waitKey(0) cv2.destroyAllWindows() break return b