Detect sign

Detecting text in computer vision involves identifying and extracting text information from images or video frames. This task is crucial for optical character recognition (OCR), document analysis, augmented reality, and more.

Description

For this example, the text of the following signs will be extracted and printed in the CMD:

For this purpose, each pixel is analysed comparing the differences between frames and coloring it depending on the direction and speed of this change.

Requirements

(libraries to install):

pip install numpy
pip install cv2
pip install pytesseract

Execution

Inside the folder in the CMD, you can execute the program by writing:

python 06_detect_sign.py

Executing this command loads and shows the previous image. A gaussian filter is applied and then the image is converted to the HSV colorscale. As there are two signs with different colors that contain text, we define two colors ranges: one for the yellow sign and another for the blue one. The color mask applies depending on the sign we want to detect. Then, the biggest contour filtered is detected, extracting the ROI related to the sign filter. A median filter is also applied to the ‘drive safely’ sign, in order for the text to be extracted. These cropped signs are then shown and saved:

After this, press ‘q’ in the images and the text will be detected from these ROIs using Pytesseract. The text written in the CMD should be: ROAD WORK AHEAD and DRIVE SAFELY.

Detecting the area to extract text and cropping it afterwards is a key step in the success of this application. If the cropping is not done correctly or we apply this same method to the complete image, the program cannot recognise the text.

Download

To receive the “Detect sign” code, please fill out the form below.

Upon submission, we’ll promptly send you the ZIP file containing the code you requested. Please ensure you’ve checked your spam folder if you don’t receive our email shortly after submitting your request.