main.cppbk 2.63 KB
#include "vpt.h"
#include <highgui.h>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include "sy_common.h"
#include "utools.h"

#ifdef _WIN32
#include<windows.h>
#else
#include <sys/time.h>
#endif


int main()
{

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;


printf("begin vpt_init\n");
vpt_init(&handle, param);
printf("finish  vpt_init\n");

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, "vpt_pic/%d.jpg", b);

#endif

		//cv::Mat img/*[b]*/;
		//memset(&img, 0, sizeof(img));
		img[b] = cv::imread(strpath);
		images[b].SetData(img[b].cols, img[b].rows, img[b].channels(), img[b].data);

	}


//vpt_batch(handle, images, batchsize, &result);



		vpt_batch(handle, images, batchsize, &result);


		for (int b = 0; b < batchsize; b++)
		{
			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(batch_mat[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;

 
	
}