当前位置:网站首页>The DNN of OpenCV is used to read onnx as the prediction end to realize classification
The DNN of OpenCV is used to read onnx as the prediction end to realize classification
2022-04-23 21:57:00 【Three stone orders】
Be careful :
1、size Consistent with training ;
2、 Used in training Normalize Words , because blobFromImage Variance is not supported , Need to rewrite blobFromImage;
3、 Format of prediction results , Ensure that the corresponding indicators are read correctly ;
class ModelFlipClass
{
private:
Net net;
public:
bool Read(string pathNet);
int Detect(string strImgPath);
};
bool ModelFlipClass::Read(string pathNet)
{
try {
net = readNet(pathNet);
}
catch (const std::exception&) {
return false;
}
net.setPreferableBackend(cv::dnn::DNN_BACKEND_DEFAULT);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
return true;
}
int ModelXRayFlipClass::Detect(string strImgPath)
{
try
{
Mat imgInput = imread(strImgPath, IMREAD_UNCHANGED);
Mat imgNorm;
normalize(imgInput, imgNorm, 0, 255, NORM_MINMAX);//16 The bit changes to 8 position
convertScaleAbs(imgNorm, imgNorm);
Mat imRGB;
cvtColor(imgNorm, imRGB, COLOR_GRAY2BGR);
const int nHight = 400;// When training is needed transforms Of Resize bring into correspondence with
const int nWight = 200;
Mat blob;
blobFromImage(imRGB, blob, 1 / 255.0, cv::Size(nWight, nHight), Scalar(), true, false);
net.setInput(blob);
vector<cv::Mat> netOutputImg;
net.forward(netOutputImg, net.getUnconnectedOutLayersNames());
float* pdata = (float*)netOutputImg[0].data;
vector<float> vecScore;
for (size_t i = 0; i < 2; i++) // There are two kinds of , So here is 2
{
vecScore.push_back(pdata[i]);
}
auto maxPosition = max_element(vecScore.begin(), vecScore.end());
int nMaxIndex = maxPosition - vecScore.begin();//vdbAmplitude The index when the absolute value of the value in is the largest
return nMaxIndex;
}
catch (const std::exception&) {
return -1;
}
}
版权声明
本文为[Three stone orders]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204200615437287.html
边栏推荐
- How Axure installs a catalog
- 引入结构化并发,Swift 5.5 发布!
- Unit function expansion
- 1. Finishing huazi Mianjing -- 1
- What if Jenkins forgot his password
- How to play the guiding role of testing strategy
- thinkphp5+数据大屏展示效果
- MySQL 回表
- [leetcode refers to the two numbers of offer 57. And S (simple)]
- Echerts add pie chart random color
猜你喜欢
Deno 1.13.2 发布
Database Experiment 2 data query
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
Two Stage Detection
Correction of date conversion format error after Oracle adds a row total
Preliminary analysis of Airbase
ROS学习笔记-----ROS的使用教程
Sharpness difference (SD) calculation method of image reconstruction and generation domain index
Database experiment I database definition and data import
[leetcode refers to the two numbers of offer 57. And S (simple)]
随机推荐
[leetcode refers to the two numbers of offer 57. And S (simple)]
[leetcode refers to the substructure of offer 26. Tree (medium)]
[leetcode refers to the maximum profit of offer 63. Stock (medium)]
The computer is out of power. How did I pass the terrible interview of Tencent cloud?
Online Excel to CSV tool
Correction of date conversion format error after Oracle adds a row total
ROS学习笔记-----ROS的使用教程
Arm architecture assembly instructions, registers and some problems
如何发挥测试策略的指导性作用
CUDA, NVIDIA driver, cudnn download address and version correspondence
在线时序流程图制作工具
Keras. Layers introduction to various layers
【SDU Chart Team - Core】SVG属性类设计之枚举
Pipes and xargs
亚马逊和Epic将入驻,微软应用商城向第三方开放
C, print the source program of beautiful bell triangle
ubutnu20安装CenterNet
A solution of C batch query
Pyuninstaller package exe cannot find the source code when running, function error oserror: could not get source code