1. 程式人生 > >目標識別探測全景拼接相機程式耗時分析

目標識別探測全景拼接相機程式耗時分析

2018年11月15日

release_X64   X64模式下

全程耗時35ms左右

const cv::Mat ComFrame = Mat::zeros(480 * 4, 640 * 18, CV_8UC1);          7ms

const cv::Mat ColorComFrame = Mat::zeros(480 * 4, 640 * 18, CV_8UC3);   24ms

發現分配該記憶體時間太長,

測試cv::Mat ColorComFrametest = Mat::zeros(480 * 4, 640 * 18, CV_8UC3);   19ms

const cv::Mat ColorComFrametest = Mat::zeros(1920, 11520, CV_8UC3);      20ms

cv::Mat ColorMainWindows = Mat::zeros(300, 1800, CV_8UC3);  0ms

發現:使用matlab方式初始化時比較大的mat型別比較耗時,

改進:使Mat型別建構函式方式初始化

 

memcpy(image.data, pNewImage->buffer, pNewImage->head.iHeight* pNewImage->head.iWidth);   0ms

cv::resize(image, resImage, cv::Size(800, 600), 0, 0, INTER_NEAREST);    0ms

flip(resImage, resImage, -1);  0ms

cv::resize(ColorComFrame, ColorMainWindows, Size(1800, 300), 0, 0, INTER_NEAREST);  0ms

imshow("MainWindows", ColorMainWindows);   0ms

imshow("view", dst);  一般情況下為0ms,如果選擇範圍太大,則耗時會比較大,可能超過5ms

 

 

//顯示雷達掃描區域   耗時0到1ms
double beta, beta0;
//    int rhomax = 1125;
double rhomax = copyRadar.cols / 2.67;
beta = 3.1415926 * index / 36;
beta0 = beta - 1.134;
Point start, end, end0;
start.x = copyRadar.cols / 2;
start.y = copyRadar.rows / 2;
//end.x = 1500 + rhomax * sin(beta);
//end.y = 1500 - rhomax * cos(beta);
end.x = start.x + rhomax * sin(beta);
end.y = start.y - rhomax * cos(beta);
end0.x = start.x + rhomax * sin(beta0);
end0.y = start.y - rhomax * cos(beta0);
copyRadar.copyTo(copyRadarLine);
line(copyRadarLine, start, end0, Scalar(0, 255, 0), 3);
line(copyRadarLine, start, end, Scalar(0, 255, 0), 3);
imshow("Radar", copyRadarLine);
_cprintf("%d\n\n", (int)(t.time()));

 

ImageStitch(index, image1, resImage, ColorComFrame);  30ms

下面分析ImageStitch中的各個函式:

cv::matchTemplate(image_source, image_template, image_matched, cv::TM_CCORR_NORMED);    耗時2ms,同時測試該函式在debug模式下耗時為8ms,release模式僅為其25%。

 

std::vector<bbox_t> result_vec = detector.detect(newframe1);    27ms

draw_boxes(newframe1, result_vec, obj_names, 0, -1, -1);   0ms

object_location(newframe1, result_vec, &copyRadar);    0ms