使用caffe训练的深度学习做目标检测(车辆检测)

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/dnn/dnn.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/objdetect/objdetect.hpp"

#include 
#include 
#include 
#include 

#include 

int main(int argc,char* argv[]){
	//init time param
	clock_t t_start,t_end;

	//init dnn
	cv::Ptr importer;
	std::string modelTxt = "./deploy.prototxt";
	std::string modelBin = "./googlenet_finetune_web_car_iter_10000.caffemodel";
	importer = cv::dnn::createCaffeImporter(modelTxt,modelBin);
        
	if(!importer){
		std::cerr << "Can't load network by using the following files: " << std::endl;
		std::cerr << "prototxt:   " << modelTxt << std::endl;
		std::cerr << "caffemodel: " << modelBin << std::endl;
		exit(-1);
	}
	cv::dnn::Net net;
	importer->populateNet(net);
	importer.release();

	//init cascades
	std::string cascadeModel = "./cars.xml";
	cv::CascadeClassifier cascade;
	if( !cascade.load(cascadeModel) ){
		std::cerr << "Can't load cascade model:" << std::endl;
		std::cerr << "cascade:   " << cascadeModel << std::endl;
		exit(-1);
	}

	cv::Mat frame;
	char image_path[32];

	//int i = atoi(argv[1]);

	for(int i=1;i<=1700;i++){

		t_start = clock();

		sprintf(image_path,"/home/xyl/caffe/lesson4/cars_input/cars_input/in%06d.jpg",i);
		std::cout< cars;
		cascade.detectMultiScale(frame,cars,1.1,2,0);
		for(int j=0;j

运行之后,结果是这样的:

使用caffe训练的深度学习做目标检测(车辆检测)_第1张图片


你可能感兴趣的:(深度学习Caffe)