VehicleRecognition.cpp 3.4 KB
#include "vehicle_recognition.h"
#include <iostream>
#include "sy_errorinfo.h"
#include "vehicle_features.h"
using namespace std;
int VehicleRecognition_Init(void *&handle, char*dbpath, int gpuid)
{
	vr_param params;
    params.gpuid = gpuid;
    params.mode = DEVICE_GPU;
	params.db_path = dbpath;
	params.engine = ENGINE_TENSORRT;
	params.max_batch = 20;
	params.serialize_file = "./serialize_file/VR";
//#ifdef _MSC_VER
//	params.dbPath = "../../../../vehicleRecognition_MCaffeTmpBody/db/CarBodyFeature.db";
//#else
//    params.dbPath = "/home/mliu/project/Project_MultiVPT/Video-Platform/video_structure_20190131/VehicleRecognition_body/db/CarBodyFeature.db";
//#endif
    int ret = vr_init(&handle, params);
    if (ret != 0)
    {
        cout << "VR Init Failed!" << endl;
        system("pause");
        return FAILED;
    }
	return SUCCESS;
}

#include <fstream>
int Vehicle_Recognition_Process(void *vhd_handle, void * vr_handle, sy_img * batch_img, int batchsize, vr_result *&vrresult)
{
	vhd_result * vhd_res = new vhd_result[batchsize]{};
	vhd_features_process(vhd_handle, batch_img, batchsize, vhd_res);
	for (int vhd_idx = 0; vhd_idx < batchsize; vhd_idx++)
	{
		vhd_result & result =  vhd_res[vhd_idx];
		for (int i = 0; i < result.obj_count_; ++i)         //车头
		{

		}
	}

	delete[] vhd_res;
}

int VehicleRecognition_Process(void * handle,  sy_img * batch_img, int batchsize, vr_result *&vrresult)
{
    //VR_Result *vr_result = new VR_Result[batchsize];
	/*vrresult = new vr_result[batchsize];
    for (int i = 0; i < batchsize; i++)
    {
		vrresult[i].vehicle_brand = new char[260];
		vrresult[i].vehicle_subbrand = new char[260];
		vrresult[i].vehicle_issue_year = new char[260];
		vrresult[i].vehicle_type = new char[260];
		vrresult[i].freight_ton = new char[260];
    }*/
	for (int i = 0; i < batchsize; i++)
	{
		if (batch_img[i].data_ == NULL)
			cout << i << " data null" << endl;
	}
	
	//cout << "begin vr_batch" << endl;
	vr_batch(handle, batch_img, batchsize, vrresult);
	//cout << "end vr_batch" << endl;
   /* for (int i = 0; i < batchsize; i++)
    {
		cout << i << ".识别结果:" << endl;
		cout << "  识别置信度: " << vr_result[i].name_score << endl;
		cout << "  车辆品牌 - " << vr_result[i].vehicleBrand << endl;
		cout << "  车辆子品牌 - " << vr_result[i].vehicleSubBrand << endl;
		cout << "  车辆年款 - " << vr_result[i].vehicleIssueYear << endl;
		cout << "  车辆类型 - " << vr_result[i].vehicleType << endl;
		cout << "  货车吨级 - " << vr_result[i].freightTon << endl;
		cout << endl;

        if (vr_result[i].vehicleBrand != NULL)
        {
            delete[] vr_result[i].vehicleBrand;
            vr_result[i].vehicleBrand = NULL;
        }
        if (vr_result[i].vehicleSubBrand != NULL)
        {
            delete[] vr_result[i].vehicleSubBrand;
            vr_result[i].vehicleSubBrand = NULL;
        }
        if (vr_result[i].vehicleIssueYear != NULL)
        {
            delete[] vr_result[i].vehicleIssueYear;
            vr_result[i].vehicleIssueYear = NULL;
        }
        if (vr_result[i].vehicleType != NULL)
        {
            delete[] vr_result[i].vehicleType;
            vr_result[i].vehicleType = NULL;
        }
        if (vr_result[i].freightTon != NULL)
        {
            delete[] vr_result[i].freightTon;
            vr_result[i].freightTon = NULL;
        }
    }*/

	return SUCCESS;
}

int VehicleRecognition_Release(void *& handle)
{
	if (handle)
	vr_release(&handle);
	return SUCCESS;
}