| | |
| | | #else |
| | | |
| | | #include <sys/time.h> |
| | | #include <basic/util/app/AppUtil.h> |
| | | |
| | | #endif |
| | | |
| | | #include <basic/util/app/AppUtil.h> |
| | | #include "VptDetectWrapper.h" |
| | | #include <Ice/Ice.h> |
| | | #include <basic/rpc/IceRpc.hpp> |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | #include "VptServerI.h" |
| | | #include <basic/debug/Debug.h> |
| | | |
| | | #include <basic/util/app/AppConfig.h> |
| | | |
| | | using namespace std; |
| | | #define varName(x) #x |
| | | #define printExp(exp) cout<<#exp<<"为:\t\t"<<(exp)<<endl |
| | | #define printExpToString(exp) cout<<(string(#exp)+"为:\t\t")<<(exp).toString()<<endl //注意exp加括号更安全 |
| | | |
| | | |
| | | void printfAnalysisRes(int index, void *result); |
| | | |
| | | int main(int argc, char **argv) { |
| | | |
| | | std::cout << __DATE__ << " " << __TIME__ << std::endl; |
| | | SAVE_APP_ARGS; |
| | | ENABLEGLOG(GET_STR_CONFIG("logPath").c_str()); |
| | | auto ich = Ice::initialize(argc, argv); |
| | | |
| | | if (argc < 4) { |
| | | assert("t_value.size()"); |
| | | } |
| | | appPref.setIntData("gpu.index", atoi(argv[1])); |
| | | appPref.setIntData("RpcVptPort", atoi(argv[2])); |
| | | appPref.setFloatData("thresh.detect", atof(argv[3])); |
| | | |
| | | |
| | | IceRpcServer<VptServerI> server("vptServer", appPref.getIntData("RpcVptPort"), "tcp"); |
| | | server.setMessageSizeMax(1024 * 1024 * 50); |
| | | server.setPoolInitSize(5); |
| | | server.setPoolMaxSize(10); |
| | | server.runWaitShutDown(); |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | int main2(int argc, char **argv) { |
| | | string imgpath; |
| | | |
| | | if (argc < 2) { |
| | |
| | | double fontScale = 1; |
| | | int thickness = 2; |
| | | |
| | | void *handle; |
| | | vptpic_param param; |
| | | param.mode = DEVICE_GPU; |
| | | param.gpuid = 0; |
| | | VptDetectWrapper vptDetectWrapper; |
| | | |
| | | param.hp_recg_config = SY_CONFIG_OPEN; |
| | | param.hcp_recg_config = SY_CONFIG_OPEN; |
| | | param.vehicle_color_config = SY_CONFIG_OPEN; |
| | | param.vehicle_recg_config = SY_CONFIG_OPEN; |
| | | param.vehicle_pendant_det_recg_config = SY_CONFIG_OPEN; |
| | | |
| | | param.dbPath = "CarBodyFeature.db"; |
| | | param.log = SY_CONFIG_OPEN; |
| | | |
| | | vpt_pic_init(&handle, param); |
| | | |
| | | cv::VideoCapture capture; |
| | | capture.open(imgpath); |
| | |
| | | while (!process_image.empty()) { |
| | | |
| | | process_image.copyTo(image); |
| | | sy_img img; |
| | | img.set_data(image.cols, image.rows, image.channels(), image.data); |
| | | vptDetectWrapper.process_image(image); |
| | | |
| | | vptpic_result result; |
| | | result.info = new vptobj_info[MAX_DET_COUNT]; |
| | | int ret = vpt_pic_process(handle, img, &result); |
| | | |
| | | for (int i = 0; i < result.count; i++) { |
| | | char str_i[100]; |
| | | int colorIndex = result.info[i].obj_index; |
| | | if (colorIndex < 0 || colorIndex >= 9)continue; |
| | | sprintf(str_i, "%s:%.2f", type[colorIndex].c_str(), result.info[i].obj_score); |
| | | |
| | | rectangle(process_image, |
| | | cvPoint(result.info[i].obj_rect.left_ - 5, result.info[i].obj_rect.top_ - 15), |
| | | cvPoint(result.info[i].obj_rect.left_ + result.info[i].obj_rect.width_ + 5, |
| | | result.info[i].obj_rect.top_ + result.info[i].obj_rect.height_ + 10), |
| | | cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1); |
| | | |
| | | cv::putText(process_image, str_i, |
| | | cv::Point(result.info[i].obj_rect.left_, result.info[i].obj_rect.top_), |
| | | fontFace, fontScale, |
| | | cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8); |
| | | |
| | | //输出二次属性分析结果 |
| | | printfAnalysisRes(colorIndex, result.info[i].analysis_res); |
| | | } |
| | | // for (int i = 0; i < result.count; i++) { |
| | | // char str_i[100]; |
| | | // int colorIndex = result.info[i].obj_index; |
| | | // if (colorIndex < 0 || colorIndex >= 9)continue; |
| | | // sprintf(str_i, "%s:%.2f", type[colorIndex].c_str(), result.info[i].obj_score); |
| | | // |
| | | // rectangle(process_image, |
| | | // cvPoint(result.info[i].obj_rect.left_ - 5, result.info[i].obj_rect.top_ - 15), |
| | | // cvPoint(result.info[i].obj_rect.left_ + result.info[i].obj_rect.width_ + 5, |
| | | // result.info[i].obj_rect.top_ + result.info[i].obj_rect.height_ + 10), |
| | | // cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), 3, 1); |
| | | // |
| | | // cv::putText(process_image, str_i, |
| | | // cv::Point(result.info[i].obj_rect.left_, result.info[i].obj_rect.top_), |
| | | // fontFace, fontScale, |
| | | // cv::Scalar(color[colorIndex][0], color[colorIndex][1], color[colorIndex][2]), thickness, 8); |
| | | // |
| | | // //输出二次属性分析结果 |
| | | // printfAnalysisRes(colorIndex, result.info[i].analysis_res); |
| | | // } |
| | | |
| | | #ifdef _MSC_VER |
| | | cv::imshow("res", image); |
| | | cv::waitKey(0); |
| | | #else |
| | | char svpath[1024]; |
| | | memset(svpath, 0, sizeof(svpath)); |
| | | std::string strNewTime2 = AppUtil::getTimeUSecString(); |
| | | strNewTime2.append(".jpg"); |
| | | |
| | | sprintf(svpath, "vpt_res/%s", strNewTime2.c_str()); |
| | | imwrite(svpath, process_image); |
| | | // char svpath[1024]; |
| | | // memset(svpath, 0, sizeof(svpath)); |
| | | // std::string strNewTime2 = AppUtil::getTimeUSecString(); |
| | | // strNewTime2.append(".jpg"); |
| | | // |
| | | // sprintf(svpath, "vpt_res/%s", strNewTime2.c_str()); |
| | | // imwrite(svpath, process_image); |
| | | #endif |
| | | //release source |
| | | if (result.info != NULL) { |
| | | for (int i = 0; i < MAX_DET_COUNT; i++) { |
| | | if (result.info[i].analysis_res != NULL) { |
| | | delete result.info[i].analysis_res; |
| | | result.info[i].analysis_res = NULL; |
| | | } |
| | | } |
| | | delete[] result.info; |
| | | result.info = NULL; |
| | | } |
| | | |
| | | capture >> process_image;//读出每一帧的图像 |
| | | } |
| | | |
| | | |
| | | vpt_pic_release(&handle); |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | void printfAnalysisRes(int index, void *result) { |
| | | if (index == 0 && result != NULL) //行人二次属性分析结果 |
| | | { |
| | | hp_res *cur_res = (hp_res *) result; |
| | | |
| | | for (int i = 0; i < HP_FIR_INDEX_SIZE; i++) { |
| | | int resIndex = cur_res->res_objs[i].res_index; |
| | | cur_res->res_objs[i].res_prob; |
| | | cout << HpResStr[i][resIndex] << " " << endl; |
| | | |
| | | } |
| | | cout << endl << endl; |
| | | } else if ((index == 1 || index == 2) && result != NULL) //行人二次属性分析结果 |
| | | { |
| | | hcp_res *cur_res = (hcp_res *) result; |
| | | |
| | | for (int i = 0; i < HCP_FIR_INDEX_SIZE; i++) { |
| | | int resIndex = cur_res->res_objs[i].res_index; |
| | | cur_res->res_objs[i].res_prob; |
| | | // cout << HcpResStr[i][resIndex] << " " << endl; |
| | | } |
| | | cout << endl << endl; |
| | | } else if (index > 3 && index != 7 && result != NULL) //车辆二次属性分析结果输出 |
| | | { |
| | | vehicle_res *cur_res = (vehicle_res *) result; |
| | | |
| | | cout << "车颜色: " << colorLabel[cur_res->vc_res.res_index] << " " << cur_res->vc_res.res_prob << endl; |
| | | |
| | | cout << "车型识别: " << endl; |
| | | if (cur_res->vr_res.vehicle_brand != NULL) { |
| | | cout << " 车辆品牌 - " << cur_res->vr_res.vehicle_brand << endl; |
| | | delete[] cur_res->vr_res.vehicle_brand; |
| | | cur_res->vr_res.vehicle_brand = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_subbrand != NULL) { |
| | | cout << " 车辆子品牌 - " << cur_res->vr_res.vehicle_subbrand << endl; |
| | | delete[] cur_res->vr_res.vehicle_subbrand; |
| | | cur_res->vr_res.vehicle_subbrand = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_issue_year != NULL) { |
| | | cout << " 车辆年款 - " << cur_res->vr_res.vehicle_issue_year << endl; |
| | | delete[] cur_res->vr_res.vehicle_issue_year; |
| | | cur_res->vr_res.vehicle_issue_year = NULL; |
| | | } |
| | | if (cur_res->vr_res.vehicle_type != NULL) { |
| | | cout << " 车辆类型 - " << cur_res->vr_res.vehicle_type << endl; |
| | | delete[] cur_res->vr_res.vehicle_type; |
| | | cur_res->vr_res.vehicle_type = NULL; |
| | | } |
| | | |
| | | if (cur_res->vr_res.freight_ton != NULL) { |
| | | cout << " 货车吨级 - " << cur_res->vr_res.freight_ton << endl; |
| | | delete[] cur_res->vr_res.freight_ton; |
| | | cur_res->vr_res.freight_ton = NULL; |
| | | } |
| | | cout << " " << cur_res->vr_res.name_score << endl; |
| | | |
| | | |
| | | if (cur_res->vp_res.rect.height_ != 0 && cur_res->vp_res.rect.width_ != 0) { |
| | | cout << "车牌位置: " << cur_res->vp_res.rect.left_ << " " << cur_res->vp_res.rect.top_ << " " |
| | | << cur_res->vp_res.rect.width_ << " " << cur_res->vp_res.rect.height_ << endl; |
| | | |
| | | for (int m = 0; m < 7; m++) { |
| | | printf("%s", cur_res->vp_res.recg[m].character); |
| | | } |
| | | printf(" numScore = %.2f, detectScore = %.2f\n", cur_res->vp_res.numScore, cur_res->vp_res.detectScore); |
| | | } |
| | | |
| | | cout << endl; |
| | | } |
| | | } |