def run(self): """ Detects objects in image and returns list of objects detected. Measures the amount of time taken to analyze an image (regardless of the accuracy of the detection)""" perception_results = {} # If no checkpoint specified, will assume `accurate` by default. In this case, # we want to use our traffic checkpoint. The Detector can also take a config # object. detector = Detector(self.checkpoint) for full_image_path in self.list_of_images: if os.path.exists(full_image_path): image_path, image_name = os.path.split(full_image_path) image_ext = image_name.split('.')[-1] image = read_image(full_image_path) perception_results.update({image_name: {}}) # Returns a dictionary with the detections. start_time = datetime.datetime.now() objects = detector.predict(image) end_time = datetime.datetime.now() time_to_get_objects = end_time - start_time # print(objects) perception_results[image_name].update({"objects": objects}) perception_results[image_name].update({"detection_time": time_to_get_objects}) if self.to_save_result: self.save_image_and_objects(image, image_name, image_ext, objects) else: print("ERROR: image not found: %s" % full_image_path) del detector return perception_results
def validate_perception(img): d = Detector(checkpoint=checkpoint_name) image = read_image(img) start = datetime.datetime.now() p = d.predict(image) end = datetime.datetime.now() print(p) execution_time = end - start return {execution_time: p}
def generate_landmark_csv(image_directory, filename_csv, detection, model, csv_save_path, img_save_path): filename_labels = pd.read_csv(filename_csv, header=None) df = pd.DataFrame() for i, names in enumerate(filename_labels.iloc[:, 0]): image = read_image(image_directory + names) landmarks = predict_vertebra(image, detection, model) df = df.append([landmarks]) save_landmarks_image(image,landmarks,img_save_path +names) df.to_csv(csv_save_path, index=False, header=False)
def predictor_object( checkpoint, image, save_image=False, ): prediction_objects = Detector(checkpoint=checkpoint).predict( read_image(image)) image_output_path = str(Path.cwd() / 'images_output' / 'output-{date}.png').format(date=date.today()) if save_image: vis_objects( read_image(image), prediction_objects, ).save(image_output_path) return prediction_objects return prediction_objects
def save_image(image_directory, detection, output_path): all_image_boxes = [] for filename in os.listdir(image_directory): if filename.endswith('jpg'): print(filename) image = read_image(image_directory + filename) pred_image, bounding_box = predict_vertebra(image, detection) all_image_boxes.append(bounding_box) cv2.imwrite(output_path + filename, pred_image) all_image_boxes = np.array(all_image_boxes) np.save('boxes.npy', all_image_boxes)
def detect(self, image_path, detector): image = read_image(image_path) #image = read_image('C:\\Users\\Klaymen-Island\\PycharmProjects\\TabExImg\\src\\data\\02_preprocessed_images\\eu-009\\eu-009_1.jpg') # If no checkpoint specified, will assume `accurate` by default. In this case, # we want to use our traffic checkpoint. The Detector can also take a config # object. # Returns a dictionary with the detections. objects = detector.predict(image) vis_objects(image, objects).save('traffic-out.png') return objects
def predict_anchor( image_path="/Users/balajidr/Developer/fyp_final/mainapp/functions/RCNN/testimages/slide-Table.jpg" ): image = read_image(image_path) # If no checkpoint specified, will assume `accurate` by default. In this case, # we want to use our traffic checkpoint. The Detector can also take a config # object. # Returns a dictionary with the detections. objects = detector.predict(image) print(objects) vis_objects(image, objects).save('traffic-out.png') return objects
def test_run_in_bulk_validations_from_file(data_provider, detector): execution_times = [] execution_names = [] for test_image in data_provider: image = read_image(test_image.image_path) print("Testing image: " + test_image.image_path) start_time = datetime.datetime.now() detected_objects = detector.predict(image) recognition_time = (datetime.datetime.now() - start_time).total_seconds() execution_names.append(test_image.image_path) execution_times.append(recognition_time) assert_data_recognized(detected_objects, test_image) plot_data_to_file(execution_names, execution_times)
def read_the_image(image): image_ = read_image(image) return image_
def run(self, save_path): detector = Detector(self.checkpoint) image = read_image(self.image) objects = detector.predict(image) vis_objects(image, objects).save(save_path) return objects
# Python's version used: 3.6.8 64 bit # pip install tensorflow==1.5.0 # pip install luminoth from luminoth import Detector, read_image, vis_objects from PIL import Image import os # Changing the current directory in the one of the .py file try: os.chdir(os.path.dirname(__file__)) except: pass # Reading the .jpg image image = read_image('Pets.jpg') # Creating the detector detector = Detector() # Returning a dictionary with the detections objects = detector.predict(image) print(objects) # Creating a .jpg file with the detections vis_objects(image, objects).save('Pets-out.jpg') # Showing the image image = Image.open('Pets-out.jpg') image.show() # Deleting the image