コード例 #1
0
        def run(self):
            cpt = 0
            connected = False
            if self.rec:
                jpeg_frame = ""
            else:
                # jpeg_frame = pickle.dumps(cv2.imencode('.jpg', self.pic, [cv2.IMWRITE_JPEG_QUALITY, 70])[1].tostring())
                jpeg_frame = base64.b64encode(cv2.imencode('.png', self.pic, [cv2.IMWRITE_PNG_COMPRESSION, 1])[1].tobytes()).decode('ascii')
                # print(jpeg_frame)
            while not connected:

                try:

                    print('[INFO] Connecting to DB mongoengine...')
                    db_client = me.connect(self.db, host=self.host , port=self.port)
                    # db_client = me.connect('test1', host='192.168.0.242', port=27017)
                    # time.sleep(0.05)
                    connected = True
                    print("Nombre en DB")
                    print(self.name)

                    # pickled = codecs.encode(pickle.dumps(item[0]), "base64").decode()
                    if self.name.split(' ')[0] == 'unknown':
                        name = self.name
                        surname = ''
                    else:
                        aux = self.name.split('_')
                        name = aux[0]
                        surname = aux[1]

                    if not self.out:
                        self.addperson2db(name=name, surname=surname, is_recongized=self.rec,
                                    last_in=self.timenow,
                                    picture=jpeg_frame, likelihood=self.likelihood)
                    else:
                        # rutina de salida
                        if PersonRasp.objects():
                            for doc in PersonRasp.objects():
                                if doc['name'] == name and doc['surname'] == surname:
                                    doc.update(set__last_out=self.timenow,
                                                set__is_recongized=self.rec,
                                                set__likelihood=self.likelihood)



                    # time.sleep(0.05)
                    print('[INFO] Connection succed')
                    db_client.close()
                    cpt = 0

                except Exception as e:
                    print(e)
                    # Falta fijar la excepcion
                    print('[INFO] Connection fails')
                    connected = False
                    cpt += 1
                    time.sleep(cpt/10.0 + 1)
                    if cpt > 50:
                        cpt = 1
コード例 #2
0
        def addperson2db(self, name, surname, is_recongized, last_in, picture, likelihood):
            idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
            # only entries, via mongoengine
            if is_recongized:
                PersonRasp(idrasp= idh,name=name, surname=surname, last_in=last_in,
                            is_recognized=is_recongized, likelihood=likelihood).save()

            else:
                PersonRasp(idrasp= idh,name=name, surname=surname, last_in=last_in,
                            is_recognized=is_recongized, likelihood=likelihood,
                            picture=picture).save()
コード例 #3
0
def addperson2db(name, surname, is_recongized, last_in, last_out, picture, likehood):
	idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
	if last_out == "":

		#PersonRasp(idrasp=idh,name=name, surname=surname, last_out=last_out,is_recognized=is_recongized, likelihood=likehood).save()

		if is_recongized:
			PersonRasp(idrasp= idh,name=name, surname=surname, last_in=last_in,
						is_recognized=is_recongized, likelihood=likehood).save()

		else:
			PersonRasp(idrasp= idh,name=name, surname=surname, last_in=last_in,
						is_recognized=is_recongized, likelihood=likehood,
						picture=picture).save()
コード例 #4
0
    def tomongo(self):
        cpt = 0
        connected = False
        while not connected:

            try:

                print('[INFO] Searching for unkown in Mongo...')
                db_client = me.connect(self.db, host=self.host, port=self.port)
                for doc in PersonRasp.objects():
                    for docweb in self.data:
                        if doc.Idrasp in docweb['idlist']:
                            self.newnames.append(
                                [doc.name, (docweb.name, docweb.surname)])

                connected = True
                # print(f'New names: {self.newnames}')
                print('[INFO] Connection succed')
                db_client.close()
                cpt = 0

            except Exception as e:
                print(e)
                # Falta fijar la excepcion
                print('[INFO] CheckDB - Connection fails')
                connected = False
                cpt += 1
                time.sleep(cpt / 10.0 + 1)
                if cpt > 50:
                    cpt = 1
コード例 #5
0
 def addperson2db(self, name, surname):
     idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
     # only entries, via mongoengine
     PersonRasp(idrasp=idh,
                name=name,
                surname=surname,
                is_recognized=True,
                is_trained=True).save()
