资源简介
HED深度学习边缘提取的c++接口测试程序
代码片段和文件信息
#include
#include
#include
#include
#include
#include “caffe/data_transformer.hpp“
#include “caffe/util/io.hpp“
#include “caffe/util/math_functions.hpp“
#include “caffe/util/rng.hpp“
using namespace caffe;
using namespace cv;
using namespace std;
#define PRINT_SHAPE1(x) \
std::cout << (x).num() << “\t“ << (x).channels() << “\t“ << (x).height() << “\t“ << (x).width() << “\n“;
#define PRINT_SHAPE2(x) \
std::cout << (x)->num() << “\t“ << (x)->channels() << “\t“ << (x)->height() << “\t“ << (x)->width() << “\n“;
#define PRINT_DATA(x) \
std::cout << (x)[0] << “\t“ << (x)[1] << “\t“<<(x)[2]<<“\n“;
class EdgeDetect
{
public:
Mat mean_;
Size input_geometry;
int num_channels;
shared_ptr > net;
public:
EdgeDetect(const string& model_file const string& trained_fileconst string& mean_file);
void WrapInputlayer(std::vector* input_channels);
void Preprocess(const cv::Mat& imgstd::vector* input_channels);
void SetMean(const string& mean_file);
};
EdgeDetect::EdgeDetect(const string& model_fileconst string& trained_fileconst string& mean_file)
{
Caffe::set_mode(Caffe::CPU);
net.reset(new Net(model_file TEST));
net->CopyTrainedlayersFrom(trained_file);
CHECK_EQ(net->num_inputs() 1) << “Network should have exactly one input.“;
//CHECK_EQ(net->num_outputs() 1) << “Network should have exactly one output.“;
Blob* input_layer = net->input_blobs()[0];
num_channels = input_layer->channels();
CHECK(num_channels == 3 || num_channels == 1)<< “Input layer should have 1 or 3 channels.“;
input_geometry = cv::Size(input_layer->width() input_layer->height());
SetMean(mean_file);
}
void EdgeDetect::Preprocess(const cv::Mat& imgstd::vector* input_channels)
{
cv::Mat sample;
if (img.channels() == 3 && num_channels == 1)
cv::cvtColor(img sample CV_BGR2GRAY);
else if (img.channels() == 4 && num_channels == 1)
cv::cvtColor(img sample CV_BGRA2GRAY);
else if (img.channels() == 4 && num_channels == 3)
cv::cvtColor(img sample CV_BGRA2BGR);
else if (img.channels() == 1 && num_channels == 3)
cv::cvtColor(img sample CV_GRAY2BGR);
else
sample = img;
cv::Mat sample_resized;
if (sample.size() != input_geometry)
cv::resize(sample sample_resized input_geometry);
else
sample_resized = sample;
imshow(“resize“sample_resized);
cv::Mat sample_float;
if (num_channels == 3)
sample_resized.convertTo(sample_float CV_32FC3);
else
sample_resized.convertTo(sample_float CV_32FC1);
cv::Mat sample_normalized;
cv::subtract(sample_float mean_ sample_normalized);
/* 3通道数据分开存储 */
cv::split(sample_normalized *input_channels);
CHECK(reinterpret_cast(input_channels->at(0).data) == net->input_blobs()[0]->cpu_data()) << “Input channels are not wrapping the input layer of the network.“;
}
//加载均值文件
void
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 47609 2015-10-01 10:38 HEDC++\3063.jpg
文件 8186 2017-02-28 11:50 HEDC++\deploy.prototxt
文件 58876104 2017-03-31 09:17 HEDC++\hed_pretrained_bsds.caffemodel
文件 786446 2014-02-25 16:24 HEDC++\imagenet_mean.binaryproto
文件 10130 2017-06-21 15:34 HEDC++\main.cpp
目录 0 2017-06-21 15:34 HEDC++
----------- --------- ---------- ----- ----
59728475 6
相关资源
- C++程序设计04737单页版
- MFC+VS2013+OpenCV打开任意路径下的图片并
- 图书管理系统c++ 数据库
- 用户权限管理模块C++实现
- 拼图游戏大型课程设计C# C++
- cminus语法分析器源代码完整版
- sqlParserC++
- C++Primer中文版第五版
- 信息学奥赛一本通C++第五版pdf以及配
- 《Linux多线程服务端编程:使用muduo
- 信息学奥赛一本通C++版配套光盘第五
- C++编程思想两卷合订本_带书签_高清完
- 编译原理--语法分析 实验 C++版
- Opencv C++数字图像处理——空域增强
- opencv和C++版相机标定
- 计算机图形学基础教程 VisualC++版 习
- MFC+YOLOv3完美版.zip
- 深入应用C++11完整版本.pdf.rar
- 大规模C++ 程序设计高清pdf
- 人群计数-c++实现内有caffemodel和deplo
- C++(qt)游戏实战项目:坦克大战(源
- Visual C++ Build Tools 2015 离线包.part7/7
- c++从入门到精通第2版
- Qt5.9C++开发指南 源码 资源.zip
- windows pe 权威指南.pdf C++反汇编与逆向
- VC++运行库一键安装
- yolov3+opencv3.4.2 C++源码
- Qt5.9 c++开发指南.part1.rar
- 编译原理--递归下降分析程序C++
- 深入理解C++11:C++11新特性解析与应用
评论
共有 条评论