In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about C++ OpenCV how to achieve image restoration function, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
Preface
Now we will use OpenCV C++ to repair the defective image. OpenCV provides inpaint API for image restoration.
1. OpenCV inpaint
The original picture is shown in the picture. The requirement of this case is to eliminate the red lines on the image. The inpaint API provided by OpenCV can achieve this effect.
Void inpaint (
InputArray src, original drawing
InputArray inpaintMask, binary mask, indicating the pixels to repair
OutputArray dst, target image
Double inpaintRadius, neighborhood painting around pixels. In general, if the area to be repaired is small, using smaller values produces less blur
Int flags INPAINT_NS or INPAINT_TELEA
)
The most important thing to use this API is to generate a binary mask image (the place to be repaired). We can use the mouse to respond to events.
/ draw a mask in inpaintMask using mouse response events to repair if (event = = EVENT_LBUTTONUP | |! (flags & EVENT_FLAG_LBUTTON)) {prevPt = Point (- 1,-1);} else if (event = = EVENT_LBUTTONDOWN) {prevPt = Point (x, y) } else if (event = = EVENT_MOUSEMOVE & & (flags & EVENT_FLAG_LBUTTON)) {prevPt = Point (x, y); / / draw mask image circle (inpaintMask, prevPt, 2, Scalar::all (255),-1); / / imshow ("inpaintMask", inpaintMask) / / Image restoration Mat result; inpaint (src, inpaintMask, result, 1, INPAINT_NS); / / imshow ("image", result);}
As shown in the picture, the mask image can then be repaired using inpaint.
Second, the source code # include#include # includeusing namespace cv;using namespace std;/*void inpaint (InputArray src, original image InputArray inpaintMask, binary mask, indicating the pixel OutputArray dst to be repaired, the target image double inpaintRadius, and the neighborhood painting around the pixel. In general, if the area to be repaired is small, using smaller values results in less blurred int flags INPAINT_NS or INPAINT_TELEA) * / Mat src, inpaintMask;Point prevPt (- 1,-1) Static void onMouse (int event, int x, int y, int flags, void*) {/ / use mouse to respond to events to draw a mask in inpaintMask for image repair if (event = = EVENT_LBUTTONUP | |! (flags & EVENT_FLAG_LBUTTON)) {prevPt = Point (- 1,-1) } else if (event = = EVENT_LBUTTONDOWN) {prevPt = Point (x, y);} else if (event = = EVENT_MOUSEMOVE & & (flags & EVENT_FLAG_LBUTTON)) {prevPt = Point (x, y) / draw mask images circle (inpaintMask, prevPt, 2, Scalar::all,-1); / imshow ("inpaintMask", inpaintMask); / / Image restoration Mat result; inpaint (src, inpaintMask, result, 1, INPAINT_NS); / / imshow ("image", result) }} int main () {src = imread ("girl.jpg"); if (src.empty ()) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.