Commit edc39d65 authored by Your Name's avatar Your Name

opendatacam updates

parent efa90a1c
apiVersion: v1
kind: Service
metadata:
labels:
app: opendatacam
name: opendatacam-mongo
spec:
ports:
- name: "27017"
port: 27017
targetPort: 27017
selector:
app: opendatacam
tier: mongo
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongodb-pv-claim
labels:
app: opendatacam
spec:
storageClassName: nfs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv
labels:
app: opendatacam
spec:
volumeMode: Filesystem
storageClassName: nfs
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
persistentVolumeReclaimPolicy: Retain
mountOptions:
- hard
- nfsvers=3
nfs:
path: /home/llh/opendatacamNFS
server: 192.168.1.230
readOnly: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: opendatacam-mongo
labels:
app: opendatacam
spec:
replicas: 1
selector:
matchLabels:
app: opendatacam
tier: mongo
strategy:
type: Recreate
template:
metadata:
labels:
app: opendatacam
tier: mongo
spec:
containers:
- name: mongo
image: mongo
imagePullPolicy: ""
# command: [ "/bin/bash"]
# args: ["-c", "while true; do sleep 10; done;"] # Our simple program just sleeps inside
args: ["--dbpath","/root/db"]
ports:
- containerPort: 27017
resources: {}
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-creds
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-creds
key: password
volumeMounts:
- name: mongodb-persistent-storage
mountPath: /root/db
securityContext:
privileged: true
restartPolicy: Always
volumes:
- name: mongodb-persistent-storage
persistentVolumeClaim:
claimName: mongodb-pv-claim
apiVersion: v1
kind: Service
metadata:
labels:
app: opendatacam
name: opendatacam
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
- name: "8070"
port: 8070
targetPort: 8070
- name: "8090"
port: 8090
targetPort: 8090
selector:
app: opendatacam
tier: frontend
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: opendatacam
name: opendatacam
spec:
replicas: 1
selector:
matchLabels:
app: opendatacam
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: opendatacam
tier: frontend
spec:
containers:
- image: opendatacam/opendatacam:v3.0.2-xavier
command: ["/bin/bash"]
args: ["-c", "/var/local/opendatacam/launch.sh"]
name: opendatacam
ports:
- containerPort: 8080
- containerPort: 8070
- containerPort: 8090
resources: {}
securityContext:
privileged: true
volumeMounts:
- name: opendatacam-config
mountPath: /var/local/opendatacam/config.json
subPath: "config.json"
- name: video-source
mountPath: /dev/video0
restartPolicy: Always
volumes:
- name: video-source
hostPath:
path: /dev/video0
- name: opendatacam-config
configMap:
name: opendatacam
items:
- key: config.json
path: config.json
nodeSelector:
kubernetes.io/hostname: neruda
{
"OPENDATACAM_VERSION": "3.0.2",
"PATH_TO_YOLO_DARKNET" : "/var/local/darknet",
"VIDEO_INPUT": "usbcam",
"NEURAL_NETWORK": "yolov4",
"VIDEO_INPUTS_PARAMS": {
"file": "opendatacam_videos/demo.mp4",
"usbcam": "v4l2src device=/dev/video0 ! video/x-raw, framerate=30/1, width=480, height=272 ! videoconvert ! appsink",
"raspberrycam": "nvarguscamerasrc ! video/x-raw(memory:NVMM),width=1280, height=720, framerate=30/1, format=NV12 ! nvvidconv ! video/x-raw, format=BGRx, width=480, height=272 ! videoconvert ! video/x-raw, format=BGR ! appsink",
"remote_cam": "YOUR IP CAM STREAM (can be .m3u8, MJPEG ...), anything supported by opencv",
"remote_hls_gstreamer": "souphttpsrc location=http://YOUR_HLSSTREAM_URL_HERE.m3u8 ! hlsdemux ! decodebin ! videoconvert ! videoscale ! appsink"
},
"TRACKER_SETTINGS": {
"objectMaxAreaInPercentageOfFrame": 80,
"confidence_threshold": 0.2,
"iouLimit": 0.05,
"unMatchedFrameTolerance": 5
},
"COUNTER_SETTINGS": {
"minAngleWithCountingLineThreshold": 5,
"computeTrajectoryBasedOnNbOfPastFrame": 5
},
"VALID_CLASSES": ["*"],
"DISPLAY_CLASSES": [
{ "class": "bicycle", "hexcode": "1F6B2"},
{ "class": "person", "hexcode": "1F6B6"},
{ "class": "truck", "hexcode": "1F69B"},
{ "class": "motorbike", "hexcode": "1F6F5"},
{ "class": "car", "hexcode": "1F697"},
{ "class": "bus", "hexcode": "1F68C"}
],
"PATHFINDER_COLORS": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"COUNTER_COLORS": {
"yellow": "#FFE700",
"turquoise": "#A3FFF4",
"green": "#a0f17f",
"purple": "#d070f0",
"red": "#AB4435"
},
"NEURAL_NETWORK_PARAMS": {
"yolov4": {
"data": "cfg/coco.data",
"cfg": "cfg/yolov4-416x416.cfg",
"weights": "yolov4.weights"
},
"yolov4-tiny": {
"data": "cfg/coco.data",
"cfg": "cfg/yolov4-tiny.cfg",
"weights": "yolov4-tiny.weights"
}
},
"TRACKER_ACCURACY_DISPLAY": {
"nbFrameBuffer": 300,
"settings": {
"radius": 3.1,
"blur": 6.2,
"step": 0.1,
"gradient": {
"0.4":"orange",
"1":"red"
},
"canvasResolutionFactor": 0.1
}
},
"MONGODB_URL": "mongodb://mongo:27017",
"PORTS": {
"app": 8080,
"darknet_json_stream": 8070,
"darknet_mjpeg_stream": 8090
}
}
{
"OPENDATACAM_VERSION": "3.0.2",
"PATH_TO_YOLO_DARKNET" : "TO_REPLACE_PATH_TO_DARKNET",
"VIDEO_INPUT": "file",
"NEURAL_NETWORK": "yolov4-tiny",
"VIDEO_INPUTS_PARAMS": {
"file": "opendatacam_videos/demo.mp4",
"usbcam": "v4l2src device=/dev/video0 ! video/x-raw, framerate=30/1, width=640, height=360 ! videoconvert ! appsink",
"raspberrycam": "nvarguscamerasrc ! video/x-raw(memory:NVMM),width=1280, height=720, framerate=30/1, format=NV12 ! nvvidconv ! video/x-raw, format=BGRx, width=640, height=360 ! videoconvert ! video/x-raw, format=BGR ! appsink",
"remote_cam": "YOUR IP CAM STREAM (can be .m3u8, MJPEG ...), anything supported by opencv",
"remote_hls_gstreamer": "souphttpsrc location=http://YOUR_HLSSTREAM_URL_HERE.m3u8 ! hlsdemux ! decodebin ! videoconvert ! videoscale ! appsink"
},
"TRACKER_SETTINGS": {
"objectMaxAreaInPercentageOfFrame": 80,
"confidence_threshold": 0.2,
"iouLimit": 0.05,
"unMatchedFrameTolerance": 5
},
"COUNTER_SETTINGS": {
"minAngleWithCountingLineThreshold": 5,
"computeTrajectoryBasedOnNbOfPastFrame": 5
},
"VALID_CLASSES": ["*"],
"DISPLAY_CLASSES": [
{ "class": "bicycle", "hexcode": "1F6B2"},
{ "class": "person", "hexcode": "1F6B6"},
{ "class": "truck", "hexcode": "1F69B"},
{ "class": "motorbike", "hexcode": "1F6F5"},
{ "class": "car", "hexcode": "1F697"},
{ "class": "bus", "hexcode": "1F68C"}
],
"PATHFINDER_COLORS": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"COUNTER_COLORS": {
"yellow": "#FFE700",
"turquoise": "#A3FFF4",
"green": "#a0f17f",
"purple": "#d070f0",
"red": "#AB4435"
},
"NEURAL_NETWORK_PARAMS": {
"yolov4": {
"data": "cfg/coco.data",
"cfg": "cfg/yolov4-416x416.cfg",
"weights": "yolov4.weights"
},
"yolov4-tiny": {
"data": "cfg/coco.data",
"cfg": "cfg/yolov4-tiny.cfg",
"weights": "yolov4-tiny.weights"
}
},
"TRACKER_ACCURACY_DISPLAY": {
"nbFrameBuffer": 300,
"settings": {
"radius": 3.1,
"blur": 6.2,
"step": 0.1,
"gradient": {
"0.4":"orange",
"1":"red"
},
"canvasResolutionFactor": 0.1
}
},
"MONGODB_URL": "mongodb://mongo:27017",
"PORTS": {
"app": 8080,
"darknet_json_stream": 8070,
"darknet_mjpeg_stream": 8090
}
}
#!/bin/bash
# exit when any command fails
set -e
# Each OpenDataCam release should set the correct version here and tag appropriatly on github
VERSION=v3.0.2
# PLATFORM in ["nano","xavier","tx2","nvidiadocker"]
PLATFORM=xavier
VIDEO_INPUT=/dev/video0
PLATFORM_OPTIONS=("nano" "xavier" "desktop")
DEFAUT_VIDEO_INPUT_OPTIONS=("opendatacam_videos/demo.mp4" "file" "file")
DEFAUT_NEURAL_NETWORK_OPTIONS=("yolov4-tiny" "yolov4" "yolov4")
ORCHESTRATOR_OPTIONS=("docker-compose" "k8s")
# PATH TO DARKNET in docker container
PATH_DARKNET=/var/local/darknet
echo "Installing OpenDataCam docker image"
display_usage() {
echo
echo "Usage: $0"
echo -n " -p, --platform Specify platform: "
for i in "${PLATFORM_OPTIONS[@]}"
do
echo -n "$i "
done
echo
echo -n " -o, --orchestrator Specify orchestrator: "
for i in "${ORCHESTRATOR_OPTIONS[@]}"
do
echo -n "$i "
done
echo
echo " -h, --help Display usage instructions"
echo
exit
}
raise_error() {
local error_message="$@"
echo "${error_message}" 1>&2;
}
function index(){
local elem=$1
shift
i=0
for word in "$@"
do
if [ "${word}" == "${elem}" ]; then
echo ${i}
fi
let i=${i}+1
done
}
function docker_compose_setup() {
echo "Deploying with Docker Compose"
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "OpenDataCam requires docker-compose, please install and retry"; }
# Get the docker compose file
wget -N https://raw.githubusercontent.com/opendatacam/opendatacam/$VERSION/docker/run/$PLATFORM/docker-compose.yml
echo "Download, install and run opendatacam docker container"
sudo docker-compose up -d
}
function k8s_setup() {
echo "Deploying with Kubernetes"
command -v kubectl >/dev/null 2>&1 || { echo >&2 "OpenDataCam requires Kubernetes, please install and retry.\nFor a Kubernetes for embedded go to https://k3s.io/"; }
# wget -N https://raw.githubusercontent.com/opendatacam/opendatacam/master/docker/run/$PLATFORM/kubernetes/0001-mongodb-deployment.yaml -P opendatacam
# wget -N https://raw.githubusercontent.com/opendatacam/opendatacam/master/docker/run/$PLATFORM/kubernetes/0002-opendatacam-deployment.yaml -P opendatacam
kubectl create configmap opendatacam --from-file=config.json --dry-run -o yaml | kubectl apply -f -
kubectl apply -f 0002-opendatacam-deployment.yaml
#Print deployment information
kubectl get pods
kubectl get service
}
while [[ $# -gt 0 ]]
do
argument="$1"
case $argument in
-h|--help)
display_usage
;;
-p|--platform)
PLATFORM=$2
INDEX=$( index $2 ${PLATFORM_OPTIONS[@]})
shift
shift
;;
-o|--orchestrator)
ORCHESTRATOR=$2
shift
shift
;;
*)
raise_error "Unknown argument: ${argument}"
display_usage
;;
esac
done
if [ "$INDEX" == "" ] || [ -z "$INDEX" ]
then
raise_error "Platform choice not correct"
display_usage
fi
if [ "$ORCHESTRATOR" == "" ] || [ -z "$INDEX" ]
then
ORCHESTRATOR="docker-compose"
fi
echo index : $INDEX
echo orchestrator: $ORCHESTRATOR
# Stop any current docker container from running
echo "Stop any running OpenDataCam docker container..."
set +e
sudo docker stop opendatacams
set -e
echo "Installing OpenDataCam $VERSION for platform: $2 ..."
if [ ! -f ./config.json ]; then
# Get the config file
echo "Download config file ..."
wget -N https://raw.githubusercontent.com/opendatacam/opendatacam/$VERSION/config.json
# Replace VIDEO_INPUT and NEURAL_NETWORK with default config for this platform
VIDEO_INPUT=${DEFAUT_VIDEO_INPUT_OPTIONS[$INDEX]}
NEURAL_NETWORK=${DEFAUT_NEURAL_NETWORK_OPTIONS[$INDEX]}
echo "Replace config file with platform default params ... (you can change those later)"
echo "NEURAL_NETWORK : $NEURAL_NETWORK"
echo "VIDEO_INPUT : $VIDEO_INPUT"
# Replace in config.json with default params for the current platform
sed -i'.bak' -e "s/TO_REPLACE_VIDEO_INPUT/$VIDEO_INPUT/g" config.json
sed -i'.bak' -e "s/TO_REPLACE_NEURAL_NETWORK/$NEURAL_NETWORK/g" config.json
sed -i'.bak' -e "s|TO_REPLACE_PATH_TO_DARKNET|$PATH_DARKNET|g" config.json
fi
case $ORCHESTRATOR in
docker-compose)
docker_compose_setup
;;
k8s)
k8s_setup
;;
*)
raise_error "Unknown orchestrator ${orchestrator}"
display_usage
;;
esac
# Message that docker container has been started and opendatacam will be available shorty on <IP>
echo "OpenDataCam docker container installed successfully, it might take up to 1-2 min to start the node app and the webserver"
# Cancel stop bash script on error (get IP will fail is no wifi dongle / ethernet connexion)
set +e
# TODO better way to get the ip to run
# really shite way this
# wifiIP=$(ifconfig wlan0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
# ethernetIP=$(ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.2')
if [ -n "$wifiIP" ]; then
echo "WIFI device IP"
echo "OpenDataCam is available at: http://$wifiIP:8080"
fi
if [ -n "$ethernetIP" ]; then
echo "Ethernet device IP"
echo "OpenDataCam is available at: http://$ethernetIP:8080"
fi
echo "OpenDataCam will start automaticaly on boot when you restart you jetson"
echo "If you want to stop it, please refer to the doc: https://github.com/opendatacam/opendatacam"
apiVersion: v1
kind: Secret
data:
password: cGFzc3dvcmQK
username: dXNlcm5hbWUK
metadata:
creationTimestamp: null
name: mongo-creds
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment