Вот один из способов достижения тех же результатов в Python / OpenCV.
- Считывание ввода
- Обрезка нужной области для затемнения
- Создание того же размер черного изображения
- Смешайте два изображения (обрезка 75% и черный 25%)
- Нарисуйте текст на смешанном изображении
- Скопируйте текстовое изображение обратно в то же место в вход
- Сохранить результаты
Вход:
![enter image description here](https://i.stack.imgur.com/jOagn.jpg)
import cv2
import numpy as np
# load image
img = cv2.imread("chimichanga.jpg")
# define undercolor region in the input image
x,y,w,h = 66,688,998,382
# define text coordinates in the input image
xx,yy = 250,800
# compute text coordinates in undercolor region
xu = xx - x
yu = yy - y
# crop undercolor region of input
sub = img[y:y+h, x:x+w]
# create black image same size
black = np.zeros_like(sub)
# blend the two
blend = cv2.addWeighted(sub, 0.75, black, 0.25, 0)
# draw text on blended image
text = cv2.putText(blend, "CHIMICHANGA", (xu,yu), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,255,255), cv2.LINE_8, bottomLeftOrigin=False )
# copy text filled region onto input
result = img.copy()
result[y:y+h, x:x+w] = text
# write result to disk
cv2.imwrite("chimichanga_result.jpg", result)
# display results
cv2.imshow("BLEND", blend)
cv2.imshow("TEXT", text)
cv2.imshow("RESULT", result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Результат:
![enter image description here](https://i.stack.imgur.com/Hv4t2.jpg)