Visual Studio 2013 Express Visual C++( アンマネージドコード ) OpenCV 3.1 |
■263.OpenCV 画像修復 | Prev Top Next | |
|
今回は画像修復します。
#include <iostream> #include <opencv2/highgui/highgui.hpp> #include <opencv2/videostab/inpainting.hpp> #pragma comment( lib, "opencv_world300d.lib" ) int main(int argc, const char* argv[]) { int hr = -1; try { cv::Mat src, mask, dst; src = cv::imread("D:/TEMP/MaverickProj/Image/OpenCV/25/Texture.png", cv::IMREAD_COLOR); mask = cv::imread("D:/TEMP/MaverickProj/Image/OpenCV/25/Mask.png", cv::IMREAD_GRAYSCALE); cv::inpaint(src, // 入力画像.8ビット,1あるいは3チャンネル. mask, // 8ビット,1チャンネルの修復マスク.非0ピクセルが修復領域 dst, 5, // 修復される各点を中心とする近傍円形領域の半径 cv::INPAINT_NS // 修復アルゴリズム ); // 元画像表示用のウィンドウ作成 cv::namedWindow("Source", 1); // 元画像をウィンドウに表示 cv::imshow("Source", src); // マスク表示用のウィンドウ作成 cv::namedWindow("Mask", 1); // マスク画像をウィンドウに表示 cv::imshow("Mask", mask); // 修正後の画像表示用のウィンドウ作成 cv::namedWindow("画像修正", 1); // 修正後の画像をウィンドウに表示 cv::imshow("画像修正", dst); cv::waitKey(0); hr = 0; } catch (cv::Exception ex) { std::cout << ex.err << std::endl; } // ウィンドウの破棄 cv::destroyAllWindows(); return hr; }元画像
マスク画像
修復後( INPAINT_NS )
修復後( INPAINT_TELEA )