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

使用 OpenCV 檢測 .pdf 表單圖像中的水平空白行

Detect horizontal blank lines in .pdf form image with OpenCV(使用 OpenCV 檢測 .pdf 表單圖像中的水平空白行)
本文介紹了使用 OpenCV 檢測 .pdf 表單圖像中的水平空白行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有 .pdf 文件已轉(zhuǎn)換為該項目的 .jpg 圖像.我的目標(biāo)是識別您通常會在 .pdf 表單中找到的空白(例如 ____________),這些空白指示用戶填寫某種信息的空間.我一直在使用 cv2.Canny()cv2.HoughlinesP() 函數(shù)進(jìn)行邊緣檢測.

I have .pdf files that have been converted to .jpg images for this project. My goal is to identify the blanks (e.g ____________) that you would generally find in a .pdf form that indicate a space for the user to sign of fill out some kind of information. I have been using edge detection with the cv2.Canny() and cv2.HoughlinesP() functions.

這工作得相當(dāng)好,但有不少誤報似乎不知從何而來.當(dāng)我查看邊緣"文件時,它會在其他單詞周圍顯示一堆噪音.我不確定這種噪音是從哪里來的.

This works fairly well, but there are quite a few false positives that come about from seemingly nowhere. When I look at the 'edges' file it shows a bunch of noise around the other words. I'm uncertain where this noise comes from.

是否應(yīng)該繼續(xù)調(diào)整參數(shù),還是有更好的方法來找到這些空白的位置?

Should I continue to tweak the parameters, or is there a better method to find the location of these blanks?

推薦答案

假設(shè)您要在 .pdf 表單上查找水平線,這里有一個簡單的方法:

Assuming that you're trying to find horizontal lines on a .pdf form, here's a simple approach:

  • 將圖像轉(zhuǎn)換為灰度和自適應(yīng)閾值圖像
  • 構(gòu)造特殊內(nèi)核以僅檢測水平線
  • 執(zhí)行形態(tài)轉(zhuǎn)換
  • 查找輪廓并在圖像上繪制

使用此示例圖片

轉(zhuǎn)換為灰度和自適應(yīng)閾值得到二值圖像

Convert to grayscale and adaptive threshold to obtain a binary image

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

然后我們用 cv2.getStructuringElement() 創(chuàng)建一個內(nèi)核,并進(jìn)行形態(tài)變換以隔離水平線

Then we create a kernel with cv2.getStructuringElement() and perform morphological transformations to isolate horizontal lines

horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (15,1))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)

從這里我們可以使用 cv2.HoughLinesP() 來檢測線條,但是由于我們已經(jīng)對圖像進(jìn)行了預(yù)處理并隔離了水平線,所以我們可以找到輪廓并繪制結(jié)果

From here we can use cv2.HoughLinesP() to detect lines but since we have already preprocessed the image and isolated the horizontal lines, we can just find contours and draw the result

cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

for c in cnts:
    cv2.drawContours(image, [c], -1, (36,255,12), 3)

完整代碼

import cv2

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

horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (15,1))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)

cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

for c in cnts:
    cv2.drawContours(image, [c], -1, (36,255,12), 3)

cv2.imshow('thresh', thresh)
cv2.imshow('detected_lines', detected_lines)
cv2.imshow('image', image)
cv2.waitKey()

這篇關(guān)于使用 OpenCV 檢測 .pdf 表單圖像中的水平空白行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产伦精品一区二区三区在线 | 香蕉久久av | 国产av毛片 | 中文字幕一区二区三区在线视频 | 久久精品国产免费一区二区三区 | 久久久久久久一区二区三区 | 久久视频免费观看 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 欧美又大粗又爽又黄大片视频 | 龙珠z国语版在线观看 | 毛片在线免费 | 福利网站导航 | 欧美精品一区二区三区在线 | 亚洲精品一区在线 | 香蕉视频一区二区 | 欧美精品一区二区三区蜜臀 | 7777在线视频免费播放 | 日韩高清电影 | 91精品国产一区二区三区蜜臀 | 亚洲欧美激情视频 | 欧美成人精品二区三区99精品 | 国产在线精品免费 | 天天操操 | 国产中文一区二区三区 | 97免费视频在线观看 | 国产精品久久久久久久久久久久冷 | 91麻豆精品国产91久久久更新资源速度超快 | 久久久久久久久国产 | 国产九九九| 五月婷婷丁香婷婷 | 久久久久国产精品一区二区 | 日韩在线视频观看 | 国产一区二区在线免费观看 | 国产精品久久久久aaaa九色 | www.欧美.com | 久久国产精品免费视频 | 欧美日韩国产高清 | 国产91在线观看 | 亚洲福利在线观看 | 一区二区三区国产好的精 | 少妇av片 |