#include "vpt_pic.h"
|
//#include <highgui.h>
|
#include <opencv2/opencv.hpp>
|
#include <iostream>
|
#include <fstream>
|
#include <string>
|
#include "sy_common.h"
|
#include "mainAssist.h"
|
|
#ifdef _WIN32
|
#include<windows.h>
|
#else
|
|
#include <sys/time.h>
|
#include <basic/util/app/AppUtil.h>
|
|
#endif
|
|
using namespace std;
|
|
|
void printfAnalysisRes(int index, void *result);
|
|
int main(int argc, char **argv) {
|
string imgpath;
|
|
if (argc < 2) {
|
printf("Parameter number not right.\n");
|
return 0;
|
} else {
|
imgpath = argv[1];
|
}
|
|
printf("SDK Version: %s\n", vpt_pic_get_version());
|
|
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;
|
|
void *handle;
|
vptpic_param param;
|
param.mode = DEVICE_GPU;
|
param.gpuid = 0;
|
|
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);
|
|
cv::Mat process_image;
|
capture >> process_image;//读出每一帧的图像
|
|
cv::Mat image;
|
|
while (!process_image.empty()) {
|
|
process_image.copyTo(image);
|
sy_img img;
|
img.set_data(image.cols, image.rows, image.channels(), image.data);
|
|
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);
|
}
|
|
#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);
|
#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;
|
}
|
}
|