#include<iostream>#include<fstream>#include<string>#include<opencv2/opencv.hpp>#include"darknet.h"
image mat_to_image(cv::Mat mat){int w = mat.cols;int h = mat.rows;int c = mat.channels();
image im =make_image(w, h, c);unsignedchar*data =(unsignedchar*)mat.data;int step = mat.step;for(int y =0; y < h;++y){for(int k =0; k < c;++k){for(int x =0; x < w;++x){
im.data[k * w * h + y * w + x]= data[y * step + x * c + k]/255.0f;}}}return im;}intmain(int argc,char**argv){char weight_file[255]="../2.weights";char cfg_file[255]="../yolov3-tiny.cfg";
network *net =load_network_custom(cfg_file, weight_file,0,1);
std::string name ="../6.jpg";
cv::Mat img = cv::imread(name);
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);if(img.data ==NULL)return0;
image im =mat_to_image(img);
image sized =resize_image(im,(*net).w,(*net).h);float*X = sized.data;network_predict(*net, X);//
layer l =(*net).layers[0];cuda_pull_array(l.output_gpu, l.output, l.outputs*l.batch);//std::cout << l.outputs*l.batch << std::endl;
std::ofstream ofs("../output.txt");for(int i =0; i <16;++i){
ofs << l.output[i]<< std::endl;}
ofs.close();return0;}