Ejemplo n.º 1
0
    def save_image_and_objects(self, image, image_name, image_ext, objects):
        """ Saves the image to a folder of results with a unique file name
            timestamp prevents the files from being over-written
            image nameand checkpoint name help understand what processing was done
            to get the results"""

        timestamp = str(datetime.datetime.now()).replace(':', '_').replace(' ', '_')
        image_output_name = image_name.replace("." + image_ext, "_" + self.checkpoint + "_" +
                                               timestamp + "." + image_ext)
        # If directory does not exist create it
        if not os.path.isdir('.\\results'):
            os.mkdir('.\\results', mode=0o777)
        vis_objects(image, objects).save(os.path.join('.\\results', image_output_name))
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
def run_module():
    """Runs Luminoth module to simulate perception outputs.
     Args:
         images: String or list of strings for the paths or directories to
             run predictions in. For directories, will return all the files
             within.
     Returns:
         List of objects detected (bounding box with probabaility and name of object.
     """

    images = [
        cv2.imread(file)
        for file in glob.glob(r'E:\CarTests\*.' + 'IMAGE_FORMATS')
    ]
    detector = Detector(checkpoint='cars')
    # Returns a dictionary with the detections.
    objects = detector.predict(images)
    print(objects)
    vis_objects(images, objects).save(r'E:\CarTests\objects')

    return objects
Ejemplo n.º 6
0
 def visual_objects(image, objects):
     vis_objects(image, objects).save(BaseConfig.IMAGE_OUTPUT)
 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
Ejemplo n.º 8
0
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
file_path = 'Pets-out.jpg'
os.remove(file_path)