【问题标题】:Is there any tool to extract all comic strips from comic page?是否有任何工具可以从漫画页面中提取所有漫画?
【发布时间】:2021-02-06 10:28:03
【问题描述】:

我有漫画页面图片,例如 Link to image

我想从中提取所有带边框的漫画作为单独的图像。 我不打算手动进行。我需要一些自动工具。

【问题讨论】:

  • 请标记编程语言。

标签: image-processing crop


【解决方案1】:

我不知道任何工具,但使用这个脚本你应该可以做到:

Extracted image example

import cv2
import numpy as np
import imutils

img = "comic.jpg"
image = cv2.imread(img)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# blur
blurred = cv2.GaussianBlur(gray, (3, 3), 0)

# threshold it
(T, threshInv) = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)

# find contours
cnts, cnts_hierarchy = cv2.findContours(threshInv.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
clone = image.copy()
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)  # order contours by area
for i,c in enumerate(cnts):
    (x, y, w, h) = cv2.boundingRect(c)

    area = cv2.contourArea(c)
    extent = area / float(w * h)
    
    crWidth = w / float(image.shape[1]) # width ratio of contour to image width
    crHeight = h / float(image.shape[0]) # height ratio of contour to image height
    
    # check if it's noise or a comic strip, change if necessary
    if crWidth > 0.15 or crHeight > 0.15 or extent > 0.8:
        # rotated bounding box
        box = cv2.minAreaRect(c)
        box = np.int0(cv2.cv.BoxPoints(box) if imutils.is_cv2() else cv2.boxPoints(box)) # gives us a contour
        
        warped = imutils.perspective.four_point_transform(clone, box.reshape(4, 2))
        cv2.imwrite(f'./image_{i}.png', warped)
    else:
        break

【讨论】:

猜你喜欢
  • 2020-12-25
  • 1970-01-01
  • 2011-12-31
  • 2011-02-12
  • 2015-12-25
  • 2013-05-22
  • 2010-09-28
  • 1970-01-01
  • 2011-02-16
相关资源
最近更新 更多