This commit is contained in:
The Bears
2025-10-31 21:15:14 -04:00
parent 09ed1b8c97
commit d3f2c5e170
6 changed files with 378 additions and 8 deletions

View File

@@ -30,14 +30,45 @@ import json
import redis
import os
pfm = LogColorize.score_obj_det_embed
# %%
with open('/home/thebears/source/infer/species_list','r') as sl:
species_list = [x for x in sl.read().split('\n') if len(x) > 0]
r = redis.Redis('localhost',port=6379, db=14)
logger = logging.getLogger('live_inference')
def get_snap( url, username, password, proxies = None, timeout=5, save_image = None, camera_name = 'N/A'):
data = {
'cmd': 'Snap',
'channel': 0,
'rs': ''.join(choices(string.ascii_uppercase + string.digits, k=10)),
'snapType':'sub',
'user': username,
'password': password,
}
parms = parse.urlencode(data, safe="!").encode("utf-8")
try:
response = requests.get(url, proxies=proxies, params=parms, timeout=timeout)
if response.status_code == 200:
rearr = np.frombuffer(bytearray(response.content), dtype=np.uint8)
img_bgr = cv2.imdecode(rearr,cv2.IMREAD_COLOR)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
if save_image is not None:
os.makedirs(os.path.dirname(save_image), exist_ok=True)
cv2.imwrite( save_image, img_bgr)
logging.info(f'{camera_name}: Wrote image to {save_image}')
logging.info(f'{camera_name}: Got image of {img_rgb.shape}')
return img_rgb
except Exception as e:
logging.error(f'{camera_name} failure: {str(e)}')
raise
# %%
def resize_image(img_in, reshape_to_final=False):
if not isinstance(img_in, np.ndarray):
img_in = np.asarray(img_in)
@@ -153,7 +184,7 @@ class SnapManager():
self.password = password
self.camera_name = camera_name
self.split_into_two = split_into_two
n self.msg_queue = msg_queue
self.msg_queue = msg_queue
self.img_scoring_queue = img_scoring_queue
logger.info(f"{self.camera_name}: initialized")
@@ -187,21 +218,18 @@ n self.msg_queue = msg_queue
return msg
def capture_and_prepare(self):
img = get_snap(self.username, self.password, self.url_api, self.camera_name)
img = get_snap(self.url_api,self.username, self.password, camera_name = self.camera_name)
if img is not None:
timestamp = time.time()
return self.format_image_for_model(img, timestamp)
return []
def run_forever(self):
while True:
try:
msg = self.msg_queue.get(timeout=0.1)
if msg == 'exit':
break
if msg == 'save_image':
if msg == 'get':
logger.info(f'Processing capture for {self.camera_name}')
model_msgs = self.capture_and_prepare()