diff --git a/axis-ptz/camera.py b/axis-ptz/camera.py index f1ca3e0..8c3737a 100755 --- a/axis-ptz/camera.py +++ b/axis-ptz/camera.py @@ -118,7 +118,9 @@ def get_jpeg_request(): # 5.2.4.1 "compression": 5, "camera": 1, } - url = "http://" + args.axis_ip + "/axis-cgi/jpg/image.cgi" + global args + + url = 'http://' + args.axis_ip + '/axis-cgi/jpg/image.cgi' start_time = datetime.now() try: resp = requests.get( @@ -133,7 +135,12 @@ def get_jpeg_request(): # 5.2.4.1 disk_time = datetime.now() if resp.status_code == 200: - captureDir = "capture/{}".format(currentPlane["type"]) + captureDir = None + + if args.flat_file_structure: + captureDir = "capture/" + else: + captureDir = "capture/{}".format(currentPlane["type"]) try: os.makedirs(captureDir) except OSError as e: @@ -765,7 +772,18 @@ def main(): help="The zoom setting for the camera (0-9999)", default=9999, ) - parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") + parser.add_argument( + "-v", + "--verbose", + action="store_true", + help="Verbose output" + ) + parser.add_argument( + '-f', + '--flat-file-structure', + action='store_true', + help="Use a flat file structure (all images saved to ./) rather than organizing images in folder by plane type." + ) args = parser.parse_args() diff --git a/docker-compose.yml b/docker-compose.yml index 6441fd7..122d390 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: image: iqtlabs/skyscan-axis-ptz command: "./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY} --lat ${LAT} --lon ${LONG} --alt ${ALT}" volumes: - - ./capture:/app/capture + - /flash/raw:/app/capture depends_on: - mqtt restart: unless-stopped diff --git a/edge-detect/ai/Dockerfile b/edge-detect/ai/Dockerfile index ecc754e..c9a1c6a 100644 --- a/edge-detect/ai/Dockerfile +++ b/edge-detect/ai/Dockerfile @@ -31,5 +31,5 @@ CMD ["bash", "-c", "python sort.py \ --plane-dir ../data/plane \ --noplane-dir ../data/noplane \ --log-dir ../data/log \ ---save-json"] +--save-json" ] diff --git a/edge-detect/ai/datasets2.py b/edge-detect/ai/datasets2.py index 44e14e2..911e76d 100644 --- a/edge-detect/ai/datasets2.py +++ b/edge-detect/ai/datasets2.py @@ -264,11 +264,12 @@ def __len__(self): class LoadFromDir: # for inference - def __init__(self, path, img_size=640, stride=32): + def __init__(self, path, img_size=640, stride=32, log_dir="/data/log"): self.path = path self.img_size = img_size self.stride = stride self.mode = 'image' + self.log_dir = log_dir def __iter__(self): self.count = 0 @@ -276,18 +277,24 @@ def __iter__(self): def __next__(self): # Check for files in folder, waiting if necessary + img0 = None + img_path = None while True: if os.path.isdir(self.path): img_paths = glob.glob(os.path.join(self.path, '*')) if len(img_paths) > 0: - break + img_path = min(img_paths, key=os.path.getctime) + img0 = cv2.imread(img_path) + if os.path.isdir(img_path) or img0 is None: + print("Found non-file object ... moving to logs") + base_folder = os.path.basename(img_path) + shutil.move(img_path, os.path.join(self.log_dir, base_folder)) + else: + break time.sleep(0.5) - img_path = min(img_paths, key=os.path.getctime) # Process image self.count += 1 - img0 = cv2.imread(img_path) - assert img0 is not None, 'Image Not Found ' + img_path img = letterbox(img0, self.img_size, stride=self.stride)[0] # Size img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, channel first img = np.ascontiguousarray(img) diff --git a/edge-detect/ai/sort.py b/edge-detect/ai/sort.py index bfafa84..5ead40b 100644 --- a/edge-detect/ai/sort.py +++ b/edge-detect/ai/sort.py @@ -58,7 +58,7 @@ def dirsort(save_img=False): watch_dir = True vid_path, vid_writer = None, None if watch_dir: - dataset = LoadFromDir(source, img_size=imgsz, stride=stride) + dataset = LoadFromDir(source, img_size=imgsz, stride=stride, log_dir=opt.log_dir) elif webcam: view_img = check_imshow() cudnn.benchmark = True # set True to speed up constant image size inference diff --git a/edge-detect/docker-compose.yml b/edge-detect/docker-compose.yml index 73384ad..ee829c2 100644 --- a/edge-detect/docker-compose.yml +++ b/edge-detect/docker-compose.yml @@ -3,22 +3,13 @@ version: '3.7' services: skyscan-edge: build: ./ai/ - command: "python sort.py --weights ../data/weights/localizer.pt --agnostic-nms --nosave --conf 0.25 --img-size 640 --device cpu --source-dir ../data/tosort --plane-dir ../data/plane --noplane-dir ../data/noplane --log-dir ../data/log --save-json" + command: "python sort.py --weights ../data/weights/localizer.pt --agnostic-nms --nosave --conf 0.25 --img-size 640 --device cpu --source-dir ../data/tosort --plane-dir ../data/plane --noplane-dir ../data/noplane --log-dir ../data/log --save-json & python processFiles.py" + environment: + - "HOSTNAME=${HOSTNAME}" volumes: - ./weights:/data/weights/ - - /flash/unprocessed:/data/tosort + - /flash/raw:/data/tosort - /flash/processed/plane:/data/plane - /flash/processed/noplane:/data/noplane - /flash/processed/log:/data/log restart: unless-stopped - - file-utils: - build: ./filemover/ - hostname: SkyScan-pinephonepro - command: "python3 processFiles.py" - environment: - - "HOSTNAME=${HOSTNAME}" - volumes: - - /flash/raw:/flash/raw - - /flash/unprocessed:/flash/unprocessed - restart: unless-stopped diff --git a/edge-detect/filemover/Dockerfile b/edge-detect/filemover/Dockerfile deleted file mode 100644 index c8c6db4..0000000 --- a/edge-detect/filemover/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM python:3.11-slim -COPY processFiles.py /processFiles.py -ENTRYPOINT ["python3", "/processFiles.py"] \ No newline at end of file diff --git a/edge-detect/filemover/processFiles.py b/edge-detect/filemover/processFiles.py deleted file mode 100644 index c6a11b9..0000000 --- a/edge-detect/filemover/processFiles.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 -import time -import os -import shutil -import socket -hostname = socket.gethostname() - -directory = '/flash/raw' -dumpdirectory = '/flash/unprocessed' - -path = '' -fname = '' - - -def processFile(path): -# try: - if True: - fileList = os.listdir(path) - for fname in fileList: - if os.path.isdir(os.path.join(path, fname)): - print('PATH IS A DIRECTORY: '+os.path.join(path, fname)) - processFile(os.path.join(path, fname)) - else: - newfname = fname.split('.')[0] + '_' + hostname + '.' + fname.split('.')[1] - shutil.move(os.path.join(path, fname), os.path.join(dumpdirectory, newfname)) - time.sleep(0.01) - os.rmdir(path) -# except: -# print('Ran into error | path: '+path+' | file: '+fname + ' |') -# time.sleep(1) - - -while True: - dir_list = [x[0] for x in os.walk(directory)] - dir_list[:] = (value for value in dir_list if value != directory) - for path in dir_list: - print('Processing Path: '+path) - processFile(path) - time.sleep(5) - -