#ifdef _MSC_VER #include "../vpt_det/vpt.h" #else #include "vpt.h" #endif #include #include #include #include #include "sy_common.h" #include "utools.h" #include #ifdef _WIN32 #include #else #include #endif int main() { #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; QueryPerformanceFrequency(&nFreq); #else struct timeval t1, t2; #endif double time_val = 0; std::vector time_Array; CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, 3); int fontFace = CV_FONT_HERSHEY_COMPLEX; double fontScale = 1; int thickness = 2; static std::string type[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" }; void* handle; vpt_param param; param.mode = DEVICE_GPU; param.gpuid = 0; param.threshold = 0.6; param.engine = ENGINE_TENSORRT; param.preprocess_param = "CopyData_CPU2GPU_U8;" "TypeConvert_U8_F32;" "ResizePad_F32_F32,test_size,720,test_max_size,1280,fpn_coarsest_stride,32," "submean_b,103.94,submean_g,116.78,submean_r,123.68," "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" "NHWC2NCHW_F32" ; param.serialize_file = "FPN_VPT"; param.max_batch = 20; vpt_init(&handle, param); const int batchsize = 10; /*³õʼ»¯½á¹û½á¹¹Ìå*/ vpt_result *result = new vpt_result[batchsize]; for (int b = 0; b < batchsize; b++) { result[b].obj_count_ = 0; result[b].obj_results_ = new vpt_obj_result[MAX_DET_COUNT]; } //CTOOLS_Img *images = new CTOOLS_Img[batchsize]; //cv::Mat img; sy_img images[batchsize]; cv::Mat img[batchsize]; char strpath[1024]; memset(strpath, 0, sizeof(strpath)); for (int b = 0; b < batchsize; b++) { #ifdef _MSC_VER sprintf(strpath, "../../../data/%d.jpg", b);// b); #else sprintf(strpath, "../../data/%d.jpg", b); #endif //cv::Mat img/*[b]*/; //memset(&img, 0, sizeof(img)); img[b] = cv::imread(strpath); images[b].set_data(img[b].cols, img[b].rows, img[b].channels(), img[b].data); } //vpt_batch(handle, images, batchsize, &result); int count = 1000; while (count--) { #ifdef _MSC_VER QueryPerformanceCounter(&nBeginTime); #else gettimeofday(&t1, NULL); #endif vpt_batch(handle, images, batchsize, &result); #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("vpt_batch cost: %.2f ms \n", time_val); #else gettimeofday(&t2, NULL); time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; printf("vpt_batch cost= %lf ms\n", time_val); #endif time_Array.push_back(time_val); } double total = 0; for (int n = 1; n < time_Array.size(); n++) { total += time_Array[n]; } printf("batch size: %d, vpt_batch avg cost: %.2f\n", batchsize, total / (time_Array.size() - 1)); for (int b = 0; b < batchsize; b++) { std::cout << "b: " << b << ", count: " << result[b].obj_count_ << std::endl; for (int c = 0; c < result[b].obj_count_; c++) { char str_i[100]; sprintf(str_i, "%s:%.2f", type[result[b].obj_results_[c].obj_index].c_str(), result[b].obj_results_[c].obj_score); rectangle(img[b], cvPoint(result[b].obj_results_[c].obj_rect.left_ - 5, result[b].obj_results_[c].obj_rect.top_ - 15), cvPoint(result[b].obj_results_[c].obj_rect.left_ + result[b].obj_results_[c].obj_rect.width_ + 5, result[b].obj_results_[c].obj_rect.top_ + result[b].obj_results_[c].obj_rect.height_ + 10), cv::Scalar(127, 64, 120), 3, 1); cv::putText(img[b], str_i, cv::Point(result[b].obj_results_[c].obj_rect.left_, result[b].obj_results_[c].obj_rect.top_), fontFace, fontScale, cv::Scalar(58, 158, 199), thickness, 8); } #ifdef _MSC_VER //cv::imshow("RES", image); //cv::waitKey(0); cv::Mat showImg; cv::resize(img[b], showImg, cv::Size(640, 480)); cv::imshow("image", showImg); cv::waitKey(0); #else sprintf(strpath, "vpt_result/%d.jpg", b); cv::imwrite(strpath, img[b]); #endif } vpt_release(&handle); return 0; }