Exemplo n.º 1
0
                    print msg
                    log.write(msg + "\n")
                    f = open('dataset/data', 'r')

                    lines = f.readlines()
                    datas_raw = []

                    for line in lines:
                        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
                        }
Exemplo n.º 2
0
lines = f.readlines()

for line in lines:
    line = line.strip()
    words = line.split(' ')

    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)
Exemplo n.º 3
0
                        f = open('dataset/data', 'r')
                        lines = f.readlines()
                        datas_raw = []

                        for line in lines:
                            line = line.strip()
                            words = line.split(' ')

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

                            strings = {}

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


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

                        f.close()

                        f = open('testset/data', 'r')

                        lines = f.readlines()
                        cc5 = 0.0
                        cc10 = 0.0
                        cc15 = 0.0
Exemplo n.º 4
0
    dataset = ['550610487.jpg', '550610488.jpg', '550610525.jpg', '550610530.jpg']
    name = ['487', '488', '525', '530']

    f = open('res_test', 'w')

    f.write("sid\t")
    for n in name:
        f.write(n+"\t")

    f.write("\n\n")

    i = 0

    for d in dataset:
        f.write(name[i]+"\t")
        i+=1
        for dd in dataset:
            im1 = tool.imread('test/head/'+d, draw=False)
            im2 = tool.imread('test/input/'+dd, draw=True)

            s1 = extract(im1)
            s2 = extract(im2)

            s = str(dist(s1, s2))

            f.write(s+"\t")

        f.write("\n")

    f.close()
Exemplo n.º 5
0
                        lines = f.readlines()
                        datas_raw = []

                        for line in lines:
                            line = line.strip()
                            words = line.split(' ')

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

                            strings = {}

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

                            data = {
                                'id': sid,
                                'sex': sex,
                                'name': name,
                                'dtype': 'strgramma',
                                'strings': strings
                            }
Exemplo n.º 6
0
    ]
    name = ['487', '488', '525', '530']

    f = open('res_test', 'w')

    f.write("sid\t")
    for n in name:
        f.write(n + "\t")

    f.write("\n\n")

    i = 0

    for d in dataset:
        f.write(name[i] + "\t")
        i += 1
        for dd in dataset:
            im1 = tool.imread('test/head/' + d, draw=False)
            im2 = tool.imread('test/input/' + dd, draw=True)

            s1 = extract(im1)
            s2 = extract(im2)

            s = str(dist(s1, s2))

            f.write(s + "\t")

        f.write("\n")

    f.close()
Exemplo n.º 7
0
import usurf
import tool
import cv2
import numpy as np

im_draw = tool.imread('dataset/550610525.jpg', draw=True)

keypoints = usurf.detect(im_draw)

for keypoint in keypoints:
    cv2.circle(im_draw,keypoint["position"], int(keypoint["scale"]*10), (0,0,0), 1)

cv2.imwrite("res.jpg", im_draw)
cv2.waitKey(0)
Exemplo n.º 8
0
lines = f.readlines()

for line in lines:
    line = line.strip()
    words = line.split(' ')

    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}
Exemplo n.º 9
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"})
Exemplo n.º 10
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"})