Ejemplo n.º 1
0
    def selectFromPerson(self, wherePerson=None, max_row=None):
        if self.CONNECTED:
            table = "person"
            person = object_DL.Person()
            if wherePerson is not None and isinstance(wherePerson,
                                                      object_DL.Person):
                arr_n = wherePerson.get_arr_name_columns()
                arr_v = wherePerson.get_value()
                f_arr_n = []
                f_arr_v = []
                for i in range(len(arr_v)):
                    if arr_v[i] is not None:
                        f_arr_n.append(arr_n[i])
                        f_arr_v.append(arr_v[i])

                columns, refer = self.__standardize_for_query(f_arr_n)
                sql = "SELECT {} FROM {} WHERE ({}) = ({})".format(
                    person.get_name_columns(), table, columns, refer)
                val = f_arr_v
                try:
                    self.__mycursor.execute(sql, val)
                except mysql.connector.Error as err:
                    logging.exception(
                        "ERR in selectFromPerson: {}".format(err))
                    return None
            else:
                sql = "SELECT {} FROM {}".format(person.get_name_columns(),
                                                 table)
                try:
                    self.__mycursor.execute(sql)
                except mysql.connector.Error as err:
                    logging.exception(
                        "ERR in selectFromPerson: {}".format(err))
                    return None

            if max_row is not None:
                rs = self.__mycursor.fetchmany(max_row)
            else:
                rs = self.__mycursor.fetchall()

            obj_rs = []
            for x in rs:
                obj_rs.append(
                    object_DL.Person(id=x[0],
                                     name=x[1],
                                     age=x[2],
                                     gender=x[3],
                                     idcode=x[4],
                                     embedding=x[5],
                                     b64face=x[6],
                                     b64image=x[7]))
            return obj_rs
Ejemplo n.º 2
0
 def getPersonByIdCode(self, idCodePerson):
     if self.CONNECTED:
         table = "person"
         person = object_DL.Person()
         sql = "SELECT * FROM {} WHERE idCode = {}".format(
             table, idCodePerson)
         try:
             self.__mycursor.execute(sql)
             rows = self.__mycursor.fetchall()
             for row in rows:
                 return object_DL.Person(id=row['idPerson'],
                                         name=row['name'],
                                         age=row['age'],
                                         gender=row['gender'],
                                         idcode=row['idCode'],
                                         embedding=row['embedding'],
                                         b64face=row['b64Face'],
                                         b64image=row['b64Image'])
         except mysql.connector.Error as err:
             logging.exception("ERR in getPersonByIdCode: {}".format(err))
             return None
     return None
Ejemplo n.º 3
0
 def getImages(self):
     if self.CONNECTED:
         sql = "SELECT * FROM image " \
             + "JOIN person ON image.idPerson = person.idPerson " \
             + "JOIN camera ON image.idCamera = camera.idCamera " \
             + "JOIN location ON location.idLocation = camera.idLocation"
         try:
             self.__mycursor.execute(sql)
             rows = self.__mycursor.fetchall()
             results = []
             for row in rows:
                 person = object_DL.Person(id=row['idPerson'],
                                           name=row['name'],
                                           age=row['age'],
                                           gender=row['gender'],
                                           idcode=row['idCode'],
                                           embedding=row['embedding'],
                                           b64face=row['b64Face'],
                                           b64image=row['b64Image'])
                 location = object_DL.Location(id=row['idLocation'],
                                               longtitude=row['longtitude'],
                                               latitude=row['latitude'],
                                               location=row['location'])
                 camera = object_DL.Camera(id=row['idCamera'],
                                           cameraname=row['cameraName'],
                                           httpurl=row['HTTPUrl'],
                                           rstpurl=row['RSTPUrl'],
                                           location=location)
                 image = object_DL.Image(id=row['idImage'],
                                         person=person,
                                         camera=camera,
                                         time=row['time'],
                                         b64image=row['b64Image'],
                                         b64face=row['b64Face'],
                                         embedding=row['embedding'],
                                         istrained=row['isTrained'])
                 results.append(image)
             return results
         except mysql.connector.Error as err:
             logging.exception("ERR in getImages: {}".format(err))
             return None
     return None
Ejemplo n.º 4
0
 def getPersons(self):
     if self.CONNECTED:
         sql = "SELECT * FROM person"
         try:
             self.__mycursor.execute(sql)
             rows = self.__mycursor.fetchall()
             results = []
             for row in rows:
                 person = object_DL.Person(id=row['idPerson'],
                                           name=row['name'],
                                           age=row['age'],
                                           gender=row['gender'],
                                           idcode=row['idCode'],
                                           embedding=row['embedding'],
                                           b64face=row['b64Face'],
                                           b64image=row['b64Image'])
                 results.append(person)
             return results
         except mysql.connector.Error as err:
             logging.exception("ERR in getPersons: {}".format(err))
             return None
     return None
Ejemplo n.º 5
0
                    self.__mydb.commit()
                    return True
                except mysql.connector.Error as err:
                    logging.exception("ERR in updateAllImage: {}".format(err))
                    return False
        return False


# Some func

    def extract_features_labels(self):
        persons = self.getPersons()
        features = []
        labels = []
        for person in persons:
            features.append(
                manage_data.convert_bytes_to_embedding_vector(
                    person.embedding))
            labels.append(person.id)
        return (persons, features, labels)

if __name__ == "__main__":
    test = Database("localhost", "root", "", "faceid")
    p = object_DL.Person(name='test', age=18, gender='female', idcode='123123')
    # rs = test.selectFromPerson(wherePerson=p)
    rows = test.getImages()
    for row in rows:
        print(row.camera.location.location)
    # for row in rows:
    #     print(row.location)
Ejemplo n.º 6
0
 def get_list_person_in_id_order(self, list_id):
     rs = []
     for id in list_id:
         p = object_DL.Person(id=id)
         rs.append(self.selectFromPerson(wherePerson=p)[0])
     return rs
Ejemplo n.º 7
0

# Some func

    def extract_features_and_labels(self):
        all_person = self.selectFromPerson()
        emb_all = []
        label_all = []
        for person in all_person:
            emb_all.append(
                manage_data.convert_bytes_to_embedding_vector(
                    person.embedding))
            label_all.append(person.id)
        return (emb_all, label_all, all_person)

    def get_list_person_in_id_order(self, list_id):
        rs = []
        for id in list_id:
            p = object_DL.Person(id=id)
            rs.append(self.selectFromPerson(wherePerson=p)[0])
        return rs

if __name__ == "__main__":
    test = Database("localhost", "root", "", "faceid")
    p = object_DL.Person()
    p.id = 19
    rs = test.selectFromPerson(wherePerson=p)
    logging.info("Fetch data successfully")
    for person in rs:
        print(person.name)