#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/imgproc.hpp"
#include<opencv2/opencv.hpp>
#include<opencv2/dnn.hpp>
#include <iostream>
using namespace std;
using namespace cv;
const size_t inWidth = 300;
const size_t inHeight = 300;
const float WHRatio = inWidth / (float)inHeight;
const char* classNames\[\] = { "background","face" };
void saveMat(cv::Mat inputMat,char* filename);
int main() {
String model = "opt_srcnn_vgg_test.pb";
dnn::Net net = cv::dnn::readNetFromTensorflow(model);
Mat img = imread("test.bmp");
Mat input;
img.copyTo(input);
cvtColor(input,input,CV_BGR2GRAY);//turn the rgb to gray
cout<<"load finish!"<<endl;
Mat inputBlob = dnn::blobFromImage(input, 1./255, Size(img.cols, img.rows));
imshow("input",input);
waitKey(0);
cout<<inputBlob.size;
net.setInput(inputBlob, "input");//set the network input,
cout<<"feed finish!"<<endl;
Mat pred = net.forward();
resize(pred,pred,Size(img.cols,img.rows));
imshow("result",pred);
waitKey(0);
return 0;
}
我们尝试使用opencv dnn使用tensorflow训练的.pb文件来实现超分辨率。我们的预期结果如图1所示,但我们得到了图2的结果(注意:我们确定.pb文件没有错误)。为什么是这样?谢谢!