Nic*_*ais 5 python opencv image image-processing
我想在这张图片中制作一个反向填充的矩形。
我有的代码:
import cv2
lena = cv2.imread('lena.png')
output = lena.copy()
cv2.rectangle(lena, (100, 100), (200, 200), (0, 0, 255), -1)
cv2.addWeighted(lena, 0.5, output, 1 - .5, 0, output)
cv2.imshow('', output)
Run Code Online (Sandbox Code Playgroud)
我想要的是:
这就是我要做的:
# initialize output
output = np.zeros_like(lena, dtype=np.uint8)
output[:,:,-1] = 255
# this is your box top_x
tx,ly,bx,ry = 100,100,200,200
# copy lena to output
output[tx:bx,ly:ry] = lena[tx:bx,ly:ry]
cv2.addWeighted(lena, 0.5, output, 1 - .5, 0, output);
Run Code Online (Sandbox Code Playgroud)
输出:
| 归档时间: |
|
| 查看次数: |
830 次 |
| 最近记录: |