資源簡介
該資源包括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...\n“);
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...\n“);
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:?“?< putText(frame?ss.str()?Point(20?20)?0?0.5?Scalar(0?0?255));
//?輸出結果
for?(int?i?=?0;?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? {
ss.str(““);
ss?< 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
評論
共有 條評論