예제 #1
0
def add():
    image = request.POST.get('photo')
    name = request.POST.get('name')
    common_name = request.POST.get('common_name')
    plant = Plant.retrieve(request.db, name)
    if plant: return "This species is already in the DB"
    if image is not None:
        mime = mimetypes.guess_type(image.filename)[0]
        conn = S3Connection('AKIAIMXIHJX3TFDQFVCA',
                            'Lf7xWpeOB9mnY1zfFzl7WNtxtNhmCZ4ZXOI8Kvrr')
        bucket = conn.get_bucket('db_leaves')
        key = Key(bucket)
        key.key = name
        key.set_metadata("Content-Type", mime)
        key.set_contents_from_string(image.value)
        key.set_acl("public-read")

        descriptors, ax, bx, ay, by = EFD(
            Threshold(image.file).process(), 50, 100).fourier_coefficients()
        return Plant({
            'name':
            name,
            'common_name':
            common_name,
            'wiki':
            request.POST.get('wiki'),
            'photo':
            'https://s3.amazonaws.com/db_leaves/%s' % quote(name),
            'descriptors':
            descriptors
        }).save(request.db)
    return []
예제 #2
0
파일: plants.py 프로젝트: sebavp/Plants-Web
def add():
    image = request.POST.get("photo")
    name = request.POST.get("name")
    common_name = request.POST.get("common_name")
    plant = Plant.retrieve(request.db, name)
    if plant:
        return "This species is already in the DB"
    if image is not None:
        mime = mimetypes.guess_type(image.filename)[0]
        conn = S3Connection("AKIAIMXIHJX3TFDQFVCA", "Lf7xWpeOB9mnY1zfFzl7WNtxtNhmCZ4ZXOI8Kvrr")
        bucket = conn.get_bucket("db_leaves")
        key = Key(bucket)
        key.key = name
        key.set_metadata("Content-Type", mime)
        key.set_contents_from_string(image.value)
        key.set_acl("public-read")

        descriptors, ax, bx, ay, by = EFD(Threshold(image.file).process(), 50, 100).fourier_coefficients()
        return Plant(
            {
                "name": name,
                "common_name": common_name,
                "wiki": request.POST.get("wiki"),
                "photo": "https://s3.amazonaws.com/db_leaves/%s" % quote(name),
                "descriptors": descriptors,
            }
        ).save(request.db)
    return []
예제 #3
0
def search():
    image = request.POST.get('photo')
    descriptors, ax, bx, ay, by = EFD(
        Threshold(image.file).process(), 50, 100).fourier_coefficients()
    plants = Plant.search(request.db, descriptors)
    response.headers['Content-type'] = 'application/json'
    return json.dumps(plants)
예제 #4
0
파일: plants.py 프로젝트: sebavp/Plants-Web
def add_sample():
    image = request.POST.get("photo")
    name = request.POST.get("name")
    if image is not None:

        descriptors, ax, bx, ay, by = EFD(Threshold(image.file).process(), 50, 100).fourier_coefficients()
        return Plant.add_sample(request.db, name, descriptors)
    return []
예제 #5
0
def add_sample():
    image = request.POST.get('photo')
    name = request.POST.get('name')
    if image is not None:

        descriptors, ax, bx, ay, by = EFD(
            Threshold(image.file).process(), 50, 100).fourier_coefficients()
        return Plant.add_sample(request.db, name, descriptors)
    return []
예제 #6
0
파일: plants.py 프로젝트: sebavp/Plants-Web
def search():
    image = request.POST.get("photo")
    descriptors, ax, bx, ay, by = EFD(Threshold(image.file).process(), 50, 100).fourier_coefficients()
    plants = Plant.search(request.db, descriptors)
    response.headers["Content-type"] = "application/json"
    return json.dumps(plants)