Пример #1
0
def targetSet1(longitude, latitude):
    
    targets = []
    for i in range(10):
        targets.append(
            AUVSIcv.TrapezoidTarget(
                size=1,
                orientation=30*i,
                altitude=0,
                longitude=longitude+0.00002*i,
                latitude=latitude+0.00003*i, 
                color=(70, 150, 100), 
                letter='d', 
                font_color=(140, 230, 240)
            )
        )
        
    
    targets.append(
        AUVSIcv.QRTarget(
            size=1,
            orientation=20,
            altitude=0,
            longitude=longitude,
            latitude=latitude,
            text='www.google.com'
        )
    )
    
    return targets
Пример #2
0
def main():

    base_path = os.environ['AUVSI_CV_DATA']
    imgs_paths = glob.glob(os.path.join(base_path, '*.jpg'))

    img = AUVSIcv.Image(imgs_paths[3])
    data_path = os.path.splitext(imgs_paths[3])[0] + '.txt'
    with open(data_path, 'r') as f:
        data = json.load(f)

    img.calculateExtrinsicMatrix(
        latitude=data['latitude'],
        longitude=data['longitude'],
        altitude=data['altitude'],
        yaw=data['yaw'],
        pitch=data['pitch'],
        roll=data['roll'],
    )

    for i in range(10):
        target = AUVSIcv.StarTarget(n=5 + int(i / 3),
                                    size=2,
                                    orientation=30 * i,
                                    altitude=0,
                                    longitude=32.8167 + 0.00003 * i,
                                    latitude=34.9833 + 0.00003 * i,
                                    color=(70, 150, 100),
                                    letter='A',
                                    font_color=(140, 230, 240))

        img.paste(target)

    target = AUVSIcv.QRTarget(size=2,
                              orientation=20,
                              altitude=0,
                              longitude=32.8167,
                              latitude=34.9833,
                              text='www.google.com')

    img.paste(target)

    cv2.namedWindow('image', flags=cv2.WINDOW_NORMAL)
    cv2.imshow('image', img.img)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
Пример #3
0
def main():

    base_path = os.environ['AUVSI_CV_DATA']
    imgs_paths = glob.glob(os.path.join(base_path, '*.jpg'))

    img = AUVSIcv.Image(imgs_paths[3])

    #
    # Load image data
    #
    data_path = os.path.splitext(imgs_paths[3])[0] + '.txt'
    with open(data_path, 'r') as f:
        data = json.load(f)

    img.calculateExtrinsicMatrix(
        latitude=data['latitude'],
        longitude=data['longitude'],
        altitude=data['altitude'],
        yaw=data['yaw'],
        pitch=data['pitch'],
        roll=data['roll'],
    )

    target = AUVSIcv.PolygonTarget(n=5,
                                   size=2,
                                   orientation=30,
                                   altitude=0,
                                   longitude=32.8167,
                                   latitude=34.9833,
                                   color=(70, 150, 100),
                                   letter='A',
                                   font_color=(140, 230, 240))

    patches = img.createPatches(patch_size=(200, 200), patch_shift=50)

    samples = []
    for patch in patches:
        img.pastePatch(patch=patch, target=target)

        patch = cv2.resize(patch, (0, 0), fx=0.15, fy=0.15)
        samples.append(patch.ravel())

    samples = np.array(samples)

    pass
Пример #4
0
def targetSet2(longitude, latitude):
    
    targets = []
    for i in range(40):
        targets.append(
            AUVSIcv.randomTarget(
                longitude=longitude,
                latitude=latitude,
                altitude=0
            )[0]
        )
        
    return targets
Пример #5
0
def main():

    base_path = os.environ['AUVSI_CV_DATA']
    imgs_paths = glob.glob(os.path.join(base_path, '*.jpg'))

    #
    # Load image and image data
    #
    img = AUVSIcv.Image(imgs_paths[3])
    data_path = os.path.splitext(imgs_paths[3])[0] + '.txt'
    with open(data_path, 'r') as f:
        data = json.load(f)

    img.calculateExtrinsicMatrix(
        latitude=data['latitude'],
        longitude=data['longitude'],
        altitude=data['altitude'],
        yaw=data['yaw'],
        pitch=data['pitch'],
        roll=data['roll'],
    )

    for i in range(10):
        target = AUVSIcv.randomTarget(altitude=0,
                                      longitude=32.8167,
                                      latitude=34.9833)

        img.paste(target)

    cv2.namedWindow('image', flags=cv2.WINDOW_NORMAL)
    resized_img = cv2.resize(img.img, (0, 0), fx=0.25, fy=0.25)

    cv2.imshow('image', resized_img)
    cv2.imwrite('image_with_targets.jpg', img.img)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
