7/6/2023 0 Comments Opencv text on imagePlay the audio using gTTS () function and pass the parameter as text, language. Store the extracted string in a variable. Open command prompt and type ~pip install gtts.įollow the above steps to convert image to string. To convert image to audio we first need to convert image to text and text to audio. Use imshow () function to display a final image.Īdd an infinite delay using cv2.waitKey( 0). putText() to add labels around the characters. rectangle() function to create boxes around the characters. Initialize four variables for x-coordinate, y- coordinate, width, height.Īssign their respective values from the above created list.Īs the list elements are in the form of string, convert it to integer.) ] Make imaginary text around each character using pytesseract.image _to_boxes( img)Ĭreate a for loop which converts all the coordinates in the form of list for easy access. ~cv2.put Text(‘ image_name’, x_coordinate, y_coordinate, ‘ font_name’, font_size, RGB_value_of_color, thickness_of_text)Ĭreate two variables to store the dimensions of each character using img. ~cv2.rectangle(‘image_name’, x_coordinate, y_coordinate, RGB_value_of_color, thickness_of_box) To add boxes around the text and label we need two function of OpenCV: 1 image_to_boxes (‘ image_name’) and store it in a variable.ĭRAW BOXES AROUND THE DETECTED CHARACTERS AND LABEL THEM Image_to_boxes () function creates imaginary boxes around each text and returns four values for each character, which are as follows: a. PRINTING THE EXACT POSITION OF TEXT/NUMBERS To convert to string use pytesseract.image _to_string(‘ image_name’) and store it in a variable. imshow(‘ window_name’, image_name).Īdd a cv2.waitKey( 0) to display image for infinity. resize() function and pass the required resolution. imread() function and pass the name of the image as parameter. Save the test image in the same directory.Ĭreate a variable to store the image using cv2. Open terminal/ command prompt and type: ~pip install pytesseract ~pip install opencv-python Tesseract, when integrated with powerful libraries like OpenCV, can be used to combine the tasks of localizing text (Text detection) in an image along with understanding what the text is (Text recognition). It is used to detect embedded characters in an image. Otherwise, you could change the elements to actually include the punctuation in them.Tesseract is an optical character recognition tool in Python. If you want to have the brackets and punctuation like you show above, you could possibly print them manually. Here's an example where the words in the list are printed: import cv2 (However, it's best not to use list as a variable because it will replace the built-in function list(). So each line will be lower because you are increasing the y value with the offset*idx.Īs you have it, the second argument str(lbls) will print out the entire array, that should be changed to the variable for the single element, which you have as list. If you want the text more to the right, you increase the x value, and if you want it lower, you increase the y value. The org argument is used to choose the position of the text in the image, and the bottom left corner of the text is put at the point org.
0 Comments
Leave a Reply. |