Pre-process, Process and Post-process work

Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
Davide Sapienza
2020-01-20 12:27:49 +01:00
parent 23a1365dc4
commit 7838cb4922
10 changed files with 1598 additions and 39 deletions
+28 -24
View File
@@ -9,7 +9,8 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "Yolo3Detection.h"
// #include "Yolo3Detection.h"
#include "CenternetDetection.h"
bool gRun;
bool SAVE_RESULT = false;
@@ -25,14 +26,15 @@ int main(int argc, char *argv[]) {
signal(SIGINT, sig_handler);
char *net = "yolo3.rt";
char *net = "resnet101_cnet.rt";
if(argc > 1)
net = argv[1];
char *input = "../demo/yolo_test.mp4";
if(argc > 2)
input = argv[2];
tk::dnn::Yolo3Detection yolo;
// tk::dnn::Yolo3Detection yolo;
tk::dnn::CenternetDetection yolo;
yolo.init(net);
gRun = true;
@@ -66,29 +68,31 @@ int main(int argc, char *argv[]) {
// TODO: async infer
yolo.update(dnn_input);
// draw dets
for(int i=0; i<yolo.detected.size(); i++) {
tk::dnn::box b = yolo.detected[i];
int x0 = b.x;
int x1 = b.x + b.w;
int y0 = b.y;
int y1 = b.y + b.h;
std::string det_class = yolo.getYoloLayer()->classesNames[b.cl];
float prob = b.prob;
frame = yolo.draw(dnn_input);
// // draw dets
// for(int i=0; i<yolo.detected.size(); i++) {
// tk::dnn::box b = yolo.detected[i];
// int x0 = b.x;
// int x1 = b.x + b.w;
// int y0 = b.y;
// int y1 = b.y + b.h;
// std::string det_class = yolo.coco_class_name[b.cl];
// // yolo.getYoloLayer()->classesNames[b.cl];
// float prob = b.prob;
std::cout<<det_class<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
// draw rectangle
cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), yolo.colors[b.cl], 2);
// // std::cout<<det_class<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
// // draw rectangle
// cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), yolo.colors[b.cl], 2);
// draw label
int baseline = 0;
float fontScale = 0.5;
int thickness = 2;
cv::Size textSize = getTextSize(det_class, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
cv::rectangle(frame, cv::Point(x0, y0), cv::Point((x0 + textSize.width - 2), (y0 - textSize.height - 2)), yolo.colors[b.cl], -1);
cv::putText(frame, det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, fontScale, cv::Scalar(255, 255, 255), thickness);
}
// // draw label
// int baseline = 0;
// float fontScale = 0.5;
// int thickness = 2;
// cv::Size textSize = getTextSize(det_class, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
// cv::rectangle(frame, cv::Point(x0, y0), cv::Point((x0 + textSize.width - 2), (y0 - textSize.height - 2)), yolo.colors[b.cl], -1);
// cv::putText(frame, det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, fontScale, cv::Scalar(255, 255, 255), thickness);
// }
cv::imshow("detection", frame);
cv::waitKey(1);
if(SAVE_RESULT)