YOLO相关配置文件及YOLO测试源码


该资源包括YOLO权重文件,YOLO配置文件,YOLO框架的测试源码,主要针对YOLOv1-v3版本,方便大家入门YOLO。
资源截图
代码片段和文件信息
#pragma once
#include“stdafx.h“
#include
#include
#include
#include
#include
#include

using namespace std;
using namespace cv;
using namespace cv::dnn;

float confidenceThreshold = 0.1;
String modelConfiguration = “yolov2-tiny-voc.cfg“;//yolov2-tiny-voc.cfg
String modelBinary = “yolov2-tiny-voc.weights“;
ifstream classNamesFile(“voc.names“);

int dnn_yolo_syx_Img();
int dnn_yolo_syx_Cam();
int main()
{
dnn_yolo_syx_Img();
}

int dnn_yolo_syx_Img() {
dnn::Net net = readNetFromDarknet(modelConfiguration modelBinary);
//判断是否读入成功
if (net.empty())
{
printf(“Could not load net...
“);
return -1;
}
//定义一个string类的数组
vector classNamesVec;

if (classNamesFile.is_open())
{
string className = ““;
while (std::getline(classNamesFile className))
classNamesVec.push_back(className);
}

// 加载图像
Mat frame = imread(“111.jpg“);
if (frame.empty())
{
printf(“Could not load image...
“);
return -1;
}

Mat inputBlob;
inputBlob = blobFromImage(frame 1 / 255.F Size(416 416) Scalar() true false);
net.setInput(inputBlob “data“);

// 检测
Mat detectionMat = net.forward(“detection_out“);
vector layersTimings;
double freq = getTickFrequency() / 1000;
double time = net.getPerfProfile(layersTimings) / freq;
ostringstream ss;
ss << “detection time: “ << time << “ ms“;
putText(frame ss.str() Point(20 20) 0 0.5 Scalar(0 0 255));

// 输出结果
for (int i = 0; i < detectionMat.rows; i++)
{
const int probability_index = 5;
const int probability_size = detectionMat.cols - probability_index;
float *prob_array_ptr = &detectionMat.at(i probability_index);
size_t objectClass = max_element(prob_array_ptr prob_array_ptr + probability_size) - prob_array_ptr;
float confidence = detectionMat.at(i (int)objectClass + probability_index);

if (confidence > confidenceThreshold)
{

float x = detectionMat.at(i 0);
float y = detectionMat.at(i 1);
float width = detectionMat.at(i 2);
float height = detectionMat.at(i 3);
int xLeftBottom = static_cast((x - width / 2) * frame.cols);
int yLeftBottom = static_cast((y - height / 2) * frame.rows);
int xRightTop = static_cast((x + width / 2) * frame.cols);
int yRightTop = static_cast((y + height / 2) * frame.rows);
Rect object(xLeftBottom yLeftBottom xRightTop - xLeftBottom yRightTop - yLeftBottom);

rectangle(frame object Scalar(0 0 255) 2 8);
if (objectClass < classNamesVec.size())
{
ss.str(““);
ss << confidence;
String conf(ss.str());
String label = String(classNamesVec[objectClass]) + “: “ + conf;
int baseLine = 0;
Size labelSize = getTextSize(label CV_FONT_HERSHEY_SIMPLEX 0.5 1 &baseLine);
rectangle(frame Rect(Point(xLeftBottom yLeftBottom)
Size(l

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        9296  2018-05-31 17:40  111.jpg
     文件        6529  2018-09-08 09:31  LearnYolo.cpp
     文件         135  2018-04-17 18:24  voc.names
     文件        1456  2018-04-17 18:24  yolov2-tiny-voc.cfg
     文件    63471556  2018-04-17 18:24  yolov2-tiny-voc.weights

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)