Add system controller camera mode
This commit is contained in:
parent
faf4cc1ba8
commit
24e0094d2a
@ -4,39 +4,54 @@ import cv2
|
|||||||
import banner_ivu_export
|
import banner_ivu_export
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from util import fprint
|
from util import fprint
|
||||||
|
import requests
|
||||||
|
|
||||||
class qr_reader():
|
class qr_reader():
|
||||||
camera = None
|
camera = None
|
||||||
def __init__(self, ip, port):
|
def __init__(self, ip, port):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.url = "http://" + ip + ":" + str(port) + "/barcode"
|
||||||
#self.camera = banner_ivu_export.DriveImg(ip, port)
|
#self.camera = banner_ivu_export.DriveImg(ip, port)
|
||||||
|
|
||||||
|
# def read_qr(self, tries=1):
|
||||||
|
# print("Trying " + str(tries) + " frames.")
|
||||||
|
# self.camera = banner_ivu_export.DriveImg(self.ip, self.port)
|
||||||
|
# for x in range(tries):
|
||||||
|
# print(str(x) + " ", end="", flush=True)
|
||||||
|
# imgtype, img = self.camera.read_img()
|
||||||
|
|
||||||
|
# if img is not None:
|
||||||
|
# #fprint(imgtype)
|
||||||
|
# image_array = np.frombuffer(img, np.uint8)
|
||||||
|
# img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
|
||||||
|
# #cv2.imshow('Image', img)
|
||||||
|
# #cv2.waitKey(1)
|
||||||
|
# detect = cv2.QRCodeDetector()
|
||||||
|
# value, points, straight_qrcode = detect.detectAndDecode(img)
|
||||||
|
|
||||||
|
# if value != "":
|
||||||
|
# self.camera.close()
|
||||||
|
# return value
|
||||||
|
# else:
|
||||||
|
# print("\nGot no image for " + str(x))
|
||||||
|
|
||||||
|
# self.camera.close()
|
||||||
|
# return False
|
||||||
def read_qr(self, tries=1):
|
def read_qr(self, tries=1):
|
||||||
print("Trying " + str(tries) + " frames.")
|
try:
|
||||||
self.camera = banner_ivu_export.DriveImg(self.ip, self.port)
|
response = requests.get(self.url, timeout=tries * 15)
|
||||||
for x in range(tries):
|
response.raise_for_status() # Raise an error for bad status codes
|
||||||
print(str(x) + " ", end="", flush=True)
|
print(response.text) # Or handle the response as needed
|
||||||
imgtype, img = self.camera.read_img()
|
if len(response.text < 8):
|
||||||
|
|
||||||
if img is not None:
|
|
||||||
#fprint(imgtype)
|
|
||||||
image_array = np.frombuffer(img, np.uint8)
|
|
||||||
img = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
|
|
||||||
#cv2.imshow('Image', img)
|
|
||||||
#cv2.waitKey(1)
|
|
||||||
detect = cv2.QRCodeDetector()
|
|
||||||
value, points, straight_qrcode = detect.detectAndDecode(img)
|
|
||||||
|
|
||||||
if value != "":
|
|
||||||
self.camera.close()
|
|
||||||
return value
|
|
||||||
else:
|
|
||||||
print("\nGot no image for " + str(x))
|
|
||||||
|
|
||||||
self.camera.close()
|
|
||||||
return False
|
return False
|
||||||
|
return response.text
|
||||||
|
except requests.Timeout:
|
||||||
|
print(f'The request timed out after {tries * 15} seconds')
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f'An error occurred: {e}')
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
class video_streamer():
|
class video_streamer():
|
||||||
camera = None
|
camera = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user