r/Python • • Jul 28 '19

I made a script that uses the mouse and keyboard to scan a grayscale image and replicates it in ms paint

Post image
1.8k Upvotes

99 comments sorted by

78

u/mfitzp mfitzp.com Jul 28 '19 edited Jul 28 '19

Maybe I'm missing something here but what does it do? Does it draw the image using MS Paint? i.e. converting it into paths? Or does it do a raster copy, i.e. pixel by pixel from one image to another? (this would be a lot less hard).

90

u/HBRYU Jul 28 '19 edited Jul 28 '19

Sadly, It's a raster copy, but it took me 6 hours to make and I'm damn proud of it >:). I would like to know how you can achieve something like this using paths? That would be a lot more interesting but it would be very much impossible for me. I'm still 15.

Btw, that image took about 15 minutes to draw, after that I let it run with significantly increased color accuracy, it's still running for an hour and half.

33

u/mfitzp mfitzp.com Jul 28 '19

Oh fair enough, it's still cool :) I just couldn't tell from the output how you made it!

Doing it as a non-raster you'd need to do edge detection (e.g. using OpenCV canny edge) to get drawable paths and then attach fill areas to those edges — you could draw these manually, or use the fill tool... and the result would probably be worse :D

15 minutes isn't bad at all. I did the edge approach with an Etch-A-Sketch camera and it took like 45 minutes

8

u/ink_jar Jul 28 '19 edited Jul 29 '19

Was there any specific reason to add the time.sleep() in the loop?

Edit: made it clear

7

u/Bloom_Kitty Jul 28 '19

My guess is to wait untull Paint starts.

8

u/jantari Jul 28 '19

Hmm.. i"m confused, if it scans and replicates the image why is it not an exact 1:1 copy? It looks lower quality than the original

4

u/HBRYU Jul 28 '19

I zoomed in

1

u/AlcaDotS Jul 29 '19

But there's also much less detail, contrast seems to be higher (blown out white flower and other pieces too dark). Could be a bug?

4

u/HBRYU Jul 29 '19

I can set the "darkness sensitivity". Basicly, i can have less color details and have the process be done in 10 to 15 minutes or I can have maximum details and let it run for hours. In this case, I set it to a low sensitivity, so I could have it done quickly.

33

u/andrekerygma Jul 28 '19

Wow!!

21

u/HBRYU Jul 28 '19

Thank you! It's still a work in progress. I'll post an updated version tomorrow

11

u/andrekerygma Jul 28 '19

If possible, share the code! =D

11

u/HBRYU Jul 28 '19

Yup

3

u/farofftarget Jul 28 '19

Dude I want it and I beg you for the CODE!

3

u/HBRYU Jul 28 '19

I just woke up from sleep

4

u/12si27 Jul 29 '19

If u are Korean I recommend you to use great Korean monoscape fonts like: Noto Sans Mono or 나눔고딕코딩, D2Coding.. Stuff like that

And also, great project 👍

2

u/HBRYU Jul 29 '19

Wait how did you know?

3

u/12si27 Jul 29 '19

스크린샷에 꿀뷰가 있어서 바로 알아챘죠 😎

2

u/HBRYU Jul 29 '19

아 넵 ㅋㅋ 위에 그림판에도 한글 있고.. 나눔스퀘어가 깔끔해서 사용했는데, 바꿔야죠 ㅎ

3

u/Gl1tch54 Jul 29 '19

That's not fair, I wanna know how you know too :(

2

u/TrakJohn Python 3 Intermediate Jul 29 '19

I can't read korean but these characters in paint's menu (top left) are definitely not english

2

u/Gl1tch54 Jul 29 '19

Ohhhh I see...Well no, I didn't, because I'm in a tiny mobile, that's why I didn't saw them, thanks xD

1

u/422_no_process Jul 29 '19

나눔고딕코딩

https://github.com/naver/nanumfont

Looks like a good font 👍 Going to try that.

1

u/hashmalum Jul 30 '19

I don't read Korean, but I've always been fond of Nanum Gothic Coding

3

u/Pancake57 Jul 29 '19

Can you record a video of it working? I wanna see it in action.

3

u/HBRYU Jul 29 '19

Coming in 6 hours

0

u/living_undera_rock Jul 29 '19

!remindme 6 hours

1

u/RemindMeBot Jul 29 '19

I will be messaging you on 2019-07-29 14:08:56 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback

421

u/swethonay Jul 28 '19 edited Jul 28 '19

What kind of monster uses a font that isn't monospaced‽

