[英]How to affect a certain region's brightness by a certain scalar in opencv with python?
这是在 Python/OpenCV 中执行此操作的一种方法。
裁剪区域。 增加它的亮度。 然后将修改后的区域放回图像中。
输入:
import cv2
import numpy as np
# load image
img = cv2.imread('orange_flower.jpg')
# specify region
x,y,w,h = 480,183,163,115
# crop region
crop = img[y:y+h, x:x+w]
# increase brightness of crop
gain = 1.5
crop = (gain * crop.astype(np.float64)).clip(0,255).astype(np.uint8)
# put crop back into input
result = img.copy()
result[y:y+h, x:x+w] = crop
# save output
cv2.imwrite('orange_flower_result.jpg', result)
# Display various images to see the steps
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()
结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.