当前位置:网站首页>[opencv450 samples] inpaint restores the selected region in the image using the region neighborhood
[opencv450 samples] inpaint restores the selected region in the image using the region neighborhood
2022-06-25 23:19:00 【Ten year dream Lab】

The left side is the repaired Source image on the right
Source code :
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/photo.hpp"
#include <iostream>
using namespace cv;
using namespace std;
static void help(char** argv)
{
cout << "\nCool inpainging demo. Inpainting repairs damage to images by floodfilling the damage \n"
<< "with surrounding image areas.\n"
"Using OpenCV version %s\n" << CV_VERSION << "\n"
"Usage:\n" << argv[0] << " [image_name -- Default fruits.jpg]\n" << endl;
cout << "Hot keys: \n"
"\tESC - quit the program\n"
"\tr - restore the original image\n"
"\ti or SPACE - run inpainting algorithm\n"
"\t\t(before running it, paint something on the image)\n" << endl;
}
Mat img, inpaintMask;
Point prevPt(-1, -1);
static void onMouse(int event, int x, int y, int flags, void*)
{
if (event == EVENT_LBUTTONUP || !(flags & EVENT_FLAG_LBUTTON))// Non left key press Left key up
prevPt = Point(-1, -1);// Reset the previous point
else if (event == EVENT_LBUTTONDOWN) // Press the left key for the first time
prevPt = Point(x, y);// Last point
else if (event == EVENT_MOUSEMOVE && (flags & EVENT_FLAG_LBUTTON))// Left key press Mouse movement
{
Point pt(x, y);// Current point
if (prevPt.x < 0)
prevPt = pt;// Last point
line(inpaintMask, prevPt, pt, Scalar::all(255), 5, 8, 0);// Draw the repair area , Nonzero pixel
line(img, prevPt, pt, Scalar::all(255), 5, 8, 0);// Draw... On the original
prevPt = pt;// Update the previous point
imshow("image", img);
}
}
int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv, "{@image|fruits.jpg|}");
help(argv);
// Load image
string filename = samples::findFile(parser.get<string>("@image"));
Mat img0 = imread(filename, IMREAD_COLOR);
if (img0.empty())
{
cout << "Couldn't open the image " << filename << ". Usage: inpaint <image_name>\n" << endl;
return 0;
}
namedWindow("image", WINDOW_AUTOSIZE);
img = img0.clone();
inpaintMask = Mat::zeros(img.size(), CV_8U);// Repair mask
imshow("image", img);
setMouseCallback("image", onMouse, NULL);// Mouse callback
for (;;)
{
char c = (char)waitKey();
if (c == 27)
break;
if (c == 'r')
{
inpaintMask = Scalar::all(0);
img0.copyTo(img);
imshow("image", img);
}
if (c == 'i' || c == ' ')
{
Mat inpainted;
/** @brief Use region neighborhood to restore the selected region in the image .
@param src Input 8 position 、16 Bit unsigned or 32 Bit floating point 1 Channel or 8 position 3 Channel image .
@param inpaintMask Repair mask ,8 position 1 Channel image . Non zero pixels represent areas that need to be repaired .
@param dst Output and src Images of the same size and type .
@param inpaintRadius The radius of the circular neighborhood of each repair point considered by the algorithm .
@param The tag may be cv::INPAINT_NS or cv::INPAINT_TELEA How to fix it
This function reconstructs the selected image region from the pixels near the region boundary . This function can be used to remove dust and scratches from scanned photos , Or remove unwanted objects from still images or videos . For more information , see also <http://en.wikipedia.org/wiki/Inpainting>.
@ note
- Examples of using repair techniques can be found in opencv_source_code/samples/cpp/inpaint.cpp find
- (Python) Examples of using repair techniques can be found in opencv_source_code/samples/python/inpaint.py find
*/
inpaint(img, inpaintMask, inpainted, 3, INPAINT_TELEA);
imshow("inpainted image", inpainted);
}
}
return 0;
}
边栏推荐
- ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数
- ES6-- 集合
- Unity technical manual - life cycle rotation rotationoverlifetime- speed rotation rotationbyspeed- and external forces
- 小程序-视图与逻辑
- Intimacy - [comfortable exit] - final communication to reduce injury
- 汇编语言核心要点
- ES6-- 模板字符串、对象的简化写法、箭头函数
- Global and Chinese flame retardant ABS industry development trend and market demand analysis report 2022 ~ 2028
- zabbix_ Server configuration file details
- String deformation (string case switching and realization)
猜你喜欢

oracle -- 表操作

小程序绘制一个简单的饼图

Why is the frame rate calculated by opencv wrong?

The applet draws a simple pie chart

STM32 development board + smart cloud aiot+ home monitoring and control system

字符串变形(字符串大小写切换和变现)

LM小型可编程控制器软件(基于CoDeSys)笔记十七:pto脉冲功能块
[email protected]@COLLATION_CONNECTION */"/>.sql数据库导入错误:/*!40101 SET @[email protected]@COLLATION_CONNECTION */

Unity的Ping類使用

Trillions of hot money smashed into the space economy. Is it really a good business?
随机推荐
zabbix_ Server configuration file details
判断预约时间是否已经过期
问题记录与思考
牛客小白月賽52--E 分組求對數和(二分)
Thinking while walking
Recently prepared to translate foreign high-quality articles
2. What is the geometric meaning of a vector multiplying its transpose?
APP测试要点
使用EAST ocr遇到的坑解决方法(编译lanms)
Does jQuery cache any selectors- Does jQuery do any kind of caching of “selectors”?
ES6-- 模板字符串、对象的简化写法、箭头函数
App test points
The Ping class of unity uses
UE4_UE5結合offline voice recognition插件做語音識別功能
Flex & Bison Start
Circuit module analysis exercise 5 (power supply)
OSPF - detailed explanation of GRE tunnel (including configuration command)
最近准备翻译外国优质文章
Comp2913 database
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系