OpenCV3.3深度神经网络DNN模块 实例3:SSD模型实现对象检测
1 #include <opencv2/opencv.hpp> 2 #include <opencv2/dnn.hpp> 3 #include <iostream> 4 5 using namespace cv; 6 using namespace cv::dnn; 7 using namespace std; 8 9 const size_t width = 300;//模型尺寸为300*300 10 const size_t height = 300; 11 //label文件 12 String labelFile = "D:/opencv3.3/opencv/sources/samples/data/dnn/labelmap_det.txt"; 13 //模型文件 14 String modelFile = "D:/opencv3.3/opencv/sources/samples/data/dnn/VGG_ILSVRC2016_SSD_300x300_iter_affemodel"; 15 //模型描述文件 16 String model_text_file = "D:/opencv3.3/opencv/sources/samples/data/dnn/deploy.prototxt"; 17 18 vector<String> readLabels(); 19 const int meanValues[3] = ; 20 static Mat getMean(const size_t &w, const size_t &h) 27 merge(channels, mean); 28 return mean; 29 } 30 31 static Mat preprocess(const Mat &frame) 39 40 int main(int argc, char** argv) 46 namedWindow("input image", CV_WINDOW_AUTOSIZE); 47 imshow("input image", frame); 48 49 vector<String> objNames = readLabels(); 50 // import Caffe SSD model 51 Ptr<dnn::Importer> importer; 52 try 55 catch (const cv::Exception &err) 58 //初始化网络 59 Net net; 60 importer>populateNet(net); 61 importer.release(); 62 Mat input_image = preprocess(frame);//获取输入图像 64 Mat blobImage = blobFrImage(input_image);//将图像转换为blob 65 66 net.setInput(blobImage, "data");//将图像转换的blob数据输入到网络的第一层“data”层,见deploy.protxt文件 67 Mat detection = net.forward("detection_out");//结果输出(最后一层“detection_out”层)输出给detection 68 Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>()); 69 float confidence_threshold = 0.2;//自信区间,可以修改,越低检测到的物体越多 70 for (int i = 0; i < detectionMat.rows; i++) 85 } 86 imshow("ssddemo", frame); 87 88 waitKey(0); 89 return 0; 90 } 91 92 vector<String> readLabels() 99 string name; 100 while (!fp.eof()) 107 } 108 return objNames; 109 }
上一篇:OpenCV3.3深度神经网络DNN模块 实例2:GoogleNet-Caffe模型实现图像分类
下一篇:OpenCV3.3深度神经网络DNN模块 实例4:SSD-MobileNet模型实时对象检测
OpenCV
pla文件怎么看,pla文件用什么打开?
pl1文件怎么看,pl1文件用什么打开?
pl文件怎么看,pl文件用什么打开?
pl0文件怎么看,pl0文件用什么打开?
pkt文件怎么看,pkt文件用什么打开?
pkm文件怎么看,pkm文件用什么打开?
pks文件怎么看,pks文件用什么打开?
pka文件怎么看,pka文件用什么打开?
pkh文件怎么看,pkh文件用什么打开?
pkg文件怎么看,pkg文件用什么打开?