visualization via thread
This commit is contained in:
+50
-25
@@ -3,7 +3,8 @@
|
|||||||
#include <stdlib.h> /* srand, rand */
|
#include <stdlib.h> /* srand, rand */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <pthread.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
@@ -20,6 +21,9 @@
|
|||||||
#define MAX_DETECT_SIZE 100
|
#define MAX_DETECT_SIZE 100
|
||||||
|
|
||||||
bool gRun;
|
bool gRun;
|
||||||
|
cv::Mat frame_v;
|
||||||
|
cv::Mat frame_top_v;
|
||||||
|
std::mutex sem;
|
||||||
|
|
||||||
void sig_handler(int signo)
|
void sig_handler(int signo)
|
||||||
{
|
{
|
||||||
@@ -27,6 +31,19 @@ void sig_handler(int signo)
|
|||||||
gRun = false;
|
gRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *showImages(void *x_void_ptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
while (gRun)
|
||||||
|
{
|
||||||
|
sem.lock();
|
||||||
|
cv::imshow("detection", frame_v);
|
||||||
|
cv::imshow("topview", frame_top_v);
|
||||||
|
sem.unlock();
|
||||||
|
cv::waitKey(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -49,7 +66,7 @@ int main(int argc, char *argv[])
|
|||||||
int CAM_IDX = 0;
|
int CAM_IDX = 0;
|
||||||
if (argc > 5)
|
if (argc > 5)
|
||||||
CAM_IDX = atoi(argv[5]);
|
CAM_IDX = atoi(argv[5]);
|
||||||
bool to_show = true;
|
bool to_show = false;
|
||||||
if (argc > 6)
|
if (argc > 6)
|
||||||
to_show = atoi(argv[6]);
|
to_show = atoi(argv[6]);
|
||||||
|
|
||||||
@@ -66,13 +83,16 @@ int main(int argc, char *argv[])
|
|||||||
std::cout << "camera started\n";
|
std::cout << "camera started\n";
|
||||||
|
|
||||||
cv::Mat frame;
|
cv::Mat frame;
|
||||||
|
cv::Mat frame_top;
|
||||||
|
|
||||||
cv::Mat dnn_input;
|
cv::Mat dnn_input;
|
||||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||||
cv::namedWindow("topview", cv::WINDOW_NORMAL);
|
cv::namedWindow("topview", cv::WINDOW_NORMAL);
|
||||||
|
|
||||||
cv::Mat frame_top;
|
|
||||||
frame_top = cv::imread("../demo/demo/data/map_b.jpg");
|
frame_top = cv::imread("../demo/demo/data/map_b.jpg");
|
||||||
|
|
||||||
|
pthread_t visual;
|
||||||
|
|
||||||
/*projection matrix*/
|
/*projection matrix*/
|
||||||
|
|
||||||
int proj_matrix_read = 0;
|
int proj_matrix_read = 0;
|
||||||
@@ -93,7 +113,7 @@ int main(int argc, char *argv[])
|
|||||||
double lat, lon, alt;
|
double lat, lon, alt;
|
||||||
|
|
||||||
/*tracker infos*/
|
/*tracker infos*/
|
||||||
srand (time(NULL));
|
srand(time(NULL));
|
||||||
std::vector<Tracker> trackers;
|
std::vector<Tracker> trackers;
|
||||||
std::vector<Data> cur_frame;
|
std::vector<Data> cur_frame;
|
||||||
int initial_age = -5;
|
int initial_age = -5;
|
||||||
@@ -107,7 +127,6 @@ int main(int argc, char *argv[])
|
|||||||
while (gRun)
|
while (gRun)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
cap >> frame;
|
cap >> frame;
|
||||||
if (!frame.data)
|
if (!frame.data)
|
||||||
{
|
{
|
||||||
@@ -159,10 +178,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
//std::cout<<obj_class<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
|
//std::cout<<obj_class<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
|
||||||
cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), yolo.colors[obj_class], 2);
|
cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), yolo.colors[obj_class], 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TIMER_START
|
//TIMER_START
|
||||||
|
|
||||||
cur_frame.clear();
|
cur_frame.clear();
|
||||||
for (int i = 0; i < coord_i; i++)
|
for (int i = 0; i < coord_i; i++)
|
||||||
@@ -173,8 +191,6 @@ int main(int argc, char *argv[])
|
|||||||
cur_frame.push_back(Data(east, north, frame_nbr));
|
cur_frame.push_back(Data(east, north, frame_nbr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (frame_nbr == 0)
|
if (frame_nbr == 0)
|
||||||
{
|
{
|
||||||
for (auto f : cur_frame)
|
for (auto f : cur_frame)
|
||||||
@@ -185,23 +201,23 @@ int main(int argc, char *argv[])
|
|||||||
Track(cur_frame, dt, n_states, initial_age, age_threshold, trackers);
|
Track(cur_frame, dt, n_states, initial_age, age_threshold, trackers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TIMER_STOP
|
||||||
TIMER_STOP
|
|
||||||
//std::cout << "There are " << trackers.size() << " trackers" << std::endl;
|
//std::cout << "There are " << trackers.size() << " trackers" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
for (auto t : trackers)
|
for (auto t : trackers)
|
||||||
{
|
{
|
||||||
for(auto pred_pos: t.pred_list_ )
|
for (auto pred_pos : t.pred_list_)
|
||||||
{
|
{
|
||||||
|
|
||||||
gc.enu2Geodetic(pred_pos.x_, pred_pos.y_, 0, &lat, &lon, &alt);
|
gc.enu2Geodetic(pred_pos.x_, pred_pos.y_, 0, &lat, &lon, &alt);
|
||||||
//std::cout << "lat: " << lat << " lon: " << lon << std::endl;
|
//std::cout << "lat: " << lat << " lon: " << lon << std::endl;
|
||||||
int pix_x, pix_y;
|
int pix_x, pix_y;
|
||||||
coord2pixel(lat, lon, pix_x, pix_y, adfGeoTransform);
|
coord2pixel(lat, lon, pix_x, pix_y, adfGeoTransform);
|
||||||
|
|
||||||
//std::cout << "pix_x: " << pix_x << " pix_y: " << pix_y << std::endl;
|
//std::cout << "pix_x: " << pix_x << " pix_y: " << pix_y << std::endl;
|
||||||
if(pix_x < frame_top.cols && pix_y < frame_top.rows && pix_x >= 0 && pix_y >= 0)
|
if (pix_x < frame_top.cols && pix_y < frame_top.rows && pix_x >= 0 && pix_y >= 0)
|
||||||
cv::circle(frame_top, cv::Point(pix_x,pix_y), 7.0, cv::Scalar(t.r_, t.g_, t.b_), CV_FILLED, 8, 0);
|
cv::circle(frame_top, cv::Point(pix_x, pix_y), 7.0, cv::Scalar(t.r_, t.g_, t.b_), CV_FILLED, 8, 0);
|
||||||
|
|
||||||
std::vector<cv::Point2f> map_p, camera_p;
|
std::vector<cv::Point2f> map_p, camera_p;
|
||||||
map_p.push_back(cv::Point2f(pix_x, pix_y));
|
map_p.push_back(cv::Point2f(pix_x, pix_y));
|
||||||
@@ -211,7 +227,25 @@ int main(int argc, char *argv[])
|
|||||||
//std::cout << "pix_x: " << camera_p[0].x << " pix_y: " << camera_p[0].y << std::endl;
|
//std::cout << "pix_x: " << camera_p[0].x << " pix_y: " << camera_p[0].y << std::endl;
|
||||||
|
|
||||||
cv::circle(frame, cv::Point(camera_p[0].x, camera_p[0].y), 3.0, cv::Scalar(t.r_, t.g_, t.b_), CV_FILLED, 8, 0);
|
cv::circle(frame, cv::Point(camera_p[0].x, camera_p[0].y), 3.0, cv::Scalar(t.r_, t.g_, t.b_), CV_FILLED, 8, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TIMER_START
|
||||||
|
sem.lock();
|
||||||
|
frame_v = frame.clone();
|
||||||
|
frame_top_v = frame_top.clone();
|
||||||
|
sem.unlock();
|
||||||
|
|
||||||
|
TIMER_STOP
|
||||||
|
|
||||||
|
if (frame_nbr == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (pthread_create(&visual, NULL, showImages, NULL))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error creating thread\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,15 +254,6 @@ int main(int argc, char *argv[])
|
|||||||
send_client_dummy(coords, coord_i, sock, socket_opened, CAM_IDX);
|
send_client_dummy(coords, coord_i, sock, socket_opened, CAM_IDX);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (to_show)
|
|
||||||
{
|
|
||||||
cv::imshow("detection", frame);
|
|
||||||
cv::imshow("topview", frame_top);
|
|
||||||
cv::waitKey(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for (size_t i = 0; i < trackers.size(); i++)
|
/* for (size_t i = 0; i < trackers.size(); i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user