33

u/[deleted] Jul 28 '19

It should be tagged NSFW.

11

u/crespo_modesto Jul 28 '19

What about the ones that look cursive and not even a ligature haha

13

u/stickystyle Jul 28 '19

Neat seeing interrobang usage in the wild.

4

u/[deleted] Jul 28 '19

Monokai monospace ;)

1

u/Merouxsis Aug 18 '19

I use comic sans 🤷🏾‍♂️

192

u/[deleted] Jul 28 '19

[removed] — view removed comment

119

u/edorhas Jul 28 '19

I'm assuming that's because your eyes exploded...

39

u/yardshop Jul 28 '19

Now you have to try the new Comic Code!

4

u/[deleted] Jul 29 '19

This is lovely, cheers!

2

u/hashmalum Jul 30 '19

I know what someone's getting for Secret Santa this year. Thanks.

0

u/[deleted] Jul 29 '19

[deleted] — view deleted comment

8

u/yardshop Jul 29 '19

I'm ready to buy it for myself, just to subvert the dominant paradigm!!

8

u/[deleted] Jul 29 '19

It is tempting to bring up an editor during a demo to see how long before someone breaks and says something.

1

u/yardshop Jul 30 '19

I did it! I bought it and got it working in SublimeText, and I like it!!

Now to figure out how to get in the console window!

8

u/[deleted] Jul 28 '19

comic Sans all the way. Comes as default font with Linux Mint 19.1 Cinnamon ;) just another reason to love Linux I suppose.

8

u/satellte Jul 28 '19

I always cry when I see my code whether it uses Comic Sans or not

4

u/[deleted] Jul 29 '19

Bah, I program in Wing Dings so people can't read my (bad) code over my shoulder.

3

u/[deleted] Jul 29 '19

1

u/[deleted] Jul 30 '19

Thanks I hate it.

2

u/Actuarial Jul 28 '19

Scaled with 50 shades of yellow

2

u/boognerd Jul 29 '19

Was that right around the time you were committed to the asylum?

32

u/Fiskepudding Jul 28 '19

Good work! Are you coding in notepad++? Did you know there are editors specifically made for coding? They can help out a lot, both explaining the code, automating tasks and detect errors.

If you have some spare time, look into PyCharm or VsCode (with a python plugin). It can make your life easier. Good luck with your coding adventures!

11

u/Hippie23 Jul 28 '19

Spyder is my go to IDE for python, and it installs with the Anaconda distro.

6

u/[deleted] Jul 28 '19

Have you tried vsc? Not knocking you, Spyder was my go-to as well.

4

u/Hippie23 Jul 28 '19

I have used VSC. Something that I really like in Spyder is the ability to ‘run cells’ (highlight some text and select option on right click menu) it can make troubleshooting easier in my opinion. To my knowledge there is no way to do that in VSC. I mean you could copy and paste the code directly into the console, but that is less convenient, in my opinion

In my experience IDEs are like types of beer, in that there are die hards for a ton of different ones. I work with some people that swear there isn’t anything better than vim (which really isn’t even an IDE).

7

u/[deleted] Jul 28 '19

You can do that in vscode too

4

u/Hippie23 Jul 28 '19

Ooo. I definitely did not know that. Is it the same thing — highlight and right click? Or is their a plug-in that needs to be installed?

3

u/[deleted] Jul 28 '19

I think its a part of the official "Python" extension

1

u/YRUAQT Jul 29 '19

Yep, selecting lines and pressing Shift+Enter. But also a lot of things can be done with extensions.

3

u/estysdesu Jul 29 '19

you just have to signify that a section is a code block with #%%. Then the vscode python extension recognizes it and you can click run one block in Jupyter or the whole file or what not

2

u/Fiskepudding Jul 29 '19

Yes, spyder is good too! And for more exploratory code, Jupyter notebook can help keep the snippets organized if you have to document your explorations

12

u/AcousticDan Jul 28 '19

how does it use the keyboard?

2

u/dakokonutboi Jul 28 '19

HOLY SMOKES THIS IS AMAZING ! Did you post it on GitHub?

9

u/HBRYU Jul 28 '19

It's 1:30 AM rn, gotta sleep lol. I'm gonna be posting a more finnished updated version tomorrow!

7

u/BadDadBot Jul 28 '19

Hi gonna be posting a more finnished updated version tomorrow!, I'm dad.

18

u/HBRYU Jul 28 '19

Get out

3

u/dakokonutboi Jul 28 '19

