Remove The Annotation Box From The Picture
** What I want to do is remove the red box in 5000 images. I wrote a piece of python code for one sample image, but I don't know where got something wrong. I can't realize such pu
Solution 1:
I am not certain what the problem is, but would suggest you replace the red box using "inpainting" - see here
That makes your code look like this:
......
# join my masks
mask = mask0+mask1
result = cv2.inpaint(img,mask,3,cv.INPAINT_TELEA)
As you have identified, the red hues wrap around and lie near 180 or 0 and, as a result you are running your range detection twice. One nifty "trick" you can use is to invert the image (by subtracting from 255) before conversion to HSV and then look for cyan colour (i.e. Hue=90 in OpenCV) instead of red. So your code becomes:
# Load imageimg = cv2.imread('box.jpg')
# Invert and convert to HSVimg_hsv=cv2.cvtColor(255-img, cv2.COLOR_BGR2HSV)
# Mask all red pixels (cyan in inverted image)lo = np.uint8([80,30,0])
hi = np.uint8([95,255,255])
mask = cv2.inRange(img_hsv,lo,hi)
# Inpaint red boxresult = cv2.inpaint(img,mask,3,cv.INPAINT_TELEA)
Also, if you have 5,000 images to do, I would suggest you consider multiprocessing - there is an example you could use as a basis here.
Keywords: Image processing, Python, OpenCV, inpainting, cv2:inpaint.
Post a Comment for "Remove The Annotation Box From The Picture"