使用EAST文本检测器和openCV

时间:2018-12-03 14:04:14

标签: python-3.x opencv3.0 python-tesseract

我正在尝试使用这些图像click here to see my image1中的EAST文本检测器在文本周围创建边框 image2 但是问题是我无法在EAST文本检测器内旋转图像,而没有East文本检测器则无法成功旋转图像。

以下是一些代码:

    # construct the argument parser and parse the arguments
image = cv2.imread("52.jpg")
#print(img1.shape)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.bitwise_not(gray)

thresh = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)[-1]

if angle < -45:
    angle = -(90 + angle)
else:
    angle = -angle


# load the input image and grab the image dimensions
orig = image.copy()
(origH, origW) = image.shape[:2]

# set the new width and height and then determine the ratio in change
# for both the width and height
(newW, newH) = (width, height)
rW = origW / float(newW)
rH = origH / float(newH)

# resize the image and grab the new image dimensions
image = cv2.resize(image, (newW, newH))
print(image.shape)

(H, W) = image.shape[:2]

center = (W // 2, H // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(image, M, (W, H),flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)

来源:https://www.pyimagesearch.com/2018/08/20/opencv-text-detection-east-text-detector/

0 个答案:

没有答案