想用C++实现基于opencv库的逆滤波
代码和结果如下,不知道问题出在哪里,希望有会的指教一下,谢谢。
#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char argv[])
{
Mat img = imread("D:\\opencv-4.5.5\\doc\\tutorials\\imgproc\\out_of_focus_deblur_filter\\images\\original.jpg", IMREAD_GRAYSCALE);
int hei = img.rows;
int wei = img.cols;
imshow("图像", img);
Mat psf = imread("D:\\opencv-4.5.5\\doc\\tutorials\\imgproc\\out_of_focus_deblur_filter\\images\\psf.png", IMREAD_GRAYSCALE);
copyMakeBorder(psf, psf, (img.rows - psf.rows) / 2, (img.rows - psf.rows) / 2, (img.cols - psf.cols) / 2, (img.cols - psf.cols) / 2, cv::BorderTypes::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
Mat If, Pf, deblurred;
img.convertTo(img, CV_32F, 1.0 / 255.0);
dft(img, If, cv::DFT_COMPLEX_OUTPUT);
psf.convertTo(psf, CV_32F, 1.0 / 255.0);
dft(psf, Pf, cv::DFT_COMPLEX_OUTPUT);
Mat a = If / Pf;
idft(a, deblurred, cv::DFT_SCALE | cv::DFT_REAL_OUTPUT);
// 显示结果图像
cv::imshow("Restored Image", deblurred);
cv::waitKey(0);
return 0;
}