Python CV2 Ersetzen Sie die Farbe durch WeißPython

Python-Programme
Anonymous
 Python CV2 Ersetzen Sie die Farbe durch Weiß

Post by Anonymous »

Ich versuche, den türkisfarbenen Teil (Wörter) aus dem Bild mit weißem Hintergrund zu ersetzen, um eine klare Quelle für Tesseract-Ocr zu haben. Und danke, dass Sie sich untersucht haben. < /p>

Code: Select all

import cv2
import numpy as np

# Read image
image = cv2.imread('pic1.png')

# Show Image
cv2.imshow('Pic1', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Create white image
whtimg = np.zeros([image.shape[0],image.shape[1],image.shape[2]],dtype=np.uint8)
whtimg.fill(255)

# Convert to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
whtimg = cv2.cvtColor(whtimg, cv2.COLOR_BGR2HSV)

# Color Range - turquoise (color pick HSV: 165/77/87)
lower_color = np.array([int(165/360*255-100), int(77/100*255*0.1), int(87/100*255-10)])
upper_color = np.array([int(165/360*255+100), int(77/100*255*3.0) , int(87/100*255+10)])

# Create mask to only select white
mask1 = cv2.inRange(hsv, lower_color, upper_color)
# mask1 = 255 - mask1 # invert mask

# Show Mask
cv2.imshow('Mask', mask1)
cv2.waitKey(0)
cv2.destroyAllWindows()

# replace with white
res = cv2.bitwise_or(hsv,whtimg,mask=mask1) # or bitwise_and, bitwise_xor

# Convert to BGR
res = cv2.cvtColor(res, cv2.COLOR_HSV2BGR)

# Show Result
cv2.imshow('Result', res)
cv2.waitKey(0)
cv2.destroyAllWindows()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post