我試圖從Aadhar卡(印度)的影像中提取完整的Aadhar號碼(12位)
。我能夠用二維碼識別地區。為了提取資訊--我一直在尋找能夠讀取和解碼印度Aadhaar卡上安全二維碼的python庫。 這兩個庫對這個用例似乎特別有用:
現在我們創建一個矩形內核和變形接近,將二維碼組合成一個輪廓
我們使用等高線面積、等高線近似值和長寬比找到等高線并過濾QR碼。提取的投資回報率(ROI)。
提取的投資回報率
代碼
import cv2 import numpy as np # Load imgae, grayscale, Gaussian blur, Otsu's threshold[/span]。 image = cv2.imread('1.png') Original = image.copy() gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(grey, (7,7), 0) thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV cv2.THRESH_OTSU) [1] # Morph close] kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5) close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=1) # 使用等高線面積、近似值和長寬比為QR碼尋找等高線和過濾器。 cnts = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if len(cnts) == 2 else cnts[1] for c in cnts: peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.04 * peri, True) x,y,w,h = cv2.boundingRect(approx) area = cv2.contourArea(c) ar = w / float(h) if len(approx) == 4 and area > 1000 and (ar > . 85 and ar < 1.3)。) cv2.rectangle(image, (x, y), (x w, y h), (36,255, 12), 3) ROI = original[y:y h, x:x w] 。 # cv2.imwrite('ROI.png', ROI)。 # 顯示 cv2.imshow('thresh', thresh) cv2.imshow('close', close) cv2.imshow('image', image) cv2.imshow('ROI', ROI) # 保存影像。 # cv2.imwrite('thresh.png', thresh)。 # cv2.imwrite('close.png', close) # cv2.imwrite('image.png', image) # cv2.imwrite('ROI.png', ROI) cv2.waitKey()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328634.html標籤:



