refactor(cli): remove docopt dependency
This commit is contained in:
parent
3919519e50
commit
fa4c7eef03
100
camera/cli.py
100
camera/cli.py
@ -1,31 +1,8 @@
|
|||||||
"""
|
|
||||||
Publish data from oak-lite device
|
|
||||||
|
|
||||||
Usage: rc-oak-camera [-u USERNAME | --mqtt-username=USERNAME] [--mqtt-password=PASSWORD] \
|
|
||||||
[--mqtt-broker-host=HOSTNAME] [--mqtt-broker-port=PORT] \
|
|
||||||
[--mqtt-topic-robocar-oak-camera="TOPIC_CAMERA"] [--mqtt-topic-robocar-objects="TOPIC_OBJECTS"] \
|
|
||||||
[--mqtt-client-id=CLIENT_ID] \
|
|
||||||
[-H IMG_HEIGHT | --image-height=IMG_HEIGHT] [-W IMG_WIDTH | --image-width=IMG_width] \
|
|
||||||
[-t OBJECTS_THRESHOLD | --objects-threshold=OBJECTS_THRESHOLD]
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-h --help Show this screen.
|
|
||||||
-u USERID --mqtt-username=USERNAME MQTT user
|
|
||||||
-p PASSWORD --mqtt-password=PASSWORD MQTT password
|
|
||||||
-b HOSTNAME --mqtt-broker-host=HOSTNAME MQTT broker host
|
|
||||||
-P HOSTNAME --mqtt-broker-port=PORT MQTT broker port
|
|
||||||
-C CLIENT_ID --mqtt-client-id=CLIENT_ID MQTT client id
|
|
||||||
-c TOPIC_CAMERA --mqtt-topic-robocar-oak-camera=TOPIC_CAMERA MQTT topic where to publish robocar-oak-camera frames
|
|
||||||
-o TOPIC_OBJECTS --mqtt-topic-robocar-objects=TOPIC_OBJECTS MQTT topic where to publish objects detection results
|
|
||||||
-H IMG_HEIGHT --image-height=IMG_HEIGHT IMG_HEIGHT image height
|
|
||||||
-W IMG_WIDTH --image-width=IMG_width IMG_WIDTH image width
|
|
||||||
-t OBJECTS_THRESHOLD --objects-threshold=OBJECTS_THRESHOLD OBJECTS_THRESHOLD threshold to filter objects detected
|
|
||||||
"""
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from . import depthai as cam
|
from . import depthai as cam
|
||||||
from docopt import docopt
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
import argparse
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@ -47,31 +24,68 @@ def init_mqtt_client(broker_host: str, broker_port, user: str, password: str, cl
|
|||||||
def execute_from_command_line():
|
def execute_from_command_line():
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
args = docopt(__doc__)
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-u", "--mqtt-username",
|
||||||
|
help="MQTT user",
|
||||||
|
default=_get_env_value("MQTT_USERNAME", ""))
|
||||||
|
parser.add_argument("-p", "--mqtt-password",
|
||||||
|
help="MQTT password",
|
||||||
|
default=_get_env_value("MQTT_PASSWORD", ""))
|
||||||
|
parser.add_argument("-b", "--mqtt-broker-host",
|
||||||
|
help="MQTT broker host",
|
||||||
|
default=_get_env_value("MQTT_BROKER_HOST", "localhost"))
|
||||||
|
parser.add_argument("-P", "--mqtt-broker-port",
|
||||||
|
help="MQTT broker port",
|
||||||
|
type=int,
|
||||||
|
default=_get_env_int_value("MQTT_BROKER_PORT", 1883))
|
||||||
|
parser.add_argument("-C", "--mqtt-client-id",
|
||||||
|
help="MQTT client id",
|
||||||
|
default=_get_env_value("MQTT_CLIENT_ID", default_client_id))
|
||||||
|
parser.add_argument("-c", "--mqtt-topic-robocar-oak-camera",
|
||||||
|
help="MQTT topic where to publish robocar-oak-camera frames",
|
||||||
|
default=_get_env_value("MQTT_TOPIC_CAMERA","/oak/camera_rgb"))
|
||||||
|
parser.add_argument("-o", "---mqtt-topic-robocar-objects",
|
||||||
|
help="MQTT topic where to publish objects detection results",
|
||||||
|
default=_get_env_value("MQTT_TOPIC_OBJECTS", "/objects"))
|
||||||
|
parser.add_argument("-t", "--objects-threshold",
|
||||||
|
help="threshold to filter detected objects",
|
||||||
|
type=float,
|
||||||
|
default=_get_env_float_value("OBJECTS_THRESHOLD", 0.2))
|
||||||
|
parser.add_argument("-H", "--image-height", help="image height",
|
||||||
|
type=int,
|
||||||
|
default=_get_env_int_value("IMAGE_HEIGHT", 120))
|
||||||
|
parser.add_argument("-W", "--image-width", help="image width",
|
||||||
|
type=int,
|
||||||
|
default=_get_env_int_value("IMAGE_WIDTH", 126))
|
||||||
|
|
||||||
client = init_mqtt_client(broker_host=get_default_value(args["--mqtt-broker-host"], "MQTT_BROKER_HOST", "localhost"),
|
args = parser.parse_args()
|
||||||
broker_port=int(get_default_value(args["--mqtt-broker-port"], "MQTT_BROKER_PORT", "1883")),
|
|
||||||
user=get_default_value(args["--mqtt-username"], "MQTT_USERNAME", ""),
|
client = init_mqtt_client(broker_host=args.mqtt_broker_host,
|
||||||
password=get_default_value(args["--mqtt-password"], "MQTT_PASSWORD", ""),
|
broker_port=args.mqtt_broker_port,
|
||||||
client_id=get_default_value(args["--mqtt-client-id"], "MQTT_CLIENT_ID",
|
user=args.mqtt_username,
|
||||||
default_client_id),
|
password=args.mqtt_password,
|
||||||
|
client_id=args.mqtt_client_id,
|
||||||
)
|
)
|
||||||
frame_topic = get_default_value(args["--mqtt-topic-robocar-oak-camera"], "MQTT_TOPIC_CAMERA", "/oak/camera_rgb")
|
|
||||||
objects_topic = get_default_value(args["--mqtt-topic-robocar-objects"], "MQTT_TOPIC_OBJECTS", "/objects")
|
|
||||||
|
|
||||||
frame_processor = cam.FramePublisher(mqtt_client=client,
|
frame_processor = cam.FramePublisher(mqtt_client=client,
|
||||||
frame_topic=frame_topic,
|
frame_topic=args.mqtt_topic_robocar_oak_camera,
|
||||||
objects_topic=objects_topic,
|
objects_topic=args.mqtt_topic_robocar_objects,
|
||||||
objects_threshold=float(get_default_value(args["--objects-threshold"],
|
objects_threshold=args.objects_threshold,
|
||||||
"OBJECTS_THRESHOLD", 0.2)),
|
img_width=args.image_width,
|
||||||
img_width=int(get_default_value(args["--image-width"], "IMAGE_WIDTH", 160)),
|
img_height=args.image_height)
|
||||||
img_height=int(get_default_value(args["--image-height"], "IMAGE_HEIGHT", 120)))
|
|
||||||
frame_processor.run()
|
frame_processor.run()
|
||||||
|
|
||||||
|
|
||||||
def get_default_value(value, env_var: str, default_value) -> str:
|
def _get_env_value(env_var: str, default_value: str) -> str:
|
||||||
if value:
|
|
||||||
return value
|
|
||||||
if env_var in os.environ:
|
if env_var in os.environ:
|
||||||
return os.environ[env_var]
|
return os.environ[env_var]
|
||||||
return default_value
|
return default_value
|
||||||
|
|
||||||
|
|
||||||
|
def _get_env_int_value(env_var: str, default_value: int) -> int:
|
||||||
|
value = _get_env_value(env_var, str(default_value))
|
||||||
|
return int(value)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_env_float_value(env_var: str, default_value: float) -> float:
|
||||||
|
value = _get_env_value(env_var, str(default_value))
|
||||||
|
return float(value)
|
||||||
|
13
poetry.lock
generated
13
poetry.lock
generated
@ -107,14 +107,6 @@ category = "main"
|
|||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.6"
|
python-versions = ">=3.6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "docopt"
|
|
||||||
version = "0.6.2"
|
|
||||||
description = "Pythonic argument parser, that will make you smile"
|
|
||||||
category = "main"
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "google"
|
name = "google"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
@ -354,7 +346,7 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "93f922ddb9c03189bf1efabdcf702513ff5526332a78f54c21ab532574f4519a"
|
content-hash = "b165038947d8a9e0e256c91b449c4cbd1e65ccfd0e65f271d002fc8e21e2640e"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
attrs = [
|
attrs = [
|
||||||
@ -421,9 +413,6 @@ depthai = [
|
|||||||
{file = "depthai-2.17.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:de7b5e4a15b0a9e15fdf19c5388e6aa9629ecc25a955675d400173f9a2dd199b"},
|
{file = "depthai-2.17.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:de7b5e4a15b0a9e15fdf19c5388e6aa9629ecc25a955675d400173f9a2dd199b"},
|
||||||
{file = "depthai-2.17.4.0.tar.gz", hash = "sha256:b8e3c2eaa643c64e737435adaa23d54e3fda58baad1477f5176908689473a85f"},
|
{file = "depthai-2.17.4.0.tar.gz", hash = "sha256:b8e3c2eaa643c64e737435adaa23d54e3fda58baad1477f5176908689473a85f"},
|
||||||
]
|
]
|
||||||
docopt = [
|
|
||||||
{file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"},
|
|
||||||
]
|
|
||||||
google = [
|
google = [
|
||||||
{file = "google-3.0.0-py2.py3-none-any.whl", hash = "sha256:889cf695f84e4ae2c55fbc0cfdaf4c1e729417fa52ab1db0485202ba173e4935"},
|
{file = "google-3.0.0-py2.py3-none-any.whl", hash = "sha256:889cf695f84e4ae2c55fbc0cfdaf4c1e729417fa52ab1db0485202ba173e4935"},
|
||||||
{file = "google-3.0.0.tar.gz", hash = "sha256:143530122ee5130509ad5e989f0512f7cb218b2d4eddbafbad40fd10e8d8ccbe"},
|
{file = "google-3.0.0.tar.gz", hash = "sha256:143530122ee5130509ad5e989f0512f7cb218b2d4eddbafbad40fd10e8d8ccbe"},
|
||||||
|
@ -12,7 +12,6 @@ packages = [
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
paho-mqtt = "^1.6.1"
|
paho-mqtt = "^1.6.1"
|
||||||
docopt = "^0.6.2"
|
|
||||||
depthai = "^2.17.4.0"
|
depthai = "^2.17.4.0"
|
||||||
protobuf3 = "^0.2.1"
|
protobuf3 = "^0.2.1"
|
||||||
google = "^3.0.0"
|
google = "^3.0.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user