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

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

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

問題描述

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

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.

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

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.

是否應該繼續調整參數,還是有更好的方法來找到這些空白的位置?

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

推薦答案

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

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

  • 將圖像轉換為灰度和自適應閾值圖像
  • 構造特殊內核以僅檢測水平線
  • 執行形態轉換
  • 查找輪廓并在圖像上繪制

使用此示例圖片

轉換為灰度和自適應閾值得到二值圖像

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() 創建一個內核,并進行形態變換以隔離水平線

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() 來檢測線條,但是由于我們已經對圖像進行了預處理并隔離了水平線,所以我們可以找到輪廓并繪制結果

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()

這篇關于使用 OpenCV 檢測 .pdf 表單圖像中的水平空白行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩成人av在线 | 草久久| 日韩精品一区二区三区在线观看 | 国产在线一区二 | 免费三级网 | 粉嫩av| 亚洲国产黄 | 国产日韩欧美一区二区在线播放 | 亚洲精品免费在线观看 | 亚洲日韩中文字幕一区 | 亚洲夜射 | 免费在线一区二区 | 91观看| 亚洲精品视频网站在线观看 | 一区久久 | 国产精品久久 | 久久久性| 九九热精品在线 | 国产精品久久久久久52avav | 一区二区中文 | 18gay男同69亚洲网站 | 四虎永久免费地址 | 色www精品视频在线观看 | 97国产一区二区精品久久呦 | 黄色免费网址大全 | www.亚洲精品 | 欧美天堂 | 国产精品精品久久久 | 成人婷婷 | 欧美女优在线观看 | 性高湖久久久久久久久3小时 | 一级看片免费视频囗交动图 | 精品亚洲一区二区三区四区五区 | 狼人伊人影院 | www成年人视频 | av免费入口 | 亚洲国产激情 | 精品国产一区二区三区日日嗨 | 欧美一区二区三区在线观看 | 欧美一区二区三区久久精品 | 欧美电影一区 |