Welcome to ROS-WiFi Camera Module repository
4. Image beautification
Open Source CV Image beautification
1、 OpenCV Fix images
1.1、Image restoration is a type of algorithm in computer vision,
Its goal is to fill the area within the image or video. This area is identified using binary masks, and filling is usually done based on the boundary information of the area that needs to be filled. The most common application of image restoration is to restore old scanned photos. It is also used to remove small unwanted objects from images.
1.2、In OpenCV, dst=cv2. inpint (src, inpaintMask, inpaintradius, flags) is provided to achieve image restoration,
Parameter meanings:
src:Source image, which is the image that needs to be repaired
inpaintMask:Binary mask, indicating the pixels to be repaired.
dst:Result image
inpaintRadius:Indicates the radius of repair
flags : Repair algorithm,major have INPAINT_NS (Navier-Stokes based method) or INPAINT_TELEA (Fast marching based method)
The repair based on Navier Stokes should be slower and tend to produce more blurry results than the fast marking method. In practice, we have not found this situation. INPAINT-NS produced better results in our testing, and the speed was slightly higher than INPAINT-TELEA。
1.3、Code and actual effect display
(1)、Firstly, based on the intact image, we will add damage to it, which can be understood as modifying the pixel values of specific parts of it
cd ~/yahboomcar_ws/src/yahboom_esp32ai_car/scripts/opencv/python3 4_1_1.py
xxxxxxxxxximport cv2import numpy as npif __name__ == '__main__': img = cv2.imread('yahboom.jpg') for i in range(50,100): img[i,50] = (0,0,0) img[i,50+1] = (0,0,0) img[i,50-1] = (0,0,0) for i in range(100,150): img[150,i] = (0,0,0) img[150,i+1] = (0,0,0) img[150-1,i] = (0,0,0) cv2.imwrite("damaged.jpg",img) dam_img = cv2.imread('damaged.jpg') while True : cv2.imshow("dam_img",dam_img) action = cv2.waitKey(10) & 0xFF if action == ord('q') or action == 113: break img.release() cv2.destroyAllWindows()After running, an image will be generated, which is considered as a damaged image of the original image

(2)、To fix the photo you just created, first read it, then create a mask, and finally use a function to fix it