当前位置:网站首页>[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;
}
边栏推荐
- What do l and R of earphone mean?
- What is 5g? What can 5g do? What will 5g bring in the future?
- Ue4 Ue5 combine le plug - in de reconnaissance vocale de bureau pour la reconnaissance vocale
- ES6 - numerical extension and object extension
- 2. What is the geometric meaning of a vector multiplying its transpose?
- ES6 --- 数值扩展、对象拓展
- 小程序-视图与逻辑
- 等价类,边界值,场景法的使用方法和运用场景
- 2022年中职组网络安全新赛题
- PDM fur
猜你喜欢
[eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
Unity的Ping類使用
Eureka core ⼼ source code analysis
1281_FreeRTOS_vTaskDelayUntil实现分析
干货丨产品的可行性分析要从哪几个方面入手?
【opencv450-samples】inpaint 使用区域邻域恢复图像中的选定区域
Baidu: in 2022, the top ten hot spots will rise and the profession will be released. There is no suspense about the first place!
字符串变形(字符串大小写切换和变现)
荣耀推出积分商城,支持兑换各种荣耀产品
多模态数据也能进行MAE?伯克利&谷歌提出M3AE,在图像和文本数据上进行MAE!最优掩蔽率可达75%,显著高于BERT的15%...
随机推荐
Which PHP open source works deserve attention
论文笔记: 多标签学习 MSWL
Unity technical manual - color in life cycle coloroverlifetime-- speed color colorbyspeed
ORACLE - 数据查询
New network security competition of the secondary vocational group in 2022
The wisdom of questioning? How to ask questions?
Live800 online customer service system: do business across time and space, starting from each interaction
MySQL queries data by day, week, month, quarter and year
Circuit module analysis exercise 6 (switch)
Meta universe standard forum established
2022 love analysis · panoramic report of it operation and maintenance manufacturers
The Ping class of unity uses
What is 5g? What can 5g do? What will 5g bring in the future?
UE4\UE5 蓝图节点Delay与Retriggerable Delay的使用与区别
ES6 - numerical extension and object extension
Comp2913 database
华为云SRE确定性运维专刊(第一期)
Canoe: the fifth simulation project: simulation + test
最近准备翻译外国优质文章
ES6 learning -- let