diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 281d035..59ee58c 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "utils.h" #include @@ -21,12 +22,28 @@ bool gRun; + +cv::Mat frame_v; +cv::Mat frame_top_v; +std::mutex sem; + void sig_handler(int signo) { std::cout << "request gateway stop\n"; 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); + } +} void draw_arrow(float angleRad, float vel, cv::Scalar color, cv::Point center, cv::Mat &frame) @@ -58,14 +75,15 @@ int main(int argc, char *argv[]) char *tiffile = "../demo/demo/data/map_b.tif"; if (argc > 4) tiffile = argv[4]; - /*CAMID*/ int CAM_IDX = 0; if (argc > 5) CAM_IDX = atoi(argv[5]); - bool to_show = true; + bool to_show = false; if (argc > 6) to_show = atoi(argv[6]); + + tk::dnn::Yolo3Detection yolo; yolo.init(net); yolo.thresh = 0.25; @@ -76,26 +94,31 @@ int main(int argc, char *argv[]) if (!cap.isOpened()) gRun = false; else - std::cout << "camera started\n"; + std::cout <<"camera started\n"; cv::Mat frame; - cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); - cv::namedWindow("topview", cv::WINDOW_NORMAL); - cv::Mat frame_top; + cv::Mat dnn_input; cv::Mat original_frame_top; - frame_top = cv::imread("../demo/demo/data/map_b.jpg"); - original_frame_top = frame_top.clone(); + + pthread_t visual; + + if(to_show) + { + cv::namedWindow("detection", cv::WINDOW_NORMAL); + cv::namedWindow("topview", cv::WINDOW_NORMAL); + frame_top = cv::imread("../demo/demo/data/map_b.jpg"); + original_frame_top = frame_top.clone(); + } /*projection matrix*/ - int proj_matrix_read = 0; cv::Mat H(cv::Size(3, 3), CV_64FC1); /*GPS information*/ double *adfGeoTransform = (double *)malloc(6 * sizeof(double)); readTiff(tiffile, adfGeoTransform); + struct obj_coords *coords = (struct obj_coords *)malloc(MAX_DETECT_SIZE * sizeof(struct obj_coords)); /*socket*/ int sock; @@ -116,13 +139,9 @@ int main(int argc, char *argv[]) int n_states = 5; float dt = 0.03; - struct obj_coords *coords = (struct obj_coords *)malloc(MAX_DETECT_SIZE * sizeof(struct obj_coords)); - int frame_nbr = 0; while (gRun) { - - cap >> frame; if (!frame.data) { @@ -144,13 +163,7 @@ int main(int argc, char *argv[]) num_detected = MAX_DETECT_SIZE; if (proj_matrix_read == 0) - { read_projection_matrix(H, proj_matrix_read, pmatrix); - } - - /*printf("%f %f %f \n%f %f %f\n %f %f %f\n\n", proj_matrix[0],proj_matrix[1], - proj_matrix[2],proj_matrix[3],proj_matrix[4],proj_matrix[5], - proj_matrix[6],proj_matrix[7],proj_matrix[8]);*/ // draw dets for (int i = 0; i < num_detected; i++) @@ -179,17 +192,14 @@ int main(int argc, char *argv[]) TIMER_START + //convert from latitude and longitude to meters for ekf cur_frame.clear(); for (int i = 0; i < coord_i; i++) { - //std::cout << "lat orig: " << coords[i].LAT << " lon orig: " << coords[i].LONG << std::endl; gc.geodetic2Enu(coords[i].LAT, coords[i].LONG, 0, &east, &north, &up); - //std::cout << "east: " << east << " north: " << north << std::endl; cur_frame.push_back(Data(east, north, frame_nbr)); } - - if (frame_nbr == 0) { for (auto f : cur_frame) @@ -200,7 +210,6 @@ int main(int argc, char *argv[]) Track(cur_frame, dt, n_states, initial_age, age_threshold, trackers); } - TIMER_STOP std::cout << "There are " << trackers.size() << " trackers" << std::endl; @@ -232,41 +241,38 @@ int main(int argc, char *argv[]) if(p == t.pred_list_.size()-1) { - auto center = cv::Point(camera_p[0].x, camera_p[0].y); auto color = cv::Scalar(t.r_, t.g_, t.b_); draw_arrow(t.pred_list_[p].yaw_, t.pred_list_[p].vel_,color, center, frame); center = cv::Point(pix_x,pix_y); draw_arrow(t.pred_list_[p].yaw_, t.pred_list_[p].vel_,color, center, frame_top); - - } - } } } - frame_nbr++; - - send_client_dummy(coords, coord_i, sock, socket_opened, CAM_IDX); - - - - if (to_show) + if(to_show) { - cv::imshow("detection", frame); - cv::imshow("topview", frame_top); - cv::waitKey(1); + sem.lock(); + frame_v = frame.clone(); + frame_top_v = frame_top.clone(); + sem.unlock(); } + if (frame_nbr == 0 && to_show) + { + if (pthread_create(&visual, NULL, showImages, NULL)) + { + fprintf(stderr, "Error creating thread\n"); + return 1; + } + } + frame_nbr++; + send_client_dummy(coords, coord_i, sock, socket_opened, CAM_IDX); } - /* for (size_t i = 0; i < trackers.size(); i++) - if (trackers[i].z_list_.size() > 10) - plotTruthvsPred(trackers[i].z_list_, trackers[i].pred_list_); */ - free(coords); free(adfGeoTransform);