假设我有下面的图像,其中有一个被删除的区域,现在我想知道这个区域的边框像素,我如何在Python中实现它? The image with one area being erased
最佳答案
Emm,我就直接把代码放下来,不运行,你稍后可以自己尝试一下。
import numpy as np
import cv2 as cv
im = cv.imread('you_input_image.jpg')
imgray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
# assume the while area 255.255.255 are what you put manually and you want it removed.
ret, thresh = cv.threshold(imgray, 254, 255, 0)
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
# There might be multiple are with 255. then you need to find the index of the largest contour
areas = [cv2.contourArea(c) for c in contours]
max_index = np.argmax(areas)
cnt=contours[max_index]
print cnt
# cnt contains all the point in this largest contour
关于python - 如何获取图像中的边框像素或删除区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64724189/