Beispiel #1
0
                        line = line.strip()
                        words = line.split(' ')

                        sid = words[0]
                        sex = words[1]
                        name = words[2] + " " + words[3]

                        im_draw = tool.imread('dataset/raw/' + sid + '.jpg',
                                              draw=True)

                        keypoints = usurf.detect(im_draw,
                                                 octave=octave,
                                                 period=period,
                                                 scale=scale,
                                                 hessian=hessian)
                        usurf.extract(im_draw, keypoints)

                        data = {
                            'id': sid,
                            'sex': sex,
                            'name': name,
                            'dtype': 'usurf',
                            'keypoints': keypoints
                        }
                        datas_raw.append(data)

                    f.close()

                    with open('data_usurf.json', 'w') as outfile:
                        json.dump(datas_raw, outfile)
                    '''
Beispiel #2
0
    def render_POST(self, request):
        self.headers = request.getAllHeaders()

        img = cgi.FieldStorage(
            fp = request.content,
            headers = self.headers,
            environ = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE': self.headers['content-type']})

        full = ""
        jaw = ""
        eyebrows = ""
        eyes = ""
        nose = ""
        mouth = ""

        if img.has_key("full"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["full"].value)
            out.close()
            full = filename

        if img.has_key("jaw"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["jaw"].value)
            out.close()
            jaw = filename

        if img.has_key("eyebrows"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["eyebrows"].value)
            out.close()
            eyebrows = filename

        if img.has_key("eyes"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["eyes"].value)
            out.close()
            eyes = filename

        if img.has_key("nose"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["nose"].value)
            out.close()
            nose = filename

        if img.has_key("mouth"):
            filename = gen_random_name(32)+'.jpg'
            out = open('logs/'+filename, 'wb')
            out.write(img["mouth"].value)
            out.close()
            mouth = filename

        if img.has_key("sex") and img.has_key("algo"):

            sex = img["sex"].value
            datas = dataset.get(filter={'sex': sex})

            if img["algo"].value=="usurf" and full!="":
                im = tool.imread('logs/'+full)
                keypoints = usurf.detect(im)
                usurf.extract(im, keypoints)

                lk = len(keypoints)

                for data in datas:
                    if data["dtype"]=="usurf":
                        data["point"] = tool.match(keypoints, data["keypoints"])*1.0/lk
                    else:
                        data["point"] = 0.0

            elif img["algo"].value=="strgrammar" and jaw!="" and eyebrows!="" and eyes!="" and nose!="" and mouth!="":
                strings = {}
                strings["jaw"] = strgramma.extract(tool.imread('logs/'+jaw))
                strings["eyebrows"] = strgramma.extract(tool.imread('logs/'+eyebrows))
                strings["eyes"] = strgramma.extract(tool.imread('logs/'+eyes))
                strings["nose"] = strgramma.extract(tool.imread('logs/'+nose))
                strings["mouth"] = strgramma.extract(tool.imread('logs/'+mouth))

                for data in datas:
                    if data["dtype"]=="strgramma":
                        data["point"] = 0.0
                        for segment in segments:
                            data["point"]+=strgramma.dist(strings[segment], data["strings"][segment])

                        data["point"] = 1.0/data["point"]
                    else:
                        data["point"] = 0.0
            else:
                return json.dumps({"status": "fail", "detail": "Wrong Parameter"})

            datas = sorted(datas, key=itemgetter('point'), reverse=True)

            res = []

            for i in range(min(10, len(datas))):
                data = datas[i]
                res.append({'id': data['id'], 'name': data['name'], 'sex': data['sex'], 'point': float(data['point'])})

            request.responseHeaders.addRawHeader(b"content-type", b"application/json")
            return json.dumps({"status": "success", "data": res})
        else:
            return json.dumps({"status": "fail", "detail": "Wrong Parameter"})
Beispiel #3
0
    sid = words[0]
    sex = words[1]
    name = words[2]+" "+words[3]

    print "Process sid " + sid

    strings = {}

    for segment in segments:
        im_draw = tool.imread('dataset/segment/'+segment+sid[-3:]+'.png', draw=False)
        s = strgramma.extract(im_draw)
        strings[segment] = s


    data = {'id': sid, 'sex': sex, 'name':name, 'dtype': 'strgramma', 'strings': strings}
    dataset.add(data)

    print "Extract String Gramma "+ sid +" [Done]"

    im_draw = tool.imread('dataset/raw/'+sid+'.jpg', draw=True)

    keypoints = usurf.detect(im_draw)
    usurf.extract(im_draw, keypoints)

    data = {'id': sid, 'sex': sex, 'name':name, 'dtype': 'usurf', 'keypoints': keypoints}
    dataset.add(data)

    print "Extract usurf "+ sid +" [DONE]"
    print ""
Beispiel #4
0
    def render_POST(self, request):
        self.headers = request.getAllHeaders()

        img = cgi.FieldStorage(fp=request.content,
                               headers=self.headers,
                               environ={
                                   'REQUEST_METHOD': 'POST',
                                   'CONTENT_TYPE': self.headers['content-type']
                               })

        full = ""
        jaw = ""
        eyebrows = ""
        eyes = ""
        nose = ""
        mouth = ""

        if img.has_key("full"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["full"].value)
            out.close()
            full = filename

        if img.has_key("jaw"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["jaw"].value)
            out.close()
            jaw = filename

        if img.has_key("eyebrows"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["eyebrows"].value)
            out.close()
            eyebrows = filename

        if img.has_key("eyes"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["eyes"].value)
            out.close()
            eyes = filename

        if img.has_key("nose"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["nose"].value)
            out.close()
            nose = filename

        if img.has_key("mouth"):
            filename = gen_random_name(32) + '.jpg'
            out = open('logs/' + filename, 'wb')
            out.write(img["mouth"].value)
            out.close()
            mouth = filename

        if img.has_key("sex") and img.has_key("algo"):

            sex = img["sex"].value
            datas = dataset.get(filter={'sex': sex})

            if img["algo"].value == "usurf" and full != "":
                im = tool.imread('logs/' + full)
                keypoints = usurf.detect(im)
                usurf.extract(im, keypoints)

                lk = len(keypoints)

                for data in datas:
                    if data["dtype"] == "usurf":
                        data["point"] = tool.match(
                            keypoints, data["keypoints"]) * 1.0 / lk
                    else:
                        data["point"] = 0.0

            elif img[
                    "algo"].value == "strgrammar" and jaw != "" and eyebrows != "" and eyes != "" and nose != "" and mouth != "":
                strings = {}
                strings["jaw"] = strgramma.extract(tool.imread('logs/' + jaw))
                strings["eyebrows"] = strgramma.extract(
                    tool.imread('logs/' + eyebrows))
                strings["eyes"] = strgramma.extract(tool.imread('logs/' +
                                                                eyes))
                strings["nose"] = strgramma.extract(tool.imread('logs/' +
                                                                nose))
                strings["mouth"] = strgramma.extract(
                    tool.imread('logs/' + mouth))

                for data in datas:
                    if data["dtype"] == "strgramma":
                        data["point"] = 0.0
                        for segment in segments:
                            data["point"] += strgramma.dist(
                                strings[segment], data["strings"][segment])

                        data["point"] = 1.0 / data["point"]
                    else:
                        data["point"] = 0.0
            else:
                return json.dumps({
                    "status": "fail",
                    "detail": "Wrong Parameter"
                })

            datas = sorted(datas, key=itemgetter('point'), reverse=True)

            res = []

            for i in range(min(10, len(datas))):
                data = datas[i]
                res.append({
                    'id': data['id'],
                    'name': data['name'],
                    'sex': data['sex'],
                    'point': float(data['point'])
                })

            request.responseHeaders.addRawHeader(b"content-type",
                                                 b"application/json")
            return json.dumps({"status": "success", "data": res})
        else:
            return json.dumps({"status": "fail", "detail": "Wrong Parameter"})