OpenCV-Python의 간단한 숫자 인식 OCR
소개
이 글은 OpenCV-Python을 사용하여 기본적인 숫자 인식 OCR(광학 문자 인식) 시스템을 구현합니다. 두 가지 인기 있는 기계 학습 알고리즘인 KNearest와 SVM을 살펴보겠습니다.
질문 1: Letter_recognition.data 파일
Letter_recognition.data는 OpenCV-Python에 포함된 데이터 세트입니다. 샘플. 여기에는 각 문자에 대한 16개의 기능 값과 함께 손으로 쓴 문자 모음이 포함되어 있습니다. 이 파일은 다양한 문자 인식 작업을 위한 훈련 데이터로 사용됩니다.
자신만의 Letter_recognition.data 구축:
다음 단계에 따라 자신만의 letter_recognition.data 파일을 생성할 수 있습니다. :
- 각 문자가 10x10 픽셀 이미지로 표시되는 문자 데이터세트를 준비합니다.
- 각 이미지에서 픽셀 값을 추출하여 100개 값의 특징 벡터를 형성합니다.
- 각 문자에 레이블(0-25, A-Z에 해당)을 수동으로 할당합니다.
- 특징 벡터와 레이블을 텍스트 파일에 저장하고 각 행은
질문 2: KNearest의 results.ravel()
results.ravel( )는 인식된 숫자 배열을 다차원 배열에서 평면 1D 배열로 변환합니다. 이렇게 하면 결과를 더 쉽게 해석하고 표시할 수 있습니다.
질문 3: 간단한 숫자 인식 도구
letter_recognition.data를 사용하여 간단한 숫자 인식 도구를 만들려면 다음을 따르세요. 단계:
데이터 준비:
- 사용자 정의 letter_recognition.data 파일을 로드하거나 OpenCV의 샘플을 사용하세요.
훈련:
- KNearest 또는 SVM 분류기 인스턴스를 생성합니다.
- letter_recognition.data의 샘플과 응답을 사용하여 분류기를 훈련합니다.
테스트:
- 인식할 숫자가 포함된 이미지를 로드합니다.
- 이미지를 전처리하여 개별 숫자를 분리합니다.
- 각 숫자를 변환합니다. 숫자를 특징 벡터(100픽셀 값)로 변환합니다.
- 훈련된 분류기를 사용하여 각 특징 벡터에 가장 가까운 일치 항목을 찾고 해당 숫자를 표시합니다.
예제 코드 :
import numpy as np import cv2 # Load data samples = np.loadtxt('my_letter_recognition.data', np.float32, delimiter=',', converters={ 0 : lambda ch : ord(ch)-ord('A') }) responses = a[:,0] # Create classifier model = cv2.KNearest() model.train(samples, responses) # Load test image test_img = cv2.imread('test_digits.png') # Preprocess image gray = cv2.cvtColor(test_img, cv2.COLOR_BGR2GRAY) thresh = cv2.adaptiveThreshold(gray, 255, 1, 1, 11, 2) # Extract digits contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) digits = [] for cnt in contours: if cv2.contourArea(cnt) > 50: [x, y, w, h] = cv2.boundingRect(cnt) roi = thresh[y:y+h, x:x+w] roismall = cv2.resize(roi, (10, 10)) digits.append(roismall) # Recognize digits results = [] for digit in digits: roismall = roismall.reshape((1, 100)) roismall = np.float32(roismall) _, results, _, _ = model.find_nearest(roismall, k=1) results = results.ravel() results = [chr(int(res) + ord('A')) for res in results] # Display results output = cv2.cvtColor(test_img, cv2.COLOR_BGR2RGB) for (digit, (x, y, w, h)) in zip(results, contours): cv2.rectangle(output, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.putText(output, str(digit), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) cv2.imshow('Output', output) cv2.waitKey(0)
이 예제에서는 숫자 인식에 KNearest를 사용하지만 대신 SVM 분류자를 생성하여 이를 SVM으로 대체할 수 있습니다.
위 내용은 KNearest 및 SVM 알고리즘을 사용하여 OpenCV-Python에서 기본 숫자 인식 OCR 시스템을 어떻게 구현할 수 있습니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음