Пример #1
0
def post_observation():
    try:
        # Get Data
        Obs = request.form
        Time = str(Obs['Time'])#datetime.datetime.now().time()
        Time = Time if Time is not None else datetime.datetime.now().time()
        Date = str(Obs['Date'])#datetime.datetime.now().date()
        Date = Date if Date is not None else datetime.datetime.now().date()
        Latitude = float(Obs['Latitude'])
        Longitude = float(Obs['Longitude'])
        DeviceId = str(Obs['DeviceId'])
        DeviceType = str(Obs['DeviceType'])
        LocationError = float(Obs['LocationError'])

        if not checkValuesExist(Latitude, Longitude, DeviceId, DeviceType, LocationError):
            raise ValueError('Values cannot be null')

        if DeviceType not in ALLOWED_DEVICES:
            raise ValueError('Device not allowed')

        # Check if phone is in the database
        device = db_session.query(Device.id, Device.IsBlackListed).filter(and_( \
            Device.DeviceId == DeviceId, \
            Device.DeviceType == DeviceType)).first()

        if device is None:
            device = Device(DeviceId, DeviceType)
            db_session().add(device)
            db_session().commit()
       
        if bool(device.IsBlackListed):
            raise ValueError('Device not allowed')
        # Get File
        newFile = request.files['picture']
        if newFile and allowed_file(newFile.filename):
            filename = secure_filename(newFile.filename)
            while getSQLNoneValue(db_session().query(Observation.FileName) \
                    .filter(Observation.FileName == filename).first()) is not None:
                filename = createUniqueFileName(filename, DeviceType)
            print filename
            newFile.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        
        os.system("convert -thumbnail 150 " + os.path.join(app.config['UPLOAD_FOLDER'], filename) \
                + " " + os.path.join(THUMBNAIL_FOLDER, filename))

        observation = Observation(Time, Date, Latitude, Longitude, LocationError, filename, UPLOAD_FOLDER, device.id) 
        db_session().add(observation)
        db_session().flush()
        db_session().refresh(observation)
        obs_id =  observation.ObsID
        db_session().commit()
        print obs_id
        id_to_db.delay(obs_id)
        results = "sent"
        errors = None

    except Exception,e:
        #print e
        results = "failed"
        errors = e.message + " " + repr(e)
Пример #2
0
def gen_rotation_images(objid):
    rotations = db_session.query(RotationObject.id, RotationObject.ParentDetectionObjectID, \
            RotationObject.Location, RotationObject.FileName, RotationObject.RotationAngle) \
            .filter(RotationObject.ParentDetectionObjectID == objid)
    isPositive = db_session.query(DetectionObject).get(objid).IsPosDetect
    pos_dir = "positive/" if isPositive == 1 or isPositive == None else "negative/"

    for rotation in rotations:
        rotationangle = rotation.RotationAngle

        original_filename = str(db_session().query(DetectionObject.ObjectID, DetectionObject.FileName)\
                .filter(DetectionObject.ObjectID == rotation.ParentDetectionObjectID)\
                .first().FileName)
        print original_filename
        filename = pos_dir + str(rotation.id) + "_rotated_" + original_filename
        os.system("shell_scripts/rotate_image2.sh " + \
                os.path.join(CROPPED_FOLDER, original_filename) + " " +\
                os.path.join(ROTATED_FOLDER, filename) + " " + str(rotationangle))

        save = RotationObject.query.get(rotation.id)
        save.FileName = filename
        save.Location = ROTATED_FOLDER
        db_session.commit()
Пример #3
0
obs_id = sys.argv[1]
obs = db_session().query(Observation).filter(Observation.ObsID == obs_id).first()

picture_location = obs.Location + '/' + obs.FileName
print FINDFLOWER_LOCATION + ' ' + picture_location + ' 2> /dev/null'
p = subprocess.Popen(FINDFLOWER_LOCATION + ' ' + picture_location + ' 2> /dev/null', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
lines = p.stdout.readlines()
p.wait()

numflowers = 0

for line in lines:
        x,y,r = line.rstrip().split(" ")
	numflowers += 1
        # only want to add to the db if there is not already an identical detection object
        if not db_session.query(DetectionObject).filter(DetectionObject.ParentObsID == obs_id, DetectionObject.XCord == x, DetectionObject.YCord == y, DetectionObject.Radius == r, DetectionObject.IsUserDetected == USER_DETECT_FALSE).first():
            flower = DetectionObject(x, y, r, POS_DETECT_TRUE, USER_DETECT_FALSE, obs_id)
            db_session().add(flower)
            print "new: ",x,y,r
        else:
            print "old: ",x,y,r

p = subprocess.Popen(BOW_PROBABILITY_LOCATION + ' ' + picture_location + ' 2> /dev/null', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
line = p.stdout.readline()

p.wait()

bow_probability = float(line)
bow_detected = bow_probability >= 0.45625
obs.Probability = bow_probability
obs.IDbyAlgorithm = bow_detected or (numflowers > 0)
Пример #4
0
p = subprocess.Popen(FINDFLOWER_LOCATION + ' ' + picture_location +
                     ' 2> /dev/null',
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
lines = p.stdout.readlines()
p.wait()

numflowers = 0

for line in lines:
    x, y, r = line.rstrip().split(" ")
    numflowers += 1
    # only want to add to the db if there is not already an identical detection object
    if not db_session.query(DetectionObject).filter(
            DetectionObject.ParentObsID == obs_id, DetectionObject.XCord == x,
            DetectionObject.YCord == y, DetectionObject.Radius == r,
            DetectionObject.IsUserDetected == USER_DETECT_FALSE).first():
        flower = DetectionObject(x, y, r, POS_DETECT_TRUE, USER_DETECT_FALSE,
                                 obs_id)
        db_session().add(flower)
        print "new: ", x, y, r
    else:
        print "old: ", x, y, r

p = subprocess.Popen(BOW_PROBABILITY_LOCATION + ' ' + picture_location +
                     ' 2> /dev/null',
                     shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
line = p.stdout.readline()