Esempio n. 1
0
    def test(self):
        model = incoming_image()
        model.time_stamp = 1547453775.2
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/i/swear.jpg'
        model.manual_tap = False
        model.autonomous_tap = False

        truncateTable('incoming_image')
        dao = IncomingImageDAO(defaultConfigPath())
        self.assertIsNotNone(dao)

        # test with empty table

        self.assertIsNone(dao.getImage(1))

        resultingId = dao.addImage(model)
        self.assertNotEqual(resultingId, -1)

        resultingModel = dao.getImage(resultingId)

        self.assertIsNotNone(resultingModel)
        self.assertAlmostEqual(resultingModel.time_stamp, model.time_stamp)
        self.assertEqual(resultingModel.focal_length, model.focal_length)
        self.assertEqual(resultingModel.image_path, model.image_path)
        self.assertEqual(resultingModel.manual_tap, model.manual_tap)
        self.assertEqual(resultingModel.autonomous_tap, model.autonomous_tap)
Esempio n. 2
0
    def get(self, image_id):
        dao = IncomingImageDAO(defaultConfigPath())
        image = dao.getImage(image_id)

        if image is None:
            return {
                'message': 'Failed to locate raw id {}'.format(image_id)
            }, 404
        return jsonify(image.toDict())
Esempio n. 3
0
    def get(self, image_id):
        dao = IncomingImageDAO(defaultConfigPath())
        image = dao.getImage(image_id)
        if image is None:
            return {
                'message': 'Failed to locate raw id {}'.format(image_id)
            }, 404

        # otherwise lets send the image::
        return rawImageSender(image.image_id, image.image_path)
Esempio n. 4
0
    def processGeolocation(self, geolocator, classification, croppedImg):
        """
        Geolocation processing stuff common to both manual and autonomous.
        Called only by the processManualGeolocation and processAutonomousGeolocation
        methods
        """
        dao = IncomingImageDAO(defaultConfigPath())
        rawImg = dao.getImage(croppedImg.image_id)
        dao.close()
        if rawImg is None:
            print(
                "Failed to find raw image {} for autonomous cropped image {}!".
                format(croppedImg.image_id, croppedImg.crop_id))
            return None

        dao = IncomingGpsDAO(defaultConfigPath())
        gpsRaw = dao.getGpsByClosestTS(rawImg.time_stamp)
        dao.close()

        if gpsRaw is None:
            print("Failed to find gps measurement close to raw timestamp {}!".
                  format(rawImg.time_stamp))
            return None

        dao = IncomingStateDAO(defaultConfigPath())
        stateRaw = dao.getStateByClosestTS(rawImg.time_stamp)
        dao.close()

        if stateRaw is None:
            print(
                "Failed to find state measurement close to raw timestamp {}!".
                format(rawImg.time_stamp))
            return None

        # lat, lon = geolocator.calculate_geolocation(gpsRaw.lat, gpsRaw.lon, gpsRaw.alt, stateRaw.roll, stateRaw.pitch, stateRaw.yaw, croppedImg.crop_coordinate_tl.x, croppedImg.crop_coordinate_tl.y, croppedImg.crop_coordinate_br.x, croppedImg.crop_coordinate_br.y)
        lat, lon = geolocator.calculate_geolocation(
            gpsRaw.lat, gpsRaw.lon, -stateRaw.position[2], stateRaw.roll,
            stateRaw.pitch, stateRaw.yaw, croppedImg.crop_coordinate_tl.x,
            croppedImg.crop_coordinate_tl.y, croppedImg.crop_coordinate_br.x,
            croppedImg.crop_coordinate_br.y)

        return {'latitude': lat, 'longitude': lon}
Esempio n. 5
0
    def post(self):
        # confirm that the X-Manual header was specified
        manual = checkXManual(request)

        # basic setup pieces for this taken from :
        # http://flask.pocoo.org/docs/1.0/patterns/fileuploads/
        # Input Validation:
        if 'cropped_image' not in request.files:
            abort(400, "Need to pass an image with the key 'cropped_image'")
        imageFile = request.files.get('cropped_image', '')

        # use the right model object depending on if this is a manual or autonomous request
        cropped = cropped_manual() if manual else cropped_autonomous()
        # confirm that we got an image_id in the headers
        if 'X-Image-Id' in request.headers:
            cropped.image_id = request.headers.get('X-Image-Id')
        else:
            abort(400, "Need to specify header 'X-Image-Id'!")

        # make sure the filename wont make our computer explode:
        if imageFile.filename == '' or imageFile.filename == 'cropped_image':
            # if we didnt get a filename we assume jpg. why not....
            extension = 'jpg'
        elif not allowedFileType(imageFile.filename):
            abort(400, "Filetype is not allowed!")
        else:
            extension = getFileExtension(imageFile.filename)

        imageFile.filename = str(int(time.time())) + "-" + str(
            randint(0, 10000)) + '.' + extension

        filename = secure_filename(imageFile.filename)
        # save image
        full_path = os.path.join(defaultCroppedImgPath(), filename)
        imageFile.save(full_path)
        cropped.cropped_path = full_path

        # check for the optional crop coordinate form data
        if 'crop_coordinate_tl' in request.form:
            cropped.crop_coordinate_tl = point(
                ptStr=request.form['crop_coordinate_tl'])
        if 'crop_coordinate_br' in request.form:
            cropped.crop_coordinate_br = point(
                ptStr=request.form['crop_coordinate_br'])

        # get the timestamp from incoming_image table to copy into this guy....
        # meh, but functional /shrug
        dao = IncomingImageDAO(defaultConfigPath())
        img = dao.getImage(cropped.image_id)
        if img is not None:
            cropped.time_stamp = img.time_stamp
        else:
            print(
                "WARN:: failed to find incoming_image model at id {} X-Image-Id"
                .format(cropped.image_id))
            cropped.time_stamp = int(time.time())

        # add to db
        dao = CroppedManualDAO(
            defaultConfigPath()) if manual else CroppedAutonomousDAO(
                defaultConfigPath())
        # resultingId is the cropped_manual.id value given to this image (abstracted from client)
        resultingId = dao.upsertCropped(cropped)

        if resultingId == -1:
            return {
                'message':
                'Failed to insert image into manual_cropped! (If youre trying to update information on an image_id that already exists, you should use PUT)'
            }, 500

        # done!
        response = make_response(
            jsonify({
                'message': 'success!',
                'id': resultingId
            }))
        response.headers['X-Crop-Id'] = resultingId
        return response