示例#1
0
 def exactor(self, one):
     faces = one[1].split(';')
     face_dir = one[-1]
     for face in faces:
         all_finished = True
         if face:
             face_path = face_dir + one[2] + '/' + face
             cmd = "../cmodel/featurebr/build/feature %s %s " % (
                 "FaceRecognition", face_path)
             print cmd
             res = exeCmd(cmd)
             data = res.strip(',').split(',')
             ldata = len(data)
             if ldata != self.conf['item_len']:
                 print "len of data error: %d" % ldata
                 all_finished = False
                 continue
             data = self.indexData(data)
             data['hash_id'] = one[0]
             data['path'] = face_path
             data['uri'] = one[3]
             res = self.es.index(index="face",
                                 doc_type="feature",
                                 body=data)
         if all_finished:
             db = Mysql(self.conf["db_host"], self.conf["db_database"],
                        self.conf["db_user"], self.conf["db_pass"])
             sql = "update images set status = '4' where `md5` = '%s' " % one[
                 0]
             db.execute(sql)
             db.close()
     return
示例#2
0
class ImgStatusChk(object):
    def __init__(self, conf):
        self.conf = {}
        self.conf = conf
        self.db = Mysql(conf["db_host"], conf["db_database"], conf["db_user"],
                        conf["db_pass"])

    def run(self):
        sql = "select pic_dir, fname, `md5` from images where status = '1' "
        res = self.db.query(sql)
        i = 0
        for one in res:
            i += 1
            imgpath = ""
            try:
                imgpath = self.conf["img_path"] + one[0] + "/" + one[1]
                tmpimg = cv.LoadImage(imgpath)
                print i, cv.GetSize(tmpimg)
                sql = "update images set status = '2' where `md5` = '%s'" % (
                    one[2])
                self.db.execute(sql)
            except:
                sql = "update images set status = 'z' where `md5` = '%s'" % (
                    one[2])
                print sql
                self.db.execute(sql)
                try:
                    if not imgpath:
                        os.remove(imgpath)
                except:
                    1

    def testPrint(self):
        print "Hello World!"
示例#3
0
 def finishPic(self, pic): # opencv
     face_cascade = cv2.CascadeClassifier(self.conf["cascade"])
     imgpath = self.conf['img_path'] + pic[0] + '/' + pic[1]
     img = cv2.imread(imgpath)
     gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
     faces = face_cascade.detectMultiScale(gray, 1.5, 7)
     i = 0
     faces_str = ""
     for (x,y,w,h) in faces:
         faces_str += pic[1] + ".face_"+str(i)+".jpg;"
         face_path = pic[3] + pic[1] + ".face_"+str(i)+".jpg"
         tmpimg = cv.LoadImage(imgpath)
         cv.SetImageROI(tmpimg, (x, y, w, int(h*1.15)))
         cv.SaveImage(face_path,tmpimg)
         print face_path
         i += 1
     db = Mysql(self.conf["db_host"], self.conf["db_database"], self.conf["db_user"], self.conf["db_pass"])
     sql = "update images set status='3', face_dir='%s' where `md5`='%s'" % (faces_str, pic[2])
     db.execute(sql)
     db.close()
     return
示例#4
0
class DataChecker(object):
    def __init__(self, conf):
        self.conf = {}
        self.conf = conf
        self.db = Mysql(conf["db_host"], conf["db_database"], conf["db_user"],
                        conf["db_pass"])
        self.rc = []

    def getOneRecord(self):
        if len(self.rc) <= 0:
            sql = "select spec, count(*), pic_dir  from images where pic_dir is null and (type = 'star_female' or type = 'star_male') group by spec order by spec limit 50"
            self.rc = self.db.query(sql)
        if len(self.rc) <= 0:
            print "empty"
            exit()
        one = self.rc.pop()
        print one[0], one[1], one[2]
        return one[0]

    def run(self):
        spec = ""
        while (True):
            spec = self.getOneRecord()
            cmd = raw_input()
            sql = ""
            if cmd == "exit":
                break
            else:
                sql = "update images set pic_dir = '%s' where pic_dir is null and spec = '%s'" % (
                    cmd, spec)

            self.db.execute(sql)
            print sql
        return

    def testPrint(self):
        print "Hello World!"
示例#5
0
class ImgSet(object):
    def __init__(self, conf):
        self.conf = {}
        self.conf = conf
        self.db = Mysql(conf["db_host"], conf["db_database"], conf["db_user"],
                        conf["db_pass"])

    def loadsData(self, data):
        print "loadsData should be rewrite!"
        return data

    def uriTemplate(self, uri_tmp, uri_referer, data_key):
        self.uri = uri_tmp
        self.referer = uri_referer
        self.data_key = data_key
        return

    def setUriParam(self, data):
        self.s = data
        for k in data.keys():
            self.uri = self.uri.replace("<%s>" % (k), urllib.quote(data[k]))
            self.referer = self.referer.replace("<%s>" % (k),
                                                urllib.quote(data[k]))
        return

    def fetchSet(self, start=0, limit=60):
        res = {}
        uri = self.uri.replace("<start>", str(start))
        uri = uri.replace("<limit>", str(limit))
        #print uri
        #print self.referer
        text = fetchUrl(uri, param={"referer": self.referer})
        res = self.loadsData(text)
        return res

    def save(self, data, loop_i):
        sql = "select `md5`, tags from images where `md5` = '%s' limit 1" % (
            data["md5"])
        res = self.db.query(sql)
        #print res
        tag = data["tags"]
        if len(res) > 0:  # update
            tags = res[0][1].split(",")
            tags_dic = {}
            for t in tags:
                tags_dic[md5(t)] = 1
            if not tags_dic.has_key(md5(tag)):
                sql = "update images set tags = concat(tags, ',%s') where `md5` = '%s'" % (
                    tag, data["md5"])
                #print sql
                self.db.execute(sql)
        else:  # insert
            keys = ""
            values = ""
            for k in data.keys():
                keys += " `%s`, " % (k)
                values += " '%s' ," % (data[k])
            keys = keys.strip(" ,") + ", createtime, fetch_loop "
            values = values.strip(" ,") + ", now(), %s " % (str(loop_i))
            sql = "insert into images ( %s ) values( %s )" % (keys, values)
            self.db.execute(sql)
            #print keys, values
            #print sql
        #exit()
        return

    def testPrint(self):
        print "Hello World!"