MVP on OCT and webcam
BIN
frame_1.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
frame_10.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
frame_2.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
frame_3.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
frame_4.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
frame_5.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
frame_6.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
frame_7.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
frame_8.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
frame_9.png
Normal file
After Width: | Height: | Size: 46 KiB |
70
main.py
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import cv2
|
||||||
|
import easyocr
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
# Initialize the EasyOCR reader
|
||||||
|
reader = easyocr.Reader(['en'])
|
||||||
|
|
||||||
|
def preprocess_image(image):
|
||||||
|
# Convert to PIL image for EasyOCR processing
|
||||||
|
return Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
||||||
|
|
||||||
|
def recognize_text(image):
|
||||||
|
processed_image = preprocess_image(image)
|
||||||
|
results = reader.readtext(np.array(processed_image), allowlist='0123456789')
|
||||||
|
# Concatenate all recognized text results
|
||||||
|
recognized_text = ''.join(result[1] for result in results)
|
||||||
|
return recognized_text
|
||||||
|
|
||||||
|
def format_number(text, length=6):
|
||||||
|
# Remove non-numeric characters and pad with zeros if necessary
|
||||||
|
formatted = ''.join(filter(str.isdigit, text))
|
||||||
|
return formatted.zfill(length)[-length:]
|
||||||
|
|
||||||
|
def most_common_number(numbers):
|
||||||
|
# Find the most common number from the list of numbers
|
||||||
|
counter = Counter(numbers)
|
||||||
|
most_common = counter.most_common(1)
|
||||||
|
return most_common[0][0] if most_common else ''
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cap = cv2.VideoCapture(2)
|
||||||
|
|
||||||
|
if not cap.isOpened():
|
||||||
|
print("Error: Could not open webcam.")
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Press 'q' to quit.")
|
||||||
|
frame_count = 0
|
||||||
|
text_history = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
ret, frame = cap.read()
|
||||||
|
if not ret:
|
||||||
|
print("Error: Failed to capture image.")
|
||||||
|
break
|
||||||
|
|
||||||
|
# Recognize text from the current frame
|
||||||
|
recognized_text = recognize_text(frame)
|
||||||
|
formatted_number = format_number(recognized_text)
|
||||||
|
|
||||||
|
# Update the history with the latest recognized number
|
||||||
|
text_history.append(formatted_number)
|
||||||
|
|
||||||
|
# Keep only the last 10 frames
|
||||||
|
if len(text_history) > 20:
|
||||||
|
text_history.pop(0)
|
||||||
|
|
||||||
|
# Determine the most common number from the history
|
||||||
|
most_common = most_common_number(text_history)
|
||||||
|
print(f"Most common number from last 10 frames: {most_common}")
|
||||||
|
|
||||||
|
# if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
|
# break
|
||||||
|
|
||||||
|
cap.release()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
75
requirements.txt
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
absl-py==2.1.0
|
||||||
|
astunparse==1.6.3
|
||||||
|
certifi==2024.7.4
|
||||||
|
charset-normalizer==3.3.2
|
||||||
|
easyocr==1.7.1
|
||||||
|
filelock==3.15.4
|
||||||
|
flatbuffers==24.3.25
|
||||||
|
fsspec==2024.6.1
|
||||||
|
gast==0.6.0
|
||||||
|
google-pasta==0.2.0
|
||||||
|
grpcio==1.65.5
|
||||||
|
h5py==3.11.0
|
||||||
|
idna==3.7
|
||||||
|
imageio==2.35.1
|
||||||
|
Jinja2==3.1.4
|
||||||
|
joblib==1.4.2
|
||||||
|
keras==3.5.0
|
||||||
|
lazy_loader==0.4
|
||||||
|
libclang==18.1.1
|
||||||
|
Markdown==3.7
|
||||||
|
markdown-it-py==3.0.0
|
||||||
|
MarkupSafe==2.1.5
|
||||||
|
mdurl==0.1.2
|
||||||
|
ml-dtypes==0.4.0
|
||||||
|
mpmath==1.3.0
|
||||||
|
namex==0.0.8
|
||||||
|
networkx==3.3
|
||||||
|
ninja==1.11.1.1
|
||||||
|
numpy==1.26.4
|
||||||
|
nvidia-cublas-cu12==12.1.3.1
|
||||||
|
nvidia-cuda-cupti-cu12==12.1.105
|
||||||
|
nvidia-cuda-nvrtc-cu12==12.1.105
|
||||||
|
nvidia-cuda-runtime-cu12==12.1.105
|
||||||
|
nvidia-cudnn-cu12==9.1.0.70
|
||||||
|
nvidia-cufft-cu12==11.0.2.54
|
||||||
|
nvidia-curand-cu12==10.3.2.106
|
||||||
|
nvidia-cusolver-cu12==11.4.5.107
|
||||||
|
nvidia-cusparse-cu12==12.1.0.106
|
||||||
|
nvidia-nccl-cu12==2.20.5
|
||||||
|
nvidia-nvjitlink-cu12==12.6.20
|
||||||
|
nvidia-nvtx-cu12==12.1.105
|
||||||
|
opencv-python==4.10.0.84
|
||||||
|
opencv-python-headless==4.10.0.84
|
||||||
|
opt-einsum==3.3.0
|
||||||
|
optree==0.12.1
|
||||||
|
packaging==24.1
|
||||||
|
pillow==10.4.0
|
||||||
|
protobuf==4.25.4
|
||||||
|
pyclipper==1.3.0.post5
|
||||||
|
Pygments==2.18.0
|
||||||
|
pytesseract==0.3.13
|
||||||
|
python-bidi==0.6.0
|
||||||
|
PyYAML==6.0.2
|
||||||
|
requests==2.32.3
|
||||||
|
rich==13.7.1
|
||||||
|
scikit-image==0.24.0
|
||||||
|
scikit-learn==1.5.1
|
||||||
|
scipy==1.14.1
|
||||||
|
shapely==2.0.6
|
||||||
|
six==1.16.0
|
||||||
|
sympy==1.13.2
|
||||||
|
tensorboard==2.17.1
|
||||||
|
tensorboard-data-server==0.7.2
|
||||||
|
tensorflow==2.17.0
|
||||||
|
tensorflow-io-gcs-filesystem==0.37.1
|
||||||
|
termcolor==2.4.0
|
||||||
|
threadpoolctl==3.5.0
|
||||||
|
tifffile==2024.8.10
|
||||||
|
torch==2.4.0
|
||||||
|
torchvision==0.19.0
|
||||||
|
triton==3.0.0
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
urllib3==2.2.2
|
||||||
|
Werkzeug==3.0.4
|
||||||
|
wrapt==1.16.0
|