👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I am trying to implement a "Digit Recognition OCR" in OpenCV-Python (cv2). It is just for learning purposes. I would like to learn both KNearest and SVM features in OpenCV.
I have 100 samples (i.e. images) of each digit. I would like to train with them.
There is a sample letter_recog.py
that comes with OpenCV sample. But I still couldn"t figure out on how to use it. I don"t understand what are the samples, responses etc. Also, it loads a txt file at first, which I didn"t understand first.
Later on searching a little bit, I could find a letter_recognition.data in cpp samples. I used it and made a code for cv2.KNearest in the model of letter_recog.py (just for testing):
import numpy as np
import cv2
fn = "letter-recognition.data"
a = np.loadtxt(fn, np.float32, delimiter=",", converters={ 0 : lambda ch : ord(ch)-ord("A") })
samples, responses = a[:,1:], a[:,0]
model = cv2.KNearest()
retval = model.train(samples,responses)
retval, results, neigh_resp, dists = model.find_nearest(samples, k = 10)
print results.ravel()
It gave me an array of size 20000, I don"t understand what it is.
Questions:
1) What is letter_recognition.data file? How to build that file from my own data set?
2) What does results.reval()
denote?
3) How we can write a simple digit recognition tool using letter_recognition.data file (either KNearest or SVM)?
👻 Read also: what is the best laptop for engineering students?
Simple Digit Recognition OCR in OpenCV-Python __del__: Questions
How can I make a time delay in Python?
5 answers
I would like to know how to put a time delay in a Python script.
Answer #1
import time
time.sleep(5) # Delays for 5 seconds. You can also use a float value.
Here is another example where something is run approximately once a minute:
import time
while True:
print("This prints once a minute.")
time.sleep(60) # Delay for 1 minute (60 seconds).
Answer #2
You can use the sleep()
function in the time
module. It can take a float argument for sub-second resolution.
from time import sleep
sleep(0.1) # Time in seconds
Simple Digit Recognition OCR in OpenCV-Python __del__: Questions
How to delete a file or folder in Python?
5 answers
How do I delete a file or folder in Python?
Answer #1
os.remove()
removes a file.os.rmdir()
removes an empty directory.shutil.rmtree()
deletes a directory and all its contents.
Path
objects from the Python 3.4+ pathlib
module also expose these instance methods:
pathlib.Path.unlink()
removes a file or symbolic link.pathlib.Path.rmdir()
removes an empty directory.
We hope this article has helped you to resolve the problem. Apart from Simple Digit Recognition OCR in OpenCV-Python, check other __del__-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Simple Digit Recognition OCR in OpenCV-Python
- Deutsch Simple Digit Recognition OCR in OpenCV-Python
- Français Simple Digit Recognition OCR in OpenCV-Python
- Español Simple Digit Recognition OCR in OpenCV-Python
- Türk Simple Digit Recognition OCR in OpenCV-Python
- Русский Simple Digit Recognition OCR in OpenCV-Python
- Português Simple Digit Recognition OCR in OpenCV-Python
- Polski Simple Digit Recognition OCR in OpenCV-Python
- Nederlandse Simple Digit Recognition OCR in OpenCV-Python
- 中文 Simple Digit Recognition OCR in OpenCV-Python
- 한국어 Simple Digit Recognition OCR in OpenCV-Python
- 日本語 Simple Digit Recognition OCR in OpenCV-Python
- हिन्दी Simple Digit Recognition OCR in OpenCV-Python
Paris | 2023-02-06
I was preparing for my coding interview, thanks for clarifying this - Simple Digit Recognition OCR in OpenCV-Python in Python is not the simplest one. Checked yesterday, it works!
Boston | 2023-02-06
Python functions is always a bit confusing 😭 Simple Digit Recognition OCR in OpenCV-Python is not the only problem I encountered. I just hope that will not emerge anymore
California | 2023-02-06
imp Python module is always a bit confusing 😭 Simple Digit Recognition OCR in OpenCV-Python is not the only problem I encountered. I am just not quite sure it is the best method