#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);
unsigned char *data = (unsigned char *)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;
}
int main(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) return 0;
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();
return 0;
}
05-18
3442
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交