久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從圖像中刪除邊框,但將文本保留在邊框上(OCR

Remove borders from image but keep text written on borders (preprocessing before OCR)(從圖像中刪除邊框,但將文本保留在邊框上(OCR 之前的預(yù)處理))
本文介紹了從圖像中刪除邊框,但將文本保留在邊框上(OCR 之前的預(yù)處理)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

擁有如上圖所示的圖像,我可以將其裁剪成四個方形框,使用 OpenCV 形態(tài)學(xué)操作(基本膨脹、腐蝕)去除邊框并得到如下結(jié)果:

Having an image such as one above, I am able to crop it into four square boxes, remove the borders using OpenCV morphological operations (basic dilation, erosion) and get a result such as:

這在大多數(shù)情況下效果很好,但如果有人越界寫,這可能會被預(yù)測為 7 而不是 2.

Which works great in most cases, but if someone writes over the line, this may get predicted as 7 instead of 2.

我無法找到一種解決方案,該解決方案可以在刪除邊框的同時恢復(fù)寫在線條上的字符部分.我擁有的圖像已經(jīng)轉(zhuǎn)換為灰度,因此我無法根據(jù)顏色區(qū)分書寫數(shù)字.解決這個問題的最佳方法是什么?

I am having trouble finding a solution that would recover the parts of the character written over the line while removing the borders. Images I have are already converted to grayscale so I can't distinguish written digits based on the color. What would be the best way to approach this problem?

推薦答案

這是一個管道

  • 將圖像轉(zhuǎn)換為灰度
  • Otsu 獲取二值圖像的閾值
  • 去除豎線
  • 去除水平線
  • 構(gòu)建修復(fù)內(nèi)核和修復(fù)鏡像
  • 反轉(zhuǎn)圖像

轉(zhuǎn)為灰度后,我們大津的閾值

After converting to grayscale, we Otsu's threshold

從這里我們刪除垂直線

然后去掉水平線

這給我們留下了字符間隙,為了解決這個問題,我們創(chuàng)建了一個修復(fù)內(nèi)核來擴(kuò)大圖像

This leaves us with a gap in the characters, to fix this, we create a repair kernel to dilate the image

接下來我們使用閾值圖像來保持我們的角色細(xì)節(jié)

Next we bitwise-and with the thresholded image to maintain our character detail

差距仍然存在,但要好一些.我們執(zhí)行 morph close 以縮小差距

The gap is still there but a little better. We perform morph close to close the gap

它現(xiàn)在已經(jīng)關(guān)閉,但我們丟失了角色細(xì)節(jié).我們使用閾值圖像執(zhí)行最終的逐位與運算以恢復(fù)我們的細(xì)節(jié)

It's now closed but we lost character detail. We perform a final bitwise-and with the thresholded image to recover our detail

為了得到想要的結(jié)果,我們反轉(zhuǎn)圖像

To get the desired result, we invert the image

import cv2

image = cv2.imread('1.png')
removed = image.copy()
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Remove vertical lines
vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,40))
remove_vertical = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, vertical_kernel, iterations=2)
cnts = cv2.findContours(remove_vertical, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(removed, [c], -1, (255,255,255), 15)

# Remove horizontal lines
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (40,1))
remove_horizontal = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(remove_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(removed, [c], -1, (255,255,255), 5)

# Repair kernel
repair_kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
removed = 255 - removed
dilate = cv2.dilate(removed, repair_kernel, iterations=5)
dilate = cv2.cvtColor(dilate, cv2.COLOR_BGR2GRAY)
pre_result = cv2.bitwise_and(dilate, thresh)

result = cv2.morphologyEx(pre_result, cv2.MORPH_CLOSE, repair_kernel, iterations=5)
final = cv2.bitwise_and(result, thresh)

invert_final = 255 - final

cv2.imshow('thresh', thresh)
cv2.imshow('removed', removed)
cv2.imshow('dilate', dilate)
cv2.imshow('pre_result', pre_result)
cv2.imshow('result', result)
cv2.imshow('final', final)
cv2.imshow('invert_final', invert_final)
cv2.waitKey()

這篇關(guān)于從圖像中刪除邊框,但將文本保留在邊框上(OCR 之前的預(yù)處理)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美性video 精品亚洲一区二区 | 色视频在线免费观看 | 日韩淫片免费看 | 中文字幕视频三区 | 欧美一区精品 | 日韩欧美亚洲 | 欧美一区二区三区,视频 | 羞羞视频免费观看入口 | 国产激情在线 | 日韩精品一区二区久久 | 97国产精品 | 国产视频二区在线观看 | 自拍视频网站 | 91麻豆产精品久久久久久夏晴子 | 久久精品国产亚洲一区二区三区 | 超碰av免费 | 日韩一区二区三区在线看 | 精品乱子伦一区二区三区 | 狠狠综合久久av一区二区小说 | 亚洲人成人一区二区在线观看 | 日本三级网站在线 | 亚洲喷水 | 日韩成人免费av | 久久久久国产精品一区二区 | 成在线人视频免费视频 | 一区二区av | 欧美三区| 中文字幕亚洲精品 | 天堂中文av | 亚洲视频一区 | 成人免费网视频 | 亚洲国产精品视频一区 | 欧美精品一区二区三区四区 | 欧美日韩精品一区二区三区四区 | 极品销魂美女一区二区 | 九色www| 欧美视频在线看 | 国产亚洲精品成人av久久ww | www.天天操 | 久久国产美女视频 | 丁香久久 |