小编Luk*_*kas的帖子

Python - 识别文本图像

我编写这段代码的前提是识别图像中的单词.此方法查找链接中显示的一些但不是所有单词.

我的代码是:

def methods_text_recognition_and_delete(self, path_floorplans, f, path_fw):

        image = cv2.imread(path_floorplans +f)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)  # grayscale
        _, thresh = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV)  # threshold
        kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))
        dilated = cv2.dilate(thresh, kernel, iterations = 1)  # dilate
        contours, hierarchy = cv2.findContours(dilated, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)  # get contours

        # for each contour found, draw a rectangle around it on original image
        for contour in contours:
            # get rectangle bounding contour
            [x, y, w, h] = cv2.boundingRect(contour)

            # discard areas …
Run Code Online (Sandbox Code Playgroud)

python opencv image-recognition

6
推荐指数
0
解决办法
1609
查看次数

标签 统计

image-recognition ×1

opencv ×1

python ×1