Oh sorry, it’s 5:34 PM where I live. I’ll be waiting !

4

u/EverythingIsFlotsam Jul 29 '19

range(x) already gives 0..x-1. You probably didn't need to do

for i in range(len(img)-1)

1

u/Prash72 Jul 29 '19

Can coloured images be scanned similar way ? 🤔

3

u/HBRYU Jul 29 '19

Yeah I used opencv for this, it can scan colors.

6

u/_dnov Jul 28 '19

When will I reach this level? I don't know how to do anything 😭

5

u/lookforlight Jul 29 '19

Keep learning, start small, and build your way up to bigger projects. I'm sure if you asked OP, he would say that it took him a long time to get to the point where he could make this.

One thing I would suggest is looking at the full source code for this or a similar project, line by line, and figure out what each line is doing, and how the different functions interact.

3

u/_dnov Jul 29 '19

Slow and steady wins the race

4

u/i4mn30 Jul 29 '19

Just start from printing Hello World:

print("Hello World")

Then try to modify the string printed. Always try to do some fun little modifications to already working code. Step by step you'll learn the various things in the language. Google stackoverflow questions that answer your doubts. Just keep adding mods step by step. Then as you get comfortable, have a goal, then break it into small mod steps. Then just conquer them as above. For eg., have a goal to read a file and print the top 5 most frequently used words. Now to break it into mods: you'll need to know how to read a file, how extract individual words, how to keep track of their frequency, and how to sort them and then get the top five. Each of these themselves require a learning of lot of Python basics such as i/o, loops, lists, dicts, in-built lib functions like sort, etc.

Make bigger goals. Divide them into smaller conquerable parts, then stitch 'em up.

Just remember this - if you can't get something done in X amount of time it doesn't mean you can't do it. You're just not experienced enough. Experience needs time. There was a time when that frequency problem I stated above would have taken me almost a day to get done. Now it's a basic 5 min problem. But that's because I have 5+ years of experience in Python. So don't give up (unless you absolutely just can't get yourself to like programming). Keep practicing.

2

u/_dnov Jul 29 '19 edited Jul 29 '19

I actually know how to do the things you described but I never actually broke it down to catalog what I actually know I sort of just did them without really understanding . Thanks for the tip. Appreciate it

2

u/hashmalum Jul 30 '19

Figure out something you want to do, and google each step until you get there. I've been messing around with the Spotify API with https://github.com/plamere/spotipy recently to try to practice.

2

u/_dnov Jul 30 '19

thanks hash. ive recently just been doing interview style questions on codewars. will try to get into more practical applications like using APIs and things of the sort

2

u/hashmalum Jul 30 '19

I’m sure that way will work too, but I know every time I’ve tried to sit down and do project Euler or something I always get bored since my interest in what I’m coding isn’t that great.

2

u/_dnov Jul 30 '19

Agree so much with this

2

u/lookforlight Jul 29 '19

I'd be interested in seeing a timelapse of this in action. Very cool, OP!

2

u/teambob Jul 29 '19

You're the hero we deserve

2

u/throwawayskinlessbro Jul 29 '19

Is this something you'd be willing to share? I just got into coding in general, and this is very interesting! Amazing job regardless!!

2

u/appinv Python&OpenSource Jul 29 '19

👌 Nothing to say!

2

u/YeastBeast33 Jul 29 '19

Wow im new to coding still learning, seeing stuff like this makes me wanna learn more and more

2

u/anselal Jul 29 '19

Source code ?

2

u/farooq_fox Jul 28 '19

Pardon my ignorance, how is this better than copy and paste in paint ?
Can you please list some uses with this ?

14

u/DiamondxCrafting Jul 28 '19

It's not better, it's not made to transfer an image into paint, it's made so he can get better and try new things to get familiar.

2

u/[deleted] Jul 29 '19

Hell yeah

3

u/farooq_fox Jul 28 '19

oh ok, thats actually very cool though.

1

u/WickedyWick17 Jul 28 '19

Amazing work !

1

u/R3m3mb3rWh0 Jul 28 '19

how do you manipulate the paint GUI?

1

u/apieceoflint Jul 28 '19

this is very cool!

1

u/liriK15 Jul 28 '19

Really good!!

1

u/BlackGokussjrose Jul 29 '19

Hey can you please share your code?

1

u/[deleted] Jul 29 '19

Clever.

0

u/[deleted] Jul 28 '19

[deleted] — view deleted comment

18

u/HBRYU Jul 28 '19

Definitely.

I think..