【问题标题】:Cutting the various pictures in one image将各种图片切割成一张图片
【发布时间】:2022-06-16 19:58:54
【问题描述】:

在白色背景中包含各种图片的图像。 我想从输入图像中裁剪照片。

我试过了

input_img = cv2.imread('test.png')
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
thresh = cv2.threshold(blurred, 230, 255, cv2.THRESH_BINARY_INV)[1]

cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    x, y, w, h = cv2.boundingRect(c)

但是,如果图片之间没有间隙,则无法检测到轮廓。

每张照片都有不同的像素颜色值,所以我尝试按颜色裁剪照片。 通过横线和竖线对比颜色,如果色差较大,则判断照片不同。 找到图片变化时的坐标并剪切

image = cv2.imread('test.png') 
h, w, c = image.shape

for i in range(w):
    img = image[:w, [i]]
    s = np.sum(img)
    sums.append(s)

for j in range(h):
    img = image[[j], :h]
    s = np.sum(img)
    sums.append(str(s))

#OR
diff = [] # sum(abs(diff)) 
for i in range(len(image)-1):
    diff += [abs(image[i][0] - image[i+1][0]), abs(image[i][1] - image[i+1][1]), abs(image[i][2] - image[i+1][2])]

我如何通过比较颜色来发现差异?

这些是几个示例图像。 带有黑色边框的框是图像。
enter image description here

【问题讨论】:

  • 你能分享一些示例图像吗?您也尝试过使用边缘检测吗?

标签: opencv


猜你喜欢
  • 2011-06-20
  • 1970-01-01
  • 2013-02-24
  • 1970-01-01
  • 2012-02-13
  • 2010-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多