【发布时间】:2021-08-02 12:56:16
【问题描述】:
我是图像处理的新手。我从 Kaggle 中找到了以下裁剪技术。有人能解释一下它实际上是如何裁剪图像的吗?
def edge_and_cut(img):
try:
edges = cv2.Canny(img, img_w, img_h)
if(np.count_nonzero(edges)>edges.size/10000):
pts = np.argwhere(edges>0)
y1,x1 = pts.min(axis=0)
y2,x2 = pts.max(axis=0)
new_img = img[y1:y2, x1:x2]
new_img = cv2.resize(new_img,(img_w, img_h))
else:
new_img = cv2.resize(img,(img_w, img_h))
except Exception as e:
print(e)
new_img = cv2.resize(img,(img_w, img_h))
return new_img
def crop_images(Imgs):
CroppedImages = np.ndarray(shape=(len(Imgs), img_w, img_h, 3), dtype=np.int)
ind = 0
for im in Imgs:
x = edge_and_cut(im)
CroppedImages[ind] = x
ind += 1
return CroppedImages
这是输出:
【问题讨论】:
-
请定义“实际如何裁剪图像”是什么意思。代码的哪一部分你不明白?
-
不是代码的任何特定部分,但我对使用精明边缘检测进行裁剪的完整过程有疑问。就像在裁剪之后,识别边界框到底发生了什么?
-
裁剪是这里的最后一步。之后什么都没有发生。
-
对不起,裁剪后没有,我误写了裁剪。我的意思是在找到边缘之后,这些 min 和 max 函数是如何工作的,以及在边缘检测之后如何识别边界框?
-
您可以使用调试器并在运行代码时观察变量。
标签: python opencv machine-learning image-processing computer-vision