我有一個這樣的串列
pixels = [[400, 220, 515, 293], [433, 373, 482, 452], [401, 370, 477, 475]]
每個子串列對應于每個裁剪的左上角和右下角
我制作了這段代碼以從整個串列中提取單個作物
x1 = min(map(lambda x: x[0], pixels))
y1 = min(map(lambda x: x[1], pixels))
x2 = max(map(lambda x: x[2], pixels))
y2 = max(map(lambda x: x[3], pixels))
crop = img[y1:y2, x1:x2]
cv2_imshow(crop)
如何從 n 個子串列中制作 n 個作物?
uj5u.com熱心網友回復:
希望它會起作用
import cv2
pixels = [[400, 220, 515, 293], [433, 373, 482, 452], [401, 370, 477, 475]]
for i in pixels:
img = cv2.imread(r"img _path")
x1,y1,x2,y2 = i
crop = img[y1:y2, x1:x2]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454667.html
上一篇:使用NumPy生成幾何序列
下一篇:生成復數的Numpy陣列
