资源简介
opencv4.0结合TensorFlow实现mask rcnn的目标分割效果Demo。
项目给予vs2015,其中没有加入mask_rcnn_inception_v2_coco训练数据集,如有导入需要可以去我的另一个资源中下载。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
using namespace cv;
using namespace dnn;
using namespace std;
// Initialize the parameters
float confThreshold = 0.5; // Confidence threshold
float maskThreshold = 0.3; // Mask threshold
vector classes;
vector colors;
void loadModal(Net& net);
void predictedAllobject(Mat& frame Net net);
// Draw the predicted bounding box
void drawBox(Mat& frame int classId float conf Rect box Mat& objectMask);
// Postprocess the neural network‘s output for each frame
void postprocess(Mat& frame const vector& outs);
int main()
{
Net net;
loadModal(net);
Mat frame;
// Create a window
static const string kWinName = “Deep learning object detection in OpenCV“;
namedWindow(kWinName WINDOW_NORMAL);
// get frame from the video
frame = imread(“3.jpg“);
predictedAllobject(frame net);
// Write the frame with the detection boxes
Mat detectedframe;
frame.convertTo(detectedframe CV_8U);
imshow(kWinName frame);
waitKey(0);
return 0;
}
void loadModal(Net& net)
{
// Load names of classes
string classesFile = “./mask_rcnn_inception_v2_coco_2018_01_28/mscoco_labels.names“;
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs line)) classes.push_back(line);
// Load the colors
string colorsFile = “./mask_rcnn_inception_v2_coco_2018_01_28/colors.txt“;
ifstream colorFptr(colorsFile.c_str());
while (getline(colorFptr line))
{
char* pEnd;
double r g b;
r = strtod(line.c_str() &pEnd);
g = strtod(pEnd NULL);
b = strtod(pEnd NULL);
Scalar color = Scalar(r g b 255.0);
colors.push_back(Scalar(r g b 255.0));
}
// Give the configuration and weight files for the model
String textGraph = “./mask_rcnn_inception_v2_coco_2018_01_28/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt“;
String modelWeights = “./mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb“;
// Load the network
net = readNetFromTensorflow(modelWeights textGraph);
net.setPreferableBackend(DNN_BACKEND_OPENCV);
net.setPreferableTarget(DNN_TARGET_CPU);
}
void predictedAllobject(Mat& frame Net net)
{
Mat blob;
// Create a 4D blob from a frame.
blobFromImage(frame blob 1.0 Size(frame.cols frame.rows) Scalar() true false);
//blobFromImage(frame blob);
//Sets the input to the network
net.setInput(blob);
// Runs the forward pass to get output from the output layers
std::vector outNames(2);
outNames[0] = “detection_out_final“;
outNames[1] = “detection_masks“;
vector outs;
net.forward(outs outNames);
// Extract the bounding box and mask for each of the detected objects
postprocess(frame outs);
// Put efficiency information. The function getPerfProfile returns the overall ti
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-02-21 10:04 opencv\
目录 0 2019-02-18 10:41 opencv\.vs\
目录 0 2019-02-18 10:41 opencv\.vs\opencv\
目录 0 2019-02-18 10:41 opencv\.vs\opencv\v14\
文件 34304 2019-02-21 10:04 opencv\.vs\opencv\v14\.suo
目录 0 2019-02-21 09:58 opencv\opencv\
文件 1300 2019-02-18 10:41 opencv\opencv.sln
文件 15224832 2019-02-21 10:04 opencv\opencv.VC.db
文件 288944 2019-01-28 11:50 opencv\opencv\1.jpg
文件 239931 2019-01-28 11:50 opencv\opencv\2.jpg
文件 213567 2019-01-28 11:50 opencv\opencv\3.jpg
文件 6601 2019-02-21 09:58 opencv\opencv\imgmain.cpp
文件 5706 2019-02-18 16:28 opencv\opencv\opencv.vcxproj
文件 948 2019-02-18 16:28 opencv\opencv\opencv.vcxproj.filters
目录 0 2019-02-18 10:53 opencv\opencv\x64\
目录 0 2019-02-21 09:58 opencv\opencv\x64\Debug\
文件 1124221 2019-02-21 09:58 opencv\opencv\x64\Debug\imgmain.obj
文件 1089484 2019-02-18 16:09 opencv\opencv\x64\Debug\main.obj
文件 728 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.log
目录 0 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\
文件 1294 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\CL.command.1.tlog
文件 57110 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\CL.read.1.tlog
文件 1378 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\CL.write.1.tlog
文件 1404 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\li
文件 3568 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\li
文件 676 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\li
文件 224 2019-02-21 09:58 opencv\opencv\x64\Debug\opencv.tlog\opencv.lastbuildstate
文件 1281024 2019-02-21 09:58 opencv\opencv\x64\Debug\vc140.idb
文件 2265088 2019-02-21 09:58 opencv\opencv\x64\Debug\vc140.pdb
目录 0 2019-02-18 10:53 opencv\x64\
目录 0 2019-02-28 14:35 opencv\x64\Debug\
............此处省略3个文件信息
- 上一篇:LifeChangerEA.zip
- 下一篇:LOINC精简版字典
相关资源
- 深度学习word2vec学习笔记.docx
- 深度学习笔记之RBM修正版
- 《深度学习》自建搜狗各学科中文词
- Learning TensorFlow_A Guide to Building Deep L
- opencv+qt通过CGI读取网络摄像头工程
- 生成对抗网络的技术与应用
- 安装opencv342缺失的boostdesc_bgm.i系列文
- OpenCV2.4.4实现HOG行人检测
- opencv的运动跟踪
- sift算法VC实现需要OPENCV
- opencv标定单目相机
- opencv 数字识别
- itti视觉显著性计算模型opencv实现
- 异常行为检测
- qt+opencv视频图像采集与基于tcp协议的
- keras实现的VGGface 特征提取,用来抽取
- opencv2.4.3和4.0函数手册带目录可搜索
- 遗留物检测
- 行为识别综述
- 笔记本OpenCV调用摄像头进行人脸捕捉
- VS+OPENCV手势识别
- opencv下haarclassifiercascade加上LBPHFaceRe
- 图片动漫风格化
- 高分辨率遥感影像的深度学习变化检
- 基于SVM与ANN的车牌识别
- OpenCV实现同一窗口显示多幅图片
- haar特征的手势检测OpenCV
- 基于opencv的人脸表情识别的预处理
- opencv+qt+vs的摄像头视频显示和处理G
- 无痛的机器学习 第一季
评论
共有 条评论