Include frame disparity visualization

This commit is contained in:
Davide Sapienza
2019-09-03 19:08:33 +02:00
parent 88e0f9393a
commit 5bbb3f3480
+29 -9
View File
@@ -46,16 +46,16 @@ struct InfoShow{
double adfGeoTransform[6]; double adfGeoTransform[6];
cv::Mat H; cv::Mat H;
cv::Mat frame_v; cv::Mat frame_v;
cv::Mat frame_disp;
}; };
void sig_handler(int signo) void sig_handler(int signo)
{ {
std::cout << "request gateway stop\n"; std::cout << "request gateway stop\n";
gRun = false; gRun = false;
} }
void *showImages(void *x_void_ptr) void *showImages(void *x_void_ptr)
{ {
InfoShow *info_show = (InfoShow *) x_void_ptr; InfoShow *info_show = (InfoShow *) x_void_ptr;
@@ -65,6 +65,8 @@ void *showImages(void *x_void_ptr)
cv::Mat original_frame_top; cv::Mat original_frame_top;
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::namedWindow("disparity", cv::WINDOW_NORMAL);
// original_frame_top = cv::imread("../demo/demo/data/map/map_geo.jpg"); // original_frame_top = cv::imread("../demo/demo/data/map/map_geo.jpg");
original_frame_top = cv::imread("../demo/demo/data/map/MASA_4670.png"); original_frame_top = cv::imread("../demo/demo/data/map/MASA_4670.png");
cv::Mat frame_v_loc; cv::Mat frame_v_loc;
@@ -72,6 +74,8 @@ void *showImages(void *x_void_ptr)
geodetic_converter::GeodeticConverter gc; geodetic_converter::GeodeticConverter gc;
double adfGeoTransform[6]; double adfGeoTransform[6];
cv::Mat H; cv::Mat H;
cv::Mat frame_disp_loc;
while (gRun) while (gRun)
{ {
TIMER_START TIMER_START
@@ -87,6 +91,8 @@ void *showImages(void *x_void_ptr)
adfGeoTransform[i] = info_show->adfGeoTransform[i]; adfGeoTransform[i] = info_show->adfGeoTransform[i];
// cv::Mat H; // cv::Mat H;
H = info_show->H.clone(); H = info_show->H.clone();
frame_disp_loc = info_show->frame_disp.clone();
sem.unlock(); sem.unlock();
frame_top = original_frame_top.clone(); frame_top = original_frame_top.clone();
@@ -127,9 +133,13 @@ void *showImages(void *x_void_ptr)
//outputVideo<< frame_top; //outputVideo<< frame_top;
// ------------------------------------------------ // ------------------------------------------------
std::cout<<"size: "<<frame_v_loc.rows<<" - "<<frame_v_loc.cols<<std::endl;
std::cout<<"size: "<<frame_top.rows<<" - "<<frame_top.cols<<std::endl;
std::cout<<"size: "<<frame_disp_loc.rows<<" - "<<frame_disp_loc.cols<<std::endl;
cv::imshow("detection", frame_v_loc); cv::imshow("detection", frame_v_loc);
cv::imshow("topview", frame_top); cv::imshow("topview", frame_top);
cv::imshow("disparity", frame_disp_loc);
cv::waitKey(1); cv::waitKey(1);
std::cout<<"visual: "; std::cout<<"visual: ";
TIMER_STOP TIMER_STOP
@@ -174,7 +184,6 @@ int main(int argc, char *argv[])
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;
cv::VideoCapture cap(input); cv::VideoCapture cap(input);
if (!cap.isOpened()) if (!cap.isOpened())
@@ -182,13 +191,14 @@ int main(int argc, char *argv[])
else else
std::cout << "camera started\n"; std::cout << "camera started\n";
pthread_t visual;
cv::Mat frame; cv::Mat frame;
cv::Mat frame_crop; cv::Mat frame_crop;
cv::Mat frame_disp;
char buf_frame_crop_name [200]; char buf_frame_crop_name [200];
cv::Mat dnn_input; cv::Mat dnn_input;
pthread_t visual;
/*projection matrix from camera to map*/ /*projection matrix from camera to map*/
cv::Mat H(cv::Size(3, 3), CV_64FC1); cv::Mat H(cv::Size(3, 3), CV_64FC1);
read_projection_matrix(H, pmatrix); read_projection_matrix(H, pmatrix);
@@ -273,6 +283,7 @@ int main(int argc, char *argv[])
cv::Rect roi; cv::Rect roi;
InfoShow info_show; InfoShow info_show;
if (to_show) if (to_show)
{ {
info_show.H = cv::Mat(cv::Size(3, 3), CV_64FC1); info_show.H = cv::Mat(cv::Size(3, 3), CV_64FC1);
@@ -290,6 +301,7 @@ int main(int argc, char *argv[])
step_t = start_t; step_t = start_t;
cap >> frame; cap >> frame;
orig_frame = frame.clone(); orig_frame = frame.clone();
if (frame_nbr == 0) if (frame_nbr == 0)
cv::initUndistortRectifyMap(cameraMat, distCoeff, cv::Mat(), cameraMat, frame.size(), CV_16SC2, map1, map2); cv::initUndistortRectifyMap(cameraMat, distCoeff, cv::Mat(), cameraMat, frame.size(), CV_16SC2, map1, map2);
@@ -299,7 +311,6 @@ int main(int argc, char *argv[])
//undistort(temp, frame, cameraMat, distCoeff); //undistort(temp, frame, cameraMat, distCoeff);
if (!frame.data) if (!frame.data)
{ {
usleep(1000000); usleep(1000000);
@@ -308,6 +319,7 @@ int main(int argc, char *argv[])
continue; continue;
} }
// this will be resized to the net format // this will be resized to the net format
dnn_input = frame.clone(); dnn_input = frame.clone();
// TODO: async infer // TODO: async infer
@@ -343,8 +355,15 @@ int main(int argc, char *argv[])
// backtorgb = cv::cvtColor(pre_canny,cv::COLOR_GRAY2RGB) // backtorgb = cv::cvtColor(pre_canny,cv::COLOR_GRAY2RGB)
cv::cvtColor(pre_canny, pre_canny_RGB, CV_GRAY2RGB); cv::cvtColor(pre_canny, pre_canny_RGB, CV_GRAY2RGB);
cv::cvtColor(canny, canny_RGB, CV_GRAY2RGB); cv::cvtColor(canny, canny_RGB, CV_GRAY2RGB);
frame_disparity(pre_canny_RGB, canny_RGB, frame_nbr, 999, 0); frame_disp = frame_disparity(pre_canny_RGB, canny_RGB, frame_nbr, 999, 0);
std::cout<<"size: "<<frame_disp.rows<<" - "<<frame_disp.cols<<std::endl;
if (frame_disp.rows == 0 || frame_disp.cols == 0)
return -1;
if (frame_disp.empty())
{ // only fools don't check...
std::cout << "image not loaded !" << std::endl;
return -1;
}
end_t_segmentation = std::chrono::steady_clock::now(); end_t_segmentation = std::chrono::steady_clock::now();
std::cout << " TIME canny : frame_disparity : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl; std::cout << " TIME canny : frame_disparity : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl;
step_t_segmentation = end_t_segmentation; step_t_segmentation = end_t_segmentation;
@@ -469,6 +488,7 @@ int main(int argc, char *argv[])
info_show.adfGeoTransform[i] = adfGeoTransform[i]; info_show.adfGeoTransform[i] = adfGeoTransform[i];
// cv::Mat H; // cv::Mat H;
info_show.H = H.clone(); info_show.H = H.clone();
info_show.frame_disp = frame_disp.clone();
sem.unlock(); sem.unlock();
} }