hurmcuuxqeu47e6u
2 questions
0 answers
Avatar
0
hurmcuuxqeu47e6u Beginner
Trích xuất dữ liệu trên CCCD không gắn chip
Hiện tại mình đang làm về trích xuất dữ liệu trên căn cước công dân , trong hướng dẫn <a href="https://viblo.asia/p/trich-xuat-thong-tin-tu-chung-minh-thu-bJzKmaRwK9N?fbclid=IwAR3TJrh43NOvV4_70rEnOaUch3W8aRGIKEx9MNqSSFcbnSylCxPbiiSQ1dU#_21-detect-4-goc-chung-minh-thu-2 " target="_blank">https://viblo.asia/p/trich-xuat-thong-tin-tu-chung-minh-thu-bJzKmaRwK9N?fbclid=IwAR3TJrh43NOvV4_70rEnOaUch3W8aRGIKEx9MNqSSFcbnSylCxPbiiSQ1dU#_21-detect-4-goc-chung-minh-thu-2 </a> , có hướng dẫn Detect 4 góc căn cước, mình chưa hiểu về đoạn " sử dụng mô hình của bản thân ,với mô hình detect đã được cung cấn sẵn bởi Tensorflow API" nhờ bạn hướng dẫn giúp ạ. Dưới đây là code import trực tiếp thừ file mình chụp <p> import cv2 </p> <p> import pytesseract </p> <p> def extract_id_card_info(image_path): </p> <p> image = cv2.imread(image_path) </p> <p> gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) </p> <h1>Vùng chứa Số CCCD</h1> number_roi = image[210:270, 500:960]<p> number_text = extract_text_from_image(number_roi) </p> <p> print("Số CCCD:", number_text) </p> <h1>Vùng chứa tên</h1> name_roi = image[290:350, 520:1000]<p> name_text = extract_text_from_image(name_roi) </p> <p> print("Tên:", name_text) </p> <h1>Vùng chứa ngày sinh</h1> birthdate_roi = image[350:430, 665:900]<p> birthdate_text = extract_text_from_image(birthdate_roi) </p> <p> print("Ngày sinh:", birthdate_text) </p> <h1>Vùng chứa giới tính</h1> gender_roi = image[435:480, 490:660]<p> gender_text = extract_text_from_image(gender_roi) </p> <p> print("Giới tính:", gender_text) </p> <h1>Vùng chứa quốc tịch</h1> nationality_roi = image[435:480, 790:1000]<p> nationality_text = extract_text_from_image(nationality_roi) </p> <p> print("Quốc tịch:", nationality_text) </p> <h1>Vùng chứa quê quán</h1> hometown_roi = image[490:545, 520:1200]hometown_text = extract_text_from_image(hometown_roi)<p> print("Quê quán:", hometown_text) </p> <h1>Vùng chứa nơi cư trú</h1> address_roi = image[575:635, 565:1200]<p> address_text = extract_text_from_image(address_roi) </p> <p> print("Nơi cư trú:", address_text) </p> <h1>Vùng chứa ngày hết hạn</h1> expiration_date_roi = image[655:705, 220:410]<p> expiration_date_text = extract_text_from_image(expiration_date_roi) </p> <p> print("Ngày hết hạn:", expiration_date_text) </p> <p> def extract_text_from_image(image): </p> <p> gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) </p> <p> text = pytesseract.image_to_string(gray, lang='vie+eng') </p> <p> return text </p> <p> image_path = r"C:UsersadminDesktopcccm1.jpg" </p> <p> extract_id_card_info(image_path) </p>
Answer
Avatar
0
hurmcuuxqeu47e6u Beginner
Đọc mã QR trên CCCD
import cv2 <p> import numpy as np </p> <p> from pyzbar.pyzbar import decode </p> <p> import tkinter.messagebox as msgbox </p> <p> import tkinter as tk </p> <p> cap = cv2.VideoCapture(0) </p> <p> root = tk.Tk() </p> <p> root.title("QR_CODE") </p> <p> decoded_label_widget = tk.Label(root, text="") </p> <p> decoded_label_widget.grid(row=0, column=0) </p> <p> decoded_entry_widget = tk.Entry(root, state="readonly", font=("Arial", 12), width=60, highlightthickness=0, bd=0) </p> <p> decoded_entry_widget.grid(row=0, column=1, pady=10) </p> <p> flag_camera = True </p> <p> def toggle_display(): </p> <p> global flag_camera </p> <p> flag_camera = not flag_camera </p> <p> toggle_button = tk.Button(root, text="Bật-Tắt-Cam", command=toggle_display) </p> <p> toggle_button.grid(row=0, column=2, padx=10) </p> <p> def copy_all(): </p> <p> root.clipboard_clear() </p> <p> root.clipboard_append(decoded_entry_widget.get()) </p> <p> copy_button = tk.Button(root, text="Sao Chép", command=copy_all) </p> <p> copy_button.grid(row=0, column=3, padx=10) </p> <p> if not cap.isOpened(): </p> <p> msgbox.showwarning("Cảnh báo", "Không thể mở camera. Vui lòng kiểm tra lại!") </p> <p> flag_camera = False </p> <p> while True: </p> <p> if flag_camera: </p> <p> _, frame = cap.read() </p> <p> frame = cv2.resize(frame, None, fx=1.3, fy=1.3, interpolation=cv2.INTER_LINEAR) </p> <p> frame = cv2.convertScaleAbs(frame, alpha=3, beta=20) </p> <p> decodedObjects = decode(frame) </p> <p> decoded_data = [obj.data.decode("utf-8") for obj in decodedObjects] </p> <p> for obj in decodedObjects: </p> <p> x, y, w, h = obj.rect.left, obj.rect.top, obj.rect.width, obj.rect.height </p> <p> cx, cy = x + w/2, y + h/2 </p> <p> cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) </p> <p> cv2.line(frame, (int(cx), y), (int(cx), y + h), (0, 255, 0), 2) </p> <p> cv2.line(frame, (x, int(cy)), (x + w, int(cy)), (0, 255, 0), 2) </p> <p> if len(decoded_data) > 0: </p> <p> decoded_text = "n".join(decoded_data) </p> <p> decoded_entry_widget.delete(0, tk.END) </p> <p> decoded_entry_widget.insert(tk.END, decoded_text) </p> <p> decoded_entry_widget.configure(state="normal") </p> <p> decoded_label_widget.configure(text="") </p> <p> else: </p> <p> decoded_label_widget.configure(text="") </p> <p> cv2.imshow("QR Code Scanner", frame) </p> <p> if cv2.waitKey(1) & 0xFF == ord('q'): </p> <p> break </p> <p> if cv2.getWindowProperty("QR Code Scanner", cv2.WND_PROP_VISIBLE) &lt; 1: </p> <p> break </p> <p> else: </p> <p> decoded_entry_widget.configure(state="normal") </p> <p> decoded_label_widget.configure(text="") </p> <p> cv2.destroyAllWindows() </p> <p> root.update() </p> <p> root.update() </p> <p> cap.release() </p> <p> cv2.destroyAllWindows() </p> <p> Mình có đoạn code scan mã qr trên CCCD nhưng hiện tại đọc nó rất lâu tầm, mình cũng đã kết nối vơi cam iphone bằng ivcam cũng vậy, Nhờ mọi người xem giúp chỉnh ở đâu ạ </p> <p> Mình cảm ơn </p>
Answer