Пример #6
0
def main():

    base_path = os.environ['AUVSI_CV_DATA']
    imgs_paths = sorted(glob.glob(os.path.join(base_path, 'renamed_images', '*.jpg')))
    data_paths = sorted(glob.glob(os.path.join(base_path, 'flight_data', '*.json')))

    for i, targetSet in enumerate((targetSet1, targetSet2)):
        img = AUVSIcv.Image(imgs_paths[IMG_INDEX], data_paths[IMG_INDEX], K=AUVSIcv.global_settings.K)

        for target in targetSet(img._longitude, img._latitude):        
            img.paste(target)
        
        cv2.namedWindow('image%d'%i, flags=cv2.WINDOW_NORMAL)
        cv2.imshow('image%d'%i, img.img)
        
    cv2.waitKey(0)
        
    cv2.destroyAllWindows()
Пример #7
0
def processImg(img_path, timestamp):
    """
    Do all image processing actions. Should be called on a separate process to allow mutli processesors.
    Currently does only resizing.
    """

    #
    # give the image some time to finish creation
    #
    time.sleep(1)

    #
    # Load the image
    #
    log.msg('Loading new image {img}'.format(img=img_path))
    img = AUVSIcv.Image(img_path, timestamp=timestamp)

    #
    # Rename it with time stamp.
    #
    new_img_path = os.path.join(gs.RENAMED_IMAGES_FOLDER,
                                img.datetime + '.jpg')

    log.msg('Renaming {old} to {new}'.format(old=img_path, new=new_img_path))
    os.rename(img_path, new_img_path)

    #
    # Resize the image.
    #
    log.msg('Resizing new image {img}'.format(img=new_img_path))

    resized_img = cv2.resize(img.img, (0, 0), fx=0.25, fy=0.25)
    filename = 'resized_{path}'.format(path=os.path.split(new_img_path)[1])

    resized_img_path = os.path.join(gs.RESIZED_IMAGES_FOLDER, filename)
    cv2.imwrite(resized_img_path, resized_img)

    return resized_img_path, img.datetime, img.K
Пример #8
0
    def addImage(self,
                 img_path,
                 data_path,
                 img_path_full_size=None,
                 toRedraw=True):
        """Add an image to the map"""

        img = AUVSIcv.Image(img_path,
                            data_path,
                            img_path_full_size=img_path_full_size,
                            K=AUVSIcv.global_settings.map_K)

        #
        # Filter image based on roll of plane
        # TODO:
        # See if this is still necessary with the new Gimbal.
        #
        if abs(img.plane['roll']) < 15. / 180 * pi and abs(
                img.plane['roll']) < 15. / 180 * pi and (img.stitching_pic_OK
                                                         == 1):
            log.msg("Adding image, roll: {}".format(img._roll))
            self.root.map_widget.addImage(img, toRedraw)
        else:
            log.msg("Discarding image, roll: {}".format(img._roll))
Пример #9
0
def processImg(img_path, current_time, img_time, vn=None):
    """
    Do all image processing actions. Should be called on a separate process to allow mutli processesors.
    Currently does only resizing.
    """

    #
    # Load the image
    #
    log.msg('Loading new image {img}'.format(img=img_path))

    img = None
    jpeg_preview = None
    use_preview = 0

    if RESIZE_USING_EXIF_PREVIEW:
        try:
            jpeg_orig = pexif.JpegFile.fromFile(img_path)

            if jpeg_orig.app2 is not None and len(
                    jpeg_orig.app2.primary.preview) > 0:
                jpeg_preview = pexif.JpegFile.fromString(
                    jpeg_orig.app2.primary.preview[0])
                #jpeg_preview.import_exif(jpeg_orig.exif)

                use_preview = 1
            else:
                log.msg('No EXIF preview found, switching to OpenCV')

        except:
            use_preview = 0
            log.msg('WARNING: Using EXIF preview failed, switching to OpenCV')
            log.err(traceback.format_exc())

    current_timestamp = current_time.strftime(gs.BASE_TIMESTAMP)

    if not use_preview:
        img = AUVSIcv.Image(img_path,
                            timestamp=current_timestamp,
                            K=AUVSIcv.global_settings.K)

    #
    # Rename it with time stamp.
    #
    new_img_path = os.path.join(gs.RENAMED_IMAGES_FOLDER,
                                current_timestamp + '.jpg')

    log.msg('Renaming {old} to {new}'.format(old=img_path, new=new_img_path))
    os.rename(img_path, new_img_path)

    #
    # Resize the image.
    #
    log.msg('Resizing new image {img}'.format(img=new_img_path))

    filename = '{prefix}{path}'.format(prefix=gs.RESIZED_PREFIX,
                                       path=os.path.split(new_img_path)[1])
    resized_img_path = os.path.join(gs.RESIZED_IMAGES_FOLDER, filename)

    if not use_preview:
        resized_img = cv2.resize(img.img, (0, 0),
                                 fx=AUVSIcv.global_settings.FX_RESIZE_RATIO,
                                 fy=AUVSIcv.global_settings.FY_RESIZE_RATIO)
        cv2.imwrite(resized_img_path, resized_img)
    else:
        jpeg_preview.writeFile(resized_img_path)

    #
    # Find the corresponding flight data.
    #
    flight_data = getFlightData(img_time, AUVSIcv.global_settings.resized_K,
                                vn)
    flight_data_path = os.path.splitext(resized_img_path)[0] + '.json'
    with open(flight_data_path, 'wb') as f:
        json.dump(flight_data, f)
    log.msg('Saving flight data to path {path}'.format(
        path=os.path.split(flight_data_path)[-1]))
    #resized_img_path="unnamed"
    #flight_data={}

    return new_img_path, resized_img_path, flight_data
