Mat*_*hew 1 python opencv image python-imaging-library
我以这种方式将坐标存储在 x 轴和 y 轴中。
rects= [[715, 49], [716, 49], [711, 50], [712, 50], [713, 50],...]
image= cv2.imread("some_image.jpg")
Run Code Online (Sandbox Code Playgroud)
如何将浅透明的彩色图层添加到存储rects在image类似于下面汽车顶部的蓝色图层的坐标中?
这是在 Python/OpenCV 中执行此操作的一种方法。
输入:
import cv2
import numpy as np
# read image
img = cv2.imread('lena.jpg')
# create cyan image
cyan = np.full_like(img,(255,255,0))
# add cyan to img and save as new image
blend = 0.5
img_cyan = cv2.addWeighted(img, blend, cyan, 1-blend, 0)
# create black image for mask base
mask = np.zeros_like(img)
# define rectangle for region where want image colorized with cyan
x1,y1,x2,y2 = 100,100,200,200
mask = cv2.rectangle(mask, (x1, y1), (x2, y2), (255,255,255), -1)
# combine img and img_cyan using mask
result = np.where(mask==255, img_cyan, img)
cv2.imshow('img', img)
cv2.imshow('cyan', cyan)
cv2.imshow('img_cyan', img_cyan)
cv2.imshow('mask', mask)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
# save results
cv2.imwrite('lena_rect_mask.jpg', mask)
cv2.imwrite('lena_plus_cyan.jpg', result)
Run Code Online (Sandbox Code Playgroud)
面具:
结果:
| 归档时间: |
|
| 查看次数: |
1141 次 |
| 最近记录: |