How to convert image to text using python
HTML-код
- Опубликовано: 29 июн 2024
- In this tutorial you will learn how to convert / turn images into text by using python and the pytesseract ocr module. You will also learn how to automate keyboard functions and drag the mouse so that you can “do something” based on the text you detect.
Pytesseract ocr is a python library that helps with optical character recognition, or “ ocr “ in short. If you are having issues with the ocr library, please try to use python 3.7 64 bit. If you are getting inaccurate results, try to make the image size larger as ocr gets better the larger the image is (don’t overdo it of course)
As usual, the full finished code can be found on the project’s github page:
github.com/KianBrose/Python-b...
Convert image to text: 0:25
Keyboard automation: 4:14
Mouse drag: 6:15
Code and links used in video (in order):
Image to text:
github.com/UB-Mannheim/tesser...
pip install pytesseract
pip install pillow
import pyautogui
from PIL import Image
from pytesseract import *
pytesseract.tesseract_cmd = r'C:\Users\Antec\AppData\Local\Tesseract-OCR\tesseract.exe'
Keyboard automation:
pip install pywin32
pip install pyautogui
pip install keyboard
import time
import pyautogui
import keyboard
import win32api, win32con
Mouse drag:
import time
import win32api, win32con
time.sleep(2)
win32api.SetCursorPos((500,500))
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.1)
win32api.SetCursorPos((500,300))
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
Hope you enjoyed the video, if it helped please consider subscribing :)
If you have any bugs / errors feel free to join the discord server where you can get near instant help: / discord
I will also run polls on the server for future videos, so check it out if you’re interested in staying.
This video is part of a series of botting tutorials where you can learn how to bot / automate daily tasks. The first video can be found here: • How to make advanced i...
Thanks for watching!
#botting #python #automation - Хобби
Tried editing this one as best as I could... Hopefully it doesn't disappoint ^-^
this video is very beginner friendly
good job
#loved it
@@dasosa1973 thanks!
Your simplistic editing style is honestly something I love, its quick, easy to follow, and doesn't stray away from the main point, its perfect!
@@lil_zcrazyg1917 thanks!
@@KianBrose perfect
this channel is gold.
Thank you!
@@KianBrose Keep the good work man, you deserve a lot!
@@ghassane2016 Thanks!
Thank you for taking the time to make these type of videos! I never done any coding or programming. These videos you make are very educational. I learned a lot more than I expected!
The pace was a bit fast, but youtube allows us to pause and watch at slower speed so this is fine. I hope to see more of your videos!
Glad you like them!
Disappoint in terms of quality? Absolutely not! I've been looking for a well made educational video on this for a while now. Easy to understand and follow. Thank you!
Glad you liked it ^_^
Amazing!! and the best part is he explains other possibilities and options as integer and all . Keeping it fast and simple is better to understand and you don’t get bored .
Keep up the good work !!
Thank you ^^
Dude, sincerly do not stop making videos!
Can't stop me nooooow
Super clean editing as usual ! great work
Ty!
these tutorials are legendary, they help so much
Thanks! Glad they helped
I thought you had at least 4M subs and then I saw u don't, that's sad man :( You deserve more
Maybe someday I get 100k xD
You have a gift as a teacher. This is soo acurate and easy to understand. THX!
Thanks! Glad you enjoyed it
Bro the way to explain stuff is just amazing.
Thanks! Glad you like it ^^
Finally a channel which explains what you really need... i have subscribed bro... and thanks for such amazing videos... 👌🏻👌🏻👌🏻
Np, ty for the sub!
You are amazing, keep going! We need more content!
Working on it!
Hey! Please, upload more videos! No matter the content, I'll watch haha. The way you explain is amazing!
Will do! I'm working on the script for the next one at the moment, will be a web server hosting tutorial
this channel will blow up im telling you...
Already is xd
@@KianBrose you had 2.55 subs 9 hours ago and its 2.8 rn gl about yt
@@KianBrose oh no. There's gonna be more. :)
6k already xD glad this is happening
just as I search how to do it. keep it up dude
Hey Kian thanks for your uploads, you don't have many videos but your content is really good. I'm learning alot of you, the way you teach python is really good. keep making videos you will be a big youtuber in 2 years if you keep making these hq video's
Thanks!
You're amazing at explaining topics
Glad you like them!
Whaaat :o
Your videos are really perfect! Easy, fast and useful. Please, continue! Thank you
I can't belive i found this chanel, it's amazing how you explaining topics
Thanks
I really love your style, keep it up
Will do, thanks!
I very much wish this video was around when I was trying to do this myself. Would have saved hours and hours of my life
Well now it's here
Love this channel!
Thank you!
Damn, you're cool! Keep at it, I love your videos.
Thank you! Will do
great stuff!!! please keep it up!
Thanks, will do!
Hey Kian this was just the channel I was looking for! I'm a machine learning enthusiast and I've always wanted to create a machine learning model to beat some online games. I saw your video about piano tiles, but I was thinking we could try out some more complicated games. I'll message you discord about the idea, I would love to work with you!
Wow this is so good. I will definitely try 😁. Good work teaching.
Thanks ^^
I just love you're channel
Ty!
i searched for copper and i found diamonds
Oo Creative comment i like it
I started watching you when I saw ur bot tutorial.
Please upload more.
Yeah, sorry for my inactivity, just have tons of things to do lately, I’ll start uploading more soon
@@KianBrose Its ok, can u give me project ideas please. Please give me specific game bots and stuff. I think I can make a lot of bots just need ideas.
Yguy hmm for practice try to make a bot that wins typewriter games
@@KianBrose Okay!
i love this, i am using this for my project!
Glad it was useful!
dude, need more videos, this epic
Ty
Great video 👌👍
Thank you 👍
Awesome videos!!
Thanks! ^-^
New pvp looks nice!
ty
Very nice video. I love the editing
Ty!
a lot of useful tips, you're so awesome
No u
@@KianBrose please keep it going forever xD
@@krissloo143 Perhaps I can turn it into a carreer xD
@@KianBrose why not :) ur so good at what ur doing
super good channel you have a new subscriber
Thank you!
Ik a lot of people say this but I seriously thought you had at least like 500k subs. You are extremely underrated 😳
Also discord link expired
The new link is in the about page
Someday maybe ^^
This was a great video :))
Thanks!
Finally found a channel which explains in a simplistic way....I subscribed too....thank you for amazing videos
Thanks! Yeah things should be simple and concise
getting the integers, this comes handy.
x,y = [int(n) for n in '12,34'.split(',')]
yep
Awesome videos thank you.
Glad you like them!
Thank you!
so perfect , make more these , like with selenium or tkinter
A web scraper tutorial, why not
you are so good mate.
Ty
i gotta sponge up all your videos
Hey, keep up the good content. Are you going to do more bot videos?
Yes of course, this is just the one I came up with since the last one
your 2 tutorials where helpful i tried making a Typeracer bot with image to text and i had some issues when testing. it didn't like the font on the text but i could just change that with a add-on.
and line breaks where annoying but pretty simple to work around.
Making the images larger also sometimes helps with the detection
@@KianBrose it's pretty good when I change the font. cdn.discordapp.com/attachments/224273954272051210/762446370061287485/unknown.png
Hey there, mate! I'm starting in the coding area and your videos are helping me a lot! Do you know what tools should I use to build a software that recognizes specific text on a screen and returns its location?
Hm location not really unfortunately, you could try your luck with opencv
Thats a very basic demonstration of tesseract but this is gold for beginners
Yeah, I intend most content to be incredibly beginner friendly and less for advanced uses
YOU ARE AMAZING
Thanks u2
@@KianBrose you seriously have to do more of these! You are great at explaining and the videos are at the perfect place, so they can fit lots of information!
Your videos on these topics are the best I have seen! Great job!
Edit: pace not place
@@squeakycamp207 thanks! I'll get to uploading again once I'm done with some things
Very very very good.
Ty ty ty very much
Bro you need more subscribers. Your videos are so fucking good!
Thanks! Hopefully someday xD
Thank you so much for these videos they help sooo much. Under curiosity how would I be able to detect objects on a 3D game?
Uèeeeeeeeh character recognition sucks if theres weird backgrounds involved, if the colors of the text are "different" enough you can try to filter them out with opencv to get rid of the background and then try to detect text there
You are the fucking best brother(this is coming from an indian), I have tried many other such videos and yours always work. And you also explain most of the things.
Thanks! Glad you like it
Can we have more videos ? You can explain really well
Working on it
MOUSE DRAG 6:16
Good stuff thanks
np
i was here before 1M sub :D
I like how he has 2016 humour.
Ah you noticed haha
Awesome.
Can you do a video tutorial where you go into converting images of numbers into manipulable integers in more detail?
That's what this video was supposed to cover although in a basic way, i unfortunately don't know of any other methods
@@KianBrose OK, thank you!
thanks! Make more!
Yes, working on it
Thanks
No problem
Maaaan, the content is incredible
But what is that speed?!
Its fast no BS content xd
Tror du att du skulle kunna göra en video om image rekognition från kamera feed/video feed mer än via open cv(vilket i o för sig också varit awesome)
Ska försöka göra en video om AI/ML där jag använder en kamera som input
will be great if you can create playlist and keep this and previous video. name like Automation with python
Yeah the next vid will be about botting a color memory game
I really enjoy the video but I prefere the other video code editor, i don’t like the blue interface instead of a code editor ;) It’s only personal, keep safe dude
Yeah multiple people have said this, I won't do it again xD
I watched once of your video yersteday, I’m inlove w/ this channel. Thanks you for have a look on our comments, all my support is yours
I want to use the py file to read any image from the user rather than specifying that image, and then convert it to text, what changes should be made in the program?
You can use openCV to open images in a directory
Please upload new videos bro, your videos give me a lot of inspirations!
Working on it!
i love you
No u
This worked for me, however I am currently analyzing thousands of images and it is very slow, reading about 1 image per 5 seconds or so. Is there any way to make my script use more of my CPU to run faster, as it is using almost nothing?
You could try your luck with multithreading, but that usually won't work really well
1 image per 5 Seconds sounds a bit excessive, how big is the image?
my code runs in vscode and IDLE but when i directly click the py file nothing happens and it closes immediately, i tried to keep the window open after the execution by adding a=input("press enter to exit") but still no use
probably due to multiple python versions being installed
I loved this video and channel too, I am seeking for some help related to this video, I want an automated code, such that there is a picture with some numbers, and I want bot to click a specific number in that picture, and that number is stored as a variable 'total'.
or tell me how to convert that 'total' variable to an image, such that I will store it as 'pic' variable, then I will use that image match function as you used it in previous video (stickman), please help me.
what you need there is ai, a simple bot solution won't be enough
I tried your resizing in order to improve OCR but it isn't working better ( maybe even less) do you have any other tricks pls ? I looked on overstack but it uses CV . Is CV better than tesseract?
Yes, you can actually apply a bunch of filters to improve the accuracy, for example: make it black and white , sharpen the corners , smooth out the sharpened corners
Sounds alien to me
damit, i tried explaining it easily
Do you have a video/code that takes an image of a text, converts to text and translate it (Spanish, etc) ?
I mean that's what this video is for... and the language doesn't really "matter" as optical character recognition just looks at characters and not words
This doesn’t work if there are indentations in the line like when u start a new paragraph, how would we get that to work, thanks!
Im not really sure what to do in that situation, sorry
Is that game Iruna Online at 2:42? :o
..yes
You now have infinity more respect from me and a sub (jk you already won me over with your first video)! Love these fast tutorials, really looking forward to more! ^^
I use a friend as a clipboard too xD
xD That's how they know you consider them valuable
Teach us about selenium automation please
Ah yes web crawlers, I do have a video about that planned in the future
@@KianBrose im really" inspired by your videoo. Maybe you can make something about selenium web scrape, or auto join zoom class 😁👍👍
when I run the code this is the error.
PermissionError: [WinError 5] Access is denied
any help?
run it as administrator
I fixed this error
@@KianBrose It doesn't show "the run it as administrator" button. What should I do?
You know that someone is an anime fan when they type g in their browser search bar and the first thing that pops up is gogoanime :thumbsup:
proceeds to type the letter *h*
I used this on text that is white, instead of black. And it didn't detect any of the words, what would you recommend I do?
Hmm you will need to do some image processing with OpenCV
@@KianBrose wait nvm, I just had to make my image size bigger. Great video man
bro...will this work on raspberry pi 3b+, I am having trouble with opencv installation with tesseract for image to text conversion.....please reply......I am a noob to python programing 😅
Ah yeah, you would have to install the linux version of opencv, personally I have never done it so I can't really guide you with that sorry
so im not the only one that uses dyno bot or mee6 to send all my important information like credit cards and highly confidential government secrets. great!
Yep xD
Btw they can store that data soo dont send your passwords
accidentally created skynet.py @4:23 Love it!
yay someone finally noticed!!!
@@KianBrose Make more videos, they are excellent!!
Jeff Hehir I know I know, the stress to make another video is slowly building up and I’m soon going to be ready with everything I currently have to do to be able to get started with the video
I get a error when this line runs: "from pytesseract import *" i did everything like 5 times. nothing just a LOT of errors.
Use Idle
Use python 3.7.0 64 bit
I did everything you did on the video however I am getting a small box at the end of the output when converting a image to text. Any way to fix this
Ah this is probably because it's detecting some weird characters. There is a spaghetti fix to this issue which is removing all non abcd...1234 characters from a string with re:
import re
regex = re.compile('[^a-zA-Z]')
#First parameter is the replacement, second parameter is your input string
regex.sub('', 'ab3d*E')
#Out: 'abdE'
@@KianBrose can i have a way to remove the last character from the output.
@@techknogamer7433 If you simply want the answer:
assuming "st" is a string:
st = st[:-1]
Is there any way to have this script run on auto and convert every new image in the folder to text, and then release the output on a discord channel?
yes
where is the first video said in this video ? link me please
ruclips.net/video/YRAIUA-Oc1Y/видео.html
instructions unclear, accidentally created skynet.py
Ayyy someone noticed!
how do i install the pyautogui on my mac?
terminal -> pip install pyautogui
What do u use to run python
Idle gives less errors than pycharm and vscode
This video was great but a little too fast.
I'd rather make it as fast as possible to avoid having empty useless spaces at all costs
How I can print out an specific text.I mean I can take a screenshot of something like playernames.Then read them out.But how I can do that Python than print that specific text I try to give the Programm?
Edit:I mean that the program press the specific keys on the keyboard for the names I give him.
keyboard.write("something")
@@KianBrose hmm I know that I can make Screenshots with Python and save them with an specific title.Could I import that file and print it out with that command?
@@maumau4369 var = cv2.open("image.png")
@@KianBrose okay I try it when I’m back home 😊
everything is running fine but there is no Output..
Double check the image is being captured correctly by saving it somewhere
Is there a way to automate the screenshotting?
I mean just stick it in a while loop haha
@@KianBrose ohhhh nvm I forgot about the pyautogui screenshot funcion 😅
When to use pytesseract and when to use easyocr any idea?
I dontk now how to answer that actually
@@KianBrose ok thanks if you could make any automation tutorial on Lackey python.
Hmm - Doesnt seem to want to read white text on a blueish background
I recommend you look into opencv to filter out the noise and unwanted colors, maybe making text a tiny bit thicker as well
@@KianBrose I finally got it to work - It was struggling to read the single digits had to ass the config on the end - EG text = pytesseract.image_to_string(img, config='--psm 6') work perfectly now - Thanks for the reply
it doesn't works with small and a little blur images
Yeah the image has to be decently large (you can use libraries like opencv to make them bigger) and perfectly readable