Add configuration file to read CLASS parameters
This commit changes the parameters reading. It introduces getopt to read input parameters from command line and it uses a configuration yaml file to read the input parameters for the network, the map and the cameras. This commit fixes a bug in message sending to the aggregator. Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
+33
-94
@@ -4,6 +4,7 @@
|
|||||||
#include "Yolo3Detection.h"
|
#include "Yolo3Detection.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "visualization.h"
|
#include "visualization.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
#include "tracker.h"
|
#include "tracker.h"
|
||||||
#include "../masa_protocol/include/send.hpp"
|
#include "../masa_protocol/include/send.hpp"
|
||||||
@@ -483,7 +484,7 @@ void *computationTask(void *x_void_ptr)
|
|||||||
}
|
}
|
||||||
std::cout << "There are " << trackers.size() << " trackers" << std::endl;
|
std::cout << "There are " << trackers.size() << " trackers" << std::endl;
|
||||||
//prepare message with tracker info
|
//prepare message with tracker info
|
||||||
if (trackers.size() == 0)
|
if (trackers.size() != 0)
|
||||||
{
|
{
|
||||||
// mutex_cv.lock();
|
// mutex_cv.lock();
|
||||||
addRoadUserfromTracker(trackers, m, gc, maskOrient, adfGeoTransform, H);
|
addRoadUserfromTracker(trackers, m, gc, maskOrient, adfGeoTransform, H);
|
||||||
@@ -533,120 +534,58 @@ int main(int argc, char *argv[])
|
|||||||
std::cout << "detection\n";
|
std::cout << "detection\n";
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
bool no_params = false; //flag to indicate if there are camera parameters or we use mp4 test video
|
|
||||||
|
|
||||||
char *net = (char *)"yolo3_coco4.rt";
|
Parameters_t par;
|
||||||
if (argc > 1)
|
|
||||||
net = argv[1];
|
if(!read_parameters(argc, argv, &par))
|
||||||
char *tiffile = (char *)"../demo/demo/data/map_b.tif";
|
|
||||||
if (argc > 2)
|
|
||||||
tiffile = argv[2];
|
|
||||||
char *n;
|
|
||||||
if (argc > 3)
|
|
||||||
{
|
|
||||||
n = argv[3];
|
|
||||||
if (strcmp(n, "-n"))
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
int n_cameras = 0;
|
|
||||||
if (argc > 4)
|
|
||||||
{
|
|
||||||
n_cameras = atoi(argv[4]);
|
|
||||||
if (argc < 5 + 7 * n_cameras)
|
|
||||||
{
|
|
||||||
std::cout << "too few parameters\n";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!n_cameras)
|
|
||||||
{
|
|
||||||
n_cameras = 1;
|
|
||||||
no_params = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Camera_t cameras[n_cameras];
|
|
||||||
bool *to_show = (bool *)malloc(n_cameras * sizeof(bool));
|
|
||||||
if (no_params)
|
|
||||||
{
|
|
||||||
cameras[0].CAM_IDX = 20936;
|
|
||||||
cameras[0].input = (char *)"../demo/demo/data/single_ped_2.mp4";
|
|
||||||
cameras[0].pmatrix = (char *)"../demo/demo/data/pmundist.txt";
|
|
||||||
cameras[0].maskfile = (char *)"../demo/demo/data/mask36.jpg";
|
|
||||||
cameras[0].cameraCalib = (char *)"../demo/demo/data/calib36.params";
|
|
||||||
cameras[0].maskFileOrient = (char *)"../demo/demo/data/mask_orient/6315_mask_orient.jpg";
|
|
||||||
cameras[0].to_show = true;
|
|
||||||
to_show[0] = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].CAM_IDX = atoi(argv[5 + i]);
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].input = argv[5 + n_cameras + i];
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].pmatrix = argv[5 + 2 * n_cameras + i];
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].maskfile = argv[5 + 3 * n_cameras + i];
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].cameraCalib = argv[5 + 4 * n_cameras + i];
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
cameras[i].maskFileOrient = argv[5 + 5 * n_cameras + i];
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
{
|
|
||||||
cameras[i].to_show = atoi(argv[5 + 6 * n_cameras + i]); //only one camera can be shown
|
|
||||||
to_show[i] = atoi(argv[5 + 6 * n_cameras + i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//TODO now only one camera can be visualized
|
|
||||||
int check_visualization = 0;
|
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
check_visualization += to_show[i];
|
|
||||||
if (check_visualization > 1)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
tk::dnn::Yolo3Detection yolo[n_cameras];
|
// tk::dnn::Yolo3Detection yolo[par.n_cameras];
|
||||||
for (int i = 0; i < n_cameras; i++)
|
// for(int i=0; i<par.n_cameras; i++)
|
||||||
{
|
// {
|
||||||
yolo[i].init(net);
|
// std::cout<<"par net: "<<par.net<<std::endl;
|
||||||
yolo[i].thresh = 0.25;
|
// yolo[i].init(par.net);
|
||||||
}
|
// yolo[i].thresh = 0.25;
|
||||||
|
// }
|
||||||
// tk::dnn::Yolo3Detection yolo;
|
// tk::dnn::Yolo3Detection yolo;
|
||||||
// yolo.init(net);
|
// yolo.init(net);
|
||||||
// yolo.thresh = 0.25;
|
// yolo.thresh = 0.25;
|
||||||
|
|
||||||
gRun = true;
|
gRun = true;
|
||||||
|
// start the local clock. It is used to check the incoming frames (by different cameras)
|
||||||
// start the local clock. It is used to check the incoming frames (by different cameras)
|
|
||||||
local_clock_start = std::chrono::steady_clock::now();
|
local_clock_start = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
/*GPS information*/
|
/*GPS information*/
|
||||||
double *adfGeoTransform = (double *)malloc(6 * sizeof(double));
|
double *adfGeoTransform = (double *)malloc(6 * sizeof(double));
|
||||||
readTiff(tiffile, adfGeoTransform);
|
readTiff(par.tiffile, adfGeoTransform);
|
||||||
|
// Camera_t cameras[par.n_cameras];
|
||||||
for (int i = 0; i < n_cameras; i++)
|
for(int i=0; i<par.n_cameras; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 6; j++)
|
for(int j = 0; j < 6; j++ )
|
||||||
cameras[i].adfGeoTransform[j] = adfGeoTransform[j];
|
par.cameras[i].adfGeoTransform[j] = adfGeoTransform[j];
|
||||||
cameras[i].yolo = yolo[i];
|
// par.cameras[i].yolo = yolo[i];
|
||||||
|
par.cameras[i].yolo.init(par.net);
|
||||||
|
par.cameras[i].yolo.thresh = 0.25;
|
||||||
|
// cameras[i].yolo = yolo[i];
|
||||||
// cameras[i].yolo = yolo;
|
// cameras[i].yolo = yolo;
|
||||||
|
|
||||||
}
|
}
|
||||||
std::cout << "INIZIA:\n";
|
pthread_t camera_task[par.n_cameras];
|
||||||
pthread_t camera_task[n_cameras];
|
for(int i=0; i<par.n_cameras; i++)
|
||||||
for (int i = 0; i < n_cameras; i++)
|
|
||||||
{
|
{
|
||||||
std::cout << "creating thread\n";
|
std::cout<<"creating thread\n";
|
||||||
if (pthread_create(&camera_task[i], NULL, computationTask, (void *)&cameras[i]))
|
if(pthread_create(&camera_task[i], NULL, computationTask, (void*)&(par.cameras[i])))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "error creating thread\n");
|
fprintf(stderr, "error creating thread\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "WHAT2\n";
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < n_cameras; i++)
|
for(int i=0; i<par.n_cameras; i++)
|
||||||
{
|
{
|
||||||
pthread_join(camera_task[i], NULL);
|
pthread_join(camera_task[i], NULL);
|
||||||
}
|
}
|
||||||
std::cout << " free adfGeoT \n";
|
std::cout <<" free adfGeoT \n";
|
||||||
free(adfGeoTransform);
|
free(adfGeoTransform);
|
||||||
std::cout << "detection end\n";
|
std::cout << "detection end\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef CONFIGURATION_H
|
||||||
|
#define CONFIGURATION_H
|
||||||
|
|
||||||
|
#include "cameraUtils.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
struct Parameters_t
|
||||||
|
{
|
||||||
|
char *net;
|
||||||
|
char *tiffile;
|
||||||
|
int n_cameras;
|
||||||
|
Camera_t *cameras;
|
||||||
|
};
|
||||||
|
|
||||||
|
void readCamerasParametersYaml(const std::string &camerasParams, Parameters_t *par);
|
||||||
|
bool read_parameters(int argc, char *argv[], Parameters_t *par);
|
||||||
|
|
||||||
|
#endif /*CONFIGURATION_H*/
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
/* Read the configuration file. The yaml file contains the information about the network,
|
||||||
|
* the map and the cameras.
|
||||||
|
**/
|
||||||
|
void readCamerasParametersYaml(const std::string &camerasParams, Parameters_t *par)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string cam, tmp;
|
||||||
|
YAML::Node config = YAML::LoadFile(camerasParams);
|
||||||
|
tmp = config["weights"].as<std::string>();//config["lastLogin"].as<DateTime>()
|
||||||
|
par->net = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->net, tmp.c_str());
|
||||||
|
par->net[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->net<<std::endl;
|
||||||
|
tmp = config["tif_map"].as<std::string>();
|
||||||
|
par->tiffile = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->tiffile, tmp.c_str());
|
||||||
|
par->tiffile[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->tiffile<<std::endl;
|
||||||
|
|
||||||
|
//read cameras infomrations
|
||||||
|
for (int i = 0; i<par->n_cameras; i++)
|
||||||
|
{
|
||||||
|
cam = std::to_string(par->cameras[i].CAM_IDX);
|
||||||
|
// std::cout<<"read "<<cam<<std::endl;
|
||||||
|
tmp = config[cam]["input_stream"].as<std::string>();
|
||||||
|
par->cameras[i].input = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->cameras[i].input, tmp.c_str());
|
||||||
|
par->cameras[i].input[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->cameras[i].input<<std::endl;
|
||||||
|
tmp = config[cam]["pmatrix"].as<std::string>();
|
||||||
|
par->cameras[i].pmatrix = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->cameras[i].pmatrix, tmp.c_str());
|
||||||
|
par->cameras[i].pmatrix[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->cameras[i].pmatrix<<std::endl;
|
||||||
|
tmp = config[cam]["maskfile"].as<std::string>();
|
||||||
|
par->cameras[i].maskfile = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->cameras[i].maskfile, tmp.c_str());
|
||||||
|
par->cameras[i].maskfile[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->cameras[i].maskfile<<std::endl;
|
||||||
|
tmp = config[cam]["cameraCalib"].as<std::string>();
|
||||||
|
par->cameras[i].cameraCalib = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->cameras[i].cameraCalib, tmp.c_str());
|
||||||
|
par->cameras[i].cameraCalib[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->cameras[i].cameraCalib<<std::endl;
|
||||||
|
tmp = config[cam]["maskFileOrient"].as<std::string>();
|
||||||
|
par->cameras[i].maskFileOrient = (char *) malloc((strlen(tmp.c_str())+1) * sizeof(char));
|
||||||
|
strcpy(par->cameras[i].maskFileOrient, tmp.c_str());
|
||||||
|
par->cameras[i].maskFileOrient[strlen(tmp.c_str())] = '\0';
|
||||||
|
// std::cout<<"- "<<par->cameras[i].maskFileOrient<<std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read the parameters from the command line and configuration file.
|
||||||
|
**/
|
||||||
|
bool read_parameters(int argc, char *argv[], Parameters_t *par)
|
||||||
|
{
|
||||||
|
bool no_params = false;
|
||||||
|
std::string params;// = "../../prova.yaml";
|
||||||
|
par->n_cameras = 0;
|
||||||
|
int opt;
|
||||||
|
char *help = "Yolo3 demo\nCommand:\n -i\tencrypted parameters file\n -n\tnumer of cameras\n \tlist of camera numbers (see -n)\n \tlist of flags for the visualization (see -n)\n\n";
|
||||||
|
// first read n_cameras parameter and/or help option
|
||||||
|
while((opt = getopt(argc, argv, ":n:i:h")) != -1)
|
||||||
|
{
|
||||||
|
switch(opt)
|
||||||
|
{
|
||||||
|
case 'n': //number of cameras
|
||||||
|
std::cout<<"number of cameras"<<std::endl;
|
||||||
|
par->n_cameras = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
std::cout<<"help"<<std::endl;
|
||||||
|
std::cout<<help<<std::endl;
|
||||||
|
return false;
|
||||||
|
case 'i':
|
||||||
|
std::cout<<"input parameters file"<<std::endl;
|
||||||
|
params = optarg;
|
||||||
|
std::cout<<"file: "<<params<<std::endl;
|
||||||
|
break;
|
||||||
|
case ':':
|
||||||
|
printf("option needs a value\n");
|
||||||
|
no_params = true;
|
||||||
|
par->n_cameras = 1;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
printf("unknown option: %c\n", optopt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
par->cameras = (Camera_t *) malloc(par->n_cameras * sizeof(Camera_t));
|
||||||
|
bool *to_show = (bool *) malloc(par->n_cameras * sizeof(bool));
|
||||||
|
if(no_params)
|
||||||
|
{
|
||||||
|
par->net = "yolo3_coco4.rt";
|
||||||
|
par->tiffile = "../demo/demo/data/map_b.tif";
|
||||||
|
par->cameras[0].CAM_IDX = 20936;
|
||||||
|
par->cameras[0].input = (char *)"../demo/demo/data/single_ped_2.mp4";
|
||||||
|
par->cameras[0].pmatrix = (char *)"../demo/demo/data/pmundist.txt";
|
||||||
|
par->cameras[0].maskfile = (char *)"../demo/demo/data/mask36.jpg";
|
||||||
|
par->cameras[0].cameraCalib = (char *)"../demo/demo/data/calib36.params";
|
||||||
|
par->cameras[0].maskFileOrient = (char *)"../demo/demo/data/mask_orient/6315_mask_orient.jpg";
|
||||||
|
par->cameras[0].to_show = true;
|
||||||
|
to_show[0] = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for(; optind < argc; optind++)
|
||||||
|
{
|
||||||
|
if(i==par->n_cameras)
|
||||||
|
break;
|
||||||
|
printf("extra arguments: %s\n", argv[optind]);
|
||||||
|
par->cameras[i].CAM_IDX = atoi(argv[optind]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i=0;
|
||||||
|
for(; optind < argc; optind++)
|
||||||
|
{
|
||||||
|
if(i==par->n_cameras)
|
||||||
|
break;
|
||||||
|
printf("extra arguments: %s\n", argv[optind]);
|
||||||
|
par->cameras[i].to_show = atoi(argv[optind]); //only one camera can be shown
|
||||||
|
to_show[i] = par->cameras[i].to_show;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
// TODO: now only one camera can be visualized
|
||||||
|
int check_visualization=0;
|
||||||
|
for(int i = 0; i<par->n_cameras; i++)
|
||||||
|
check_visualization += to_show[i];
|
||||||
|
if(check_visualization > 1)
|
||||||
|
return false;
|
||||||
|
//decrypt the input file, save it in tmp directory
|
||||||
|
char s[200] = "";
|
||||||
|
strcat(s, "openssl enc -aes-256-cbc -d -in ");
|
||||||
|
strcat(s, params.c_str());
|
||||||
|
strcat(s, " -base64 -md sha1 -out /tmp/decrypt.yaml");
|
||||||
|
if(system(s))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error system\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// read the file yaml to get the camera parameters
|
||||||
|
readCamerasParametersYaml("/tmp/decrypt.yaml", par);
|
||||||
|
// delete the file decrypted
|
||||||
|
if (system("rm /tmp/decrypt.yaml"))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error system\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user