Пример #10
0
    def updateADLCresultsDB(self, img_name, img_path, data_path, results):
        """Update the image database with a new analysis result"""

        #
        # First add the crops to the database (so that we can update the GUI)
        # NOTE:
        # This section assumes that the flight_data has arrived. Although
        # this is a reasonable assumtion, it can fail. For example, if the
        # user turns of the download of images. So in general this location
        # is prone for error.
        #
        # NOTE:
        # I am hard coding the height, so that there will be no need to
        # load the image (time)
        #
        img_obj = AUVSIcv.Image(data_path=data_path,
                                K=AUVSIcv.global_settings.resized_K)
        h = 1080

        requested_crops = []
        for result in results:
            #
            # Note:
            # coords2LatLon assumes the center of axes is at the bottom left of
            # the image. Therefore there is a need to flip the y coords.
            #
            coords = np.array(result['rect']).ravel()
            x, y = (coords[:2] + coords[2:]) / 2
            y = max(h - y - 1, 0)
            lat, lon = img_obj.coords2LatLon(x, y)

            #
            # Check if the target is inside the search area.
            #
            if self._search_area is not None and not self._search_area.contains(
                    Point(lat, lon)):
                #
                # Target is not inside search area, ignore it.
                # The motivation is to reduce false positive even in the danger of missing
                # a true target.
                #
                continue

            shape = AUVSIcv.global_settings.SHAPE_LABELS[np.argmax(
                result['shape'])]
            if result['character'] is not None:
                if shape == "QRcode":
                    #
                    # In the case of QRcode, the character holds the message.
                    #
                    character = result['character']
                    yaw = None
                else:
                    #
                    # In the case of a geometric shape the characters holds
                    # the confidence scores.
                    #
                    character = AUVSIcv.global_settings.LETTER_LABELS[
                        np.argmax(result['character'])]
                    yaw = calculateOrientation(img_obj._yaw + result['angle'])
                requested_crops.append(coords)
            else:
                character = None
                yaw = None

            if result['color'] is None:
                shape_color = None
                char_color = None
            else:
                colors = result['color'][1:-1].split(',')
                char_color = colors[0].strip()
                shape_color = colors[1].strip()

            new_row = pd.Series(data=(lat, lon, shape, character, yaw,
                                      shape_color, char_color),
                                index=('latitude', 'longitude', 'shape',
                                       'character', 'angle', 'shape color',
                                       'character color'))
            self.crops_db.loc[(img_name, coordsToInds(coords)), :] = new_row

        #
        # Sort the crops multiindex lexically to improve search performance.
        #
        self.crops_db = self.crops_db.sortlevel()

        #
        # Update the image db.
        #
        if img_name not in self.images_db.index:
            #
            # The image has yet to download (unlikely).
            #
            new_row = pd.Series(data=(len(results), ), index=('crops num', ))
            new_row.name = img_name
            self.images_db = self.images_db.append(new_row)
        else:
            self.images_db['crops num'][img_name] = len(results)

        return requested_crops
Пример #11
0
            except:
                pass
            addPHdata(ph_flight_data)


def stopPixHawk():

    global continue_messages

    continue_message = False


