Update camera image parser

This commit is contained in:
Cole Deck 2024-04-19 09:43:43 -05:00
parent 275cbd027e
commit 660fe29236
2 changed files with 27 additions and 13 deletions

View File

@ -40,13 +40,16 @@ class DriveImg():
self.onLine = False self.onLine = False
fprint("Offline") fprint("Offline")
def close(self):
self.trans.close()
def read_img(self): def read_img(self):
resposta = 'Falha' resposta = 'Falha'
try: try:
if not self.onLine: if not self.onLine:
#print(f'tentando Conectar camera {self.ip}...') #print(f'tentando Conectar camera {self.ip}...')
gravaLog(ip=self.ip,msg=f'Trying to connect...') gravaLog(ip=self.ip,msg=f'Trying to connect...')
sleep(2) #sleep(2)
try: try:
self.trans = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.trans = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.trans.connect((self.ip,self.PORT)) self.trans.connect((self.ip,self.PORT))
@ -63,13 +66,13 @@ class DriveImg():
if valida.find("TC IMAGE")<0: if valida.find("TC IMAGE")<0:
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
sleep(2) #sleep(2)
gravaLog(ip=self.ip,tipo="Falha",msg=f'Unable to find TC IMAGE bookmark') gravaLog(ip=self.ip,tipo="Falha",msg=f'Unable to find TC IMAGE bookmark')
return "Error" return "Error"
except Exception as ex: except Exception as ex:
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
sleep(2) #sleep(2)
gravaLog(ip=self.ip,tipo="Falha",msg=f'Error - {str(ex)}') gravaLog(ip=self.ip,tipo="Falha",msg=f'Error - {str(ex)}')
return "Error" return "Error"
if ret: if ret:
@ -113,7 +116,7 @@ class DriveImg():
#print(f'erro {str(ex)}') #print(f'erro {str(ex)}')
self.onLine = False self.onLine = False
self.trans.close() self.trans.close()
sleep(2) #sleep(2)
return resposta return resposta
class DriveData(): class DriveData():
@ -139,7 +142,7 @@ class DriveData():
if not self.onLine: if not self.onLine:
#print(f'tentando Conectar...\n') #print(f'tentando Conectar...\n')
gravaLog(ip=self.ip,msg=f'tentando Conectar...',file="log_data.txt") gravaLog(ip=self.ip,msg=f'tentando Conectar...',file="log_data.txt")
sleep(2) #sleep(2)
try: try:
self.trans = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.trans = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.trans.connect((self.ip,self.PORT)) self.trans.connect((self.ip,self.PORT))
@ -154,7 +157,7 @@ class DriveData():
except Exception as ex: except Exception as ex:
self.onLine = False self.onLine = False
gravaLog(ip=self.ip,tipo="Falha Generica",msg=f'erro {str(ex)}',file="log_data.txt") gravaLog(ip=self.ip,tipo="Falha Generica",msg=f'erro {str(ex)}',file="log_data.txt")
sleep(2) #sleep(2)
return resposta return resposta

View File

@ -8,13 +8,18 @@ from util import fprint
class qr_reader(): class qr_reader():
camera = None camera = None
def __init__(self, ip, port): def __init__(self, ip, port):
self.camera = banner_ivu_export.DriveImg(ip, port) self.ip = ip
self.port = port
#self.camera = banner_ivu_export.DriveImg(ip, port)
def read_qr(self, tries=1): def read_qr(self, tries=1):
print("Trying " + str(tries) + " frames.") print("Trying " + str(tries) + " frames.")
self.camera = banner_ivu_export.DriveImg(self.ip, self.port)
for x in range(tries): for x in range(tries):
try: print(str(x) + " ", end="", flush=True)
imgtype, img = self.camera.read_img() imgtype, img = self.camera.read_img()
if True:
#fprint(imgtype) #fprint(imgtype)
image_array = np.frombuffer(img, np.uint8) image_array = np.frombuffer(img, np.uint8)
img = cv2.imdecode(image_array, cv2.IMREAD_COLOR) img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
@ -22,9 +27,13 @@ class qr_reader():
#cv2.waitKey(1) #cv2.waitKey(1)
detect = cv2.QRCodeDetector() detect = cv2.QRCodeDetector()
value, points, straight_qrcode = detect.detectAndDecode(img) value, points, straight_qrcode = detect.detectAndDecode(img)
return value
except: if value != "":
continue self.camera.close()
return value
self.camera.close()
return False return False
@ -41,5 +50,7 @@ class video_streamer():
if __name__ == "__main__": if __name__ == "__main__":
test = qr_reader("192.168.1.125", 32200) test = qr_reader("192.168.1.125", 32200)
import time
while True: while True:
fprint(test.read_qr(5)) fprint(test.read_qr(300))
time.sleep(1)