Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to camera file structure to allow for edge detection capability #39

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def get_jpeg_request(): # 5.2.4.1
"compression": 5,
"camera": 1,
}
url = "http:https://" + args.axis_ip + "/axis-cgi/jpg/image.cgi"
global args

url = 'http:https://' + args.axis_ip + '/axis-cgi/jpg/image.cgi'
start_time = datetime.now()
try:
resp = requests.get(
Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edge-detect/ai/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

17 changes: 12 additions & 5 deletions edge-detect/ai/datasets2.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,30 +264,37 @@ 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
return 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)
Expand Down
2 changes: 1 addition & 1 deletion edge-detect/ai/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions edge-detect/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions edge-detect/filemover/Dockerfile

This file was deleted.

42 changes: 0 additions & 42 deletions edge-detect/filemover/processFiles.py

This file was deleted.