if __name__ == '__main__':

    #try:
    #initPixHawk()
    #reactor.run()
    #except:
    #stopPixHawk()
    #raise

    import AUVSIcv

    initPixHawkSimulation()

    base_path = os.environ['AUVSI_CV_DATA']
    imgs_paths = glob.glob(os.path.join(base_path, '*.jpg'))

    img = AUVSIcv.Image(imgs_paths[0])
    print queryPHdata(img.datetime)
Пример #12
0
        root.add_widget(layout)

        return root


if __name__ == '__main__':

    TIME_OFFSET = 5
    base_path = r'C:\Users\User\Desktop\Go No Go 2.4\No Go\images'
    #base_path = gs.IMAGES_FOLDER

    #imgs_paths = sorted(glob.glob(os.path.join(base_path, '*0.jpg')))
    data_paths = sorted(glob.glob(os.path.join(base_path, '*.json')))
    imgs_paths = sorted(glob.glob(os.path.join(base_path, '*tn.jpg')))

    print len(imgs_paths)
    START = 200
    END = 500

    #imgs = [AUVSIcv.Image(img_path, data_path) for img_path, data_path in zip(imgs_paths[TIME_OFFSET:], data_paths[:-TIME_OFFSET])]
    #imgs = [AUVSIcv.Image(img_path, data_path) for img_path, data_path in zip(imgs_paths[:-TIME_OFFSET], data_paths[TIME_OFFSET:])]
    imgs = [
        AUVSIcv.Image(img_path, data_path) for img_path, data_path in zip(
            imgs_paths[START:END], data_paths[START:END])
    ]
    ned = NED.NED(imgs[0].latitude, imgs[0].longitude, 0)

    quads = [img.calculateQuad(ned, resolution=[4000, 3000]) for img in imgs]

    CanvasApp().run()
Пример #13
0
    def _shootingLoop(self, run):
        """Inifinite shooting loop. To run on separate process."""

        import PixHawk as PH
        import tempfile

        base_temp_path = tempfile.mkdtemp()
        temp_data_path = os.path.join(base_temp_path, 'temp.json')

        #
        # There is a need to init the pixhawk module
        # because the camera is running on a separate
        # process.
        #
        PH.initPixHawkSimulation()

        base_path = os.environ['AUVSI_CV_DATA']
        log.msg('base_path=' + base_path)
        imgs_paths = sorted(
            glob.glob(os.path.join(base_path, 'renamed_images', '*.jpg')))
        img_index = 0
        target_set = []
        while run.value == 1:
            #
            # Pick up an image from disk
            #
            img_path = imgs_paths[img_index]
            time_stamp = os.path.split(img_path)[-1][:-4]
            new_name = os.path.join(self.base_path,
                                    os.path.split(img_path)[-1])

            img_index = (img_index + 1) % len(imgs_paths)

            if self._simulate_targets:
                #
                # When simulating targets, there is a need to
                # load the image from disk, paste a target on
                # it and resave on disk. In the process the
                # exif thumbnail is not updated and therefor
                # the resized image will need to be done using
                # opencv. This process is slower than just copying
                # the image and therefore it is not a good idea
                # to do this on the odroid.
                #
                # Get the corresponding data
                #
                with open(temp_data_path, 'wb') as f:
                    json.dump(PH.queryPHdata(time_stamp), f)

                #
                # Load the image
                #
                try:
                    img = AUVSIcv.Image(img_path,
                                        data_path=temp_data_path,
                                        K=AUVSIcv.global_settings.K)
                except:
                    continue

                #
                # Add a target.
                #
                try:
                    if not target_set:
                        print 'creating targets'
                        for i in range(300):
                            #
                            # Create a target.
                            #
                            target, _, _ = AUVSIcv.randomTarget(
                                altitude=0,
                                longitude=-76.6993009944,
                                latitude=38.8515321606,
                                coords_offset=0.005)
                            print 'Created target:', type(target)
                            target_set.append(target)

                    #
                    # Paste it on the image.
                    #
                    for target in target_set:
                        print 'Pasting target'
                        img.paste(target)

                    #
                    # Save the image to disk (should trigger the image processing code).
                    #
                    cv2.imwrite(new_name, img.img)

                except:
                    raise
            else:
                #
                # Save the image to disk (should trigger the image processing code).
                #
                shutil.copyfile(img_path, new_name)

            if self.target_queue:
                img_time = datetime.strptime(time_stamp, gs.BASE_TIMESTAMP)
                self.target_queue.put((new_name, img_time), False)

            #
            # fps = 2
            #
            time.sleep(0.5)