コード例 #6
0
def addperson2db(col, emb, rgb, rec=False, lh=0):
    # name is
    idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
    PersonRasp(idrasp=idh,
               last_in=dt.datetime.utcnow,
               is_recognized=rec,
               seralize_pic=emb,
               picture=str(rgb),
               likelihood=lh).save()
    if rec == False:
        mail1 = SendMail(user=user,
                         password=password,
                         receiver=receiver_email,
                         id=idh,
                         col=col)
        mail1.setmessage('content.txt')
        buffer = io.BytesIO()
        plt.imsave(buffer, rgb)
        mail1.attach_bytes(buffer.getbuffer(), 'unknown.png')
        mail1.start()
    return idh
コード例 #7
0
import mongoengine as me
import time
from User.User import PersonRasp
c = 0
erase = True
while erase:

    try:
        me.connect('Rasp', host='127.0.0.1', port=27017)
        for doc in PersonRasp.objects():
            if doc.surname == "campeny":
                doc.delete()
        erase = False
    except Exception as e:
        print(e)
        print("Unknown cleaning fails...")
        c += 1
        time.sleep(0.01)
        if c > 50:
            print("Couldt connect to mongo")
            erase = False
コード例 #8
0
    def run(self):

        waiting2connect = False

        while not self.stopped or len(self.queue) > 0:
            c = 0
            while not waiting2connect and len(self.queue) > 0:
                elem = ""
                try:
                    db_client = me.connect(self.db,
                                           host=self.host,
                                           port=self.port)
                    waiting2connect = True
                    elem = self.queue.popleft()
                    if len(elem) > 2:
                        likelihood, pic, rec, out, inn, rawname, timenow = elem
                        if rec:
                            jpeg_frame = ""
                        else:
                            # jpeg_frame = pickle.dumps(cv2.imencode('.jpg', self.pic, [cv2.IMWRITE_JPEG_QUALITY, 70])[1].tostring())
                            jpeg_frame = base64.b64encode(
                                cv2.imencode('.png', pic,
                                             [cv2.IMWRITE_PNG_COMPRESSION, 1
                                              ])[1].tobytes()).decode('ascii')
                            # print(jpeg_frame)

                        if rawname.split(' ')[0] == 'unknown':
                            name = rawname
                            surname = ''
                        else:
                            aux = rawname.split('_')
                            name = aux[0]
                            surname = aux[1]

                        if not out:
                            self.addperson2db(name=name,
                                              surname=surname,
                                              is_recongized=rec,
                                              last_in=timenow,
                                              picture=jpeg_frame,
                                              likelihood=likelihood)
                        else:
                            # rutina de salida
                            if PersonRasp.objects():
                                for doc in PersonRasp.objects():
                                    if doc['name'] == name and doc[
                                            'surname'] == surname:
                                        doc.update(set__last_out=timenow,
                                                   set__is_recongized=rec,
                                                   set__likelihood=likelihood)
                    else:
                        # reg mode
                        name, surname = elem
                        self.addperson2dbregmode(name=name, surname=surname)
                    # time.sleep(0.05)
                    print('[INFO] Connection succed')

                except Exception as e:
                    print(e)
                    # Falta fijar la excepcion
                    print('[INFO] Connection fails')
                    c += 1
                    time.sleep(0.01)
                    waiting2connect = False
                    if elem:
                        self.queue.appendleft(elem)
                    if c > 15:
                        waiting2connect = True

            try:
                response = requests.get('https://www.google.com/')
                waiting2connect = False
            except:
                print('no internet')
                time.sleep(5)
コード例 #9
0
from User.User import PersonRasp
import datetime as dt
import hashlib
import io
import time
import pickle
import mongoengine as me
import numpy
from pymongo import ReadPreference
import time
## Connect to DBs
# Connection to mongoengine DB Rasp
# me.connect('Rasp', host='grupo14.duckdns.org', port=1226)
# me.connect('Rasp',read_preference=ReadPreference.PRIMARY)
idh = hashlib.sha256(str(time.time()).encode()).hexdigest()
PersonRasp(idrasp=idh,
           last_in=dt.datetime.utcnow,
           is_recognized=False,
           likelihood=0.85,
           name='Max',
           surname='Rivera').save()
me.connect('Rasp')
while True:
    time.sleep(1)
    print('1')
    continue