#include "vehicle_features.h" #include #include "sy_errorinfo.h" using namespace std; void RectboundCheck(int Width, int Height, int &left, int &top, int &width, int &height); int vhd_features_init(void *&handle, char*dbpath, int gpuid) { vhd_param params; params.gpuid = gpuid; params.mode = DEVICE_GPU; params.process_min_length = 512; params.threshold = 0.5; params.engine = ENGINE_TENSORRT; params.max_batchsize = 20; params.serialize_file = "./serialize_file/VHD"; // params.db_path = dbpath; if (vhd_init(&handle, ¶ms) !=0) { cout << "Init vhd Failed!" << endl; return FAILED; } return SUCCESS; } int vf_features_init(void *&handle, char*dbpath, int gpuid) { vf_param params; params.gpuid = gpuid; params.mode = DEVICE_GPU; params.serialize_file = NULL; params.engine = ENGINE_TENSORRT; params.max_batch = 20; params.serialize_file = "./serialize_file/VF"; // params.db_path = dbpath; if (vf_init(&handle, params) !=0) { cout << "Init VF Failed!" << endl; return FAILED; } return SUCCESS; } int vhd_features_process(void * handle, sy_img * batch_img, int batch_size, vhd_result*& result) { for (int i = 0; i < batch_size; i++) { if (batch_img[i].data_ == NULL) cout << i << " data null" << endl; } vhd_process_batch(handle, batch_img, batch_size, result); for (int b = 0; b < batch_size; b++) { for (int c = 0; c < result[b].obj_count_; c++) { RectboundCheck(batch_img[b].w_, batch_img[b].h_, result[b].obj_results_[c].obj_rect.left_, result[b].obj_results_[c].obj_rect.top_, result[b].obj_results_[c].obj_rect.width_, result[b].obj_results_[c].obj_rect.height_); } } return SUCCESS; } #include #include #include int vf_features_process(void * handle, sy_img * batch_img, int batch_size, int8**& result) { for (int i = 0; i < batch_size; i++) { if (batch_img[i].data_ == NULL) cout << i << " data null" << endl; } int **fea = new int*[batch_size]; for (int i = 0; i < batch_size; i++) { fea[i] = new int[FEATURESIZE]; } vf_feature_batch(handle, batch_img, batch_size, fea); for (int i = 0; i < batch_size; i++) { for (int f = 0; f < FEATURESIZE; f++) { result[i][f] = (unsigned char)fea[i][f]; } } if (fea) { for (int b = 0; b < batch_size; b++) { if(fea[b]) { delete[] fea[b]; fea[b] = NULL; } } delete[] fea; fea = NULL; } return SUCCESS; } int vhd_feature_release(void *& handle) { if (handle) vhd_release(&handle); return SUCCESS; } int vf_feature_release(void *& handle) { if (handle) vf_release(&handle); return SUCCESS; } void RectboundCheck(int Width, int Height, int &left, int &top, int &width, int &height) { #ifdef _DEBUG printf("img: Width = %d Height = %d\n", Width, Height); printf("Src: width = %d height = %d, x = %d, y =%d\n", rect->width, rect->height, rect->left, rect->top); #endif if (left <= 0) left = 0; if (left >= (Width - 1)) left = Width - 2; if (top < 0) top = 0; if (top >= (Height - 1)) top = Height - 2; if ((left + width) >= Width) width = Width - left - 1; if (width <= 0) width = 0; if ((top + height) >= Height) height = Height - 1 - top; if (height <= 0) height = 0; #ifdef _DEBUG printf("Dst: width = %d, height = %d, x = %d, y =%d\n", rect->width, rect->height, rect->left, rect->top); #endif }