r/Python • u/mshoaib9711 • May 18 '20
I Made This So I made a Python and Arduino project that dynamically changes sets the ambient lighting to match the computed dominant color values from the wallpapers.
121
u/Zhababui May 18 '20
This is really cool. I also love all of your wallpapers. Would making this work for something like every X frame of a video game work? Or would that fry the Arduino. I’m not very familiar with them.
64
u/mshoaib9711 May 18 '20
Thanks a lot! Yes. That was definitely in my mind. Wouldn't be a bad idea to attempt. CPU optimisation would be key there.
13
u/densvedigegris Computer Scientist May 18 '20
You would probably have to do it at 30 fps or more to make it smooth. I'm not sure how that would affect performance, since you would have to transfer the screen buffer (essentially take a screenshot) 30 times a second. The CPU stuff could be done extremely fast with a vector library (NumPy might even be enough).
10
u/f3xjc May 18 '20
With lag you can make anything smooth. IE take 1 screenshot per second, smoothly interpolate between color 1 and 2 over a second. Only downside is you're always one second late, probably only visible on a fast transition.
Then you can see how fast you can Crank the thing. Probably 5 per second feel interactive.
2
0
May 18 '20
[deleted]
4
u/densvedigegris Computer Scientist May 18 '20
-if- you could sample random pixel (for low res sample), you could, but I don’t think that’s possible
1
u/to7m May 19 '20
Is the problem with trying to capture anything that's not a full screen? If not, one solution could be to ignore frame rate and just continuously capture random pixels, and take a moving average colour from that.
1
u/densvedigegris Computer Scientist May 19 '20
It may be a non-issue, but my worry is the fact the you have to transfer the screen buffer from the GPU to the CPU that often.
About random pixels: It might take just as long to get the whole screen, than a few pixels (if you account for the latency and the context switches). You should see the GPU as a device on the network like a NAS or something.
Normally, when you stream your video output, there is a dedicated chip to encode the signal to h264 (not 100% sure about the codec) and send the compressed signal to the CPU.
This library sounds promising: https://github.com/BoboTiG/python-mss “An ultra fast cross-platform multiple screenshots”
I may try it sound in the weekend
1
u/to7m May 19 '20
Sounds like it might be efficient to capture a full video stream, but then only read random pixels from that captured stream.
7
16
u/TheMediaBear May 18 '20
You could just use the Raspi TV ambient lighting setup like this:
8
u/panalgin May 18 '20 edited May 18 '20
the way in the video requires external hardware for decoding video signals over hdmi or analog video out. However if the OP can manage it with just in software, it will be a lot less dependent on external devices. just my 2 cents thx.
9
u/TheMediaBear May 18 '20
but, if it's done with external hardware (which is what the Arduino is anyway) and it's done as the video does it, that can be removed and used on a TV as well as a monitor
4
u/panalgin May 18 '20
Yes correct, and having to be supporting any hdmi/analog video output device is superb but, the magic relies in the that hdm/signal processor device used. As far as I know those things are expensive to get. However spending a few bucks on arduino and a led strip is a lot simpler, and they are so common basic electronic devices, everyone have them at home.
4
u/TheMediaBear May 18 '20
No, everyone doesn't have an Arduino and LED strips lying around at home. I've at least 4 Raspi's but no Arduino.
And the price for the HDMI output devices etc come to about $20's, similar to what just a basic Arduino board comes too.
The youtube video has links to all the parts needed and none are overly expensive
2
u/panalgin May 18 '20
Well seems like you're right, I thought those hdmi capturing devices were too expensive but they aren't. And raspberry is powerful enough to work with video signal's already. That's one better approach, thanks for sharing i will give it a try since I have a raspberry too!
Thx
1
u/Switchen May 18 '20
There are loads of solutions like this something like Bambilight just works over USB with the software running on the PC.
2
2
u/audrey_i_think May 19 '20
You're describing a project called Adalight. I built one a few years back - it works really well!
1
u/Russian_repost_bot May 19 '20
60 frames a second or worst, if it's a 144hz monitor, 144 frames a second. Getting that amount of data would very likely be too much for an Arduino.
Now, whether you could minimize that, by not getting it every frame, and instead only a few times a second, without your eyes noticing it, that'd be the real interesting part.
If the data is being captured by using a screen grab, another hard part to take into account is screen resolution. At 4k+, even shrunk down to a workable size, is still processing power used to shrink a 4k screen grab down to a manageable "color checking" size.
It's cool, but moving from stills into the realm of movies and video games seems very cumbersome or at least a large increase in code, and checking that things are working smoothly enough for the eye not to see a flicker, which could end up being more annoying than cool.
13
15
u/kokoseij May 18 '20
Awesome!
Are you going to upload this on github? I want to know how it works.
16
u/mshoaib9711 May 18 '20
Will soon!
2
u/mshoaib9711 May 19 '20
1
u/kokoseij Jun 01 '20
Nice
1
u/nice-scores Jun 01 '20
𝓷𝓲𝓬𝓮 ☜(゚ヮ゚☜)
Nice Leaderboard
1.
u/spiro29at 9781 nices2.
u/RepliesNiceat 8551 nices3.
u/Manan175at 7099 nices...
248393.
u/kokoseijat 1 niceI AM A BOT | REPLY !IGNORE AND I WILL STOP REPLYING TO YOUR COMMENTS
11
u/FriendOfDogZilla May 18 '20
RemindME! 2 weeks
3
u/RemindMeBot May 18 '20 edited May 22 '20
I will be messaging you in 10 days on 2020-06-01 13:27:31 UTC to remind you of this link
54 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback 2
1
1
1
1
1
1
1
1
1
1
1
0
13
u/rauchboy May 18 '20
That's neat! Can you please share some guides if you have?
17
u/mshoaib9711 May 18 '20
Glad you liked. I didn't really follow any particular guides. It was research and gathering of bits and pieces from all the internet. But if you want anything in particular, I can help. Cheers!
4
2
2
2
u/petertiny1 May 18 '20
I'll have your whole stock!
1
u/mshoaib9711 May 18 '20
Haha. You can support me on "Buy me a coffee" until I have stocks :P Thanks and appreciate it :) https://www.buymeacoffee.com/mshoaib9711
1
u/petertiny1 May 18 '20
Nah. I'll build it myself. What parts did you use?
2
u/mshoaib9711 May 18 '20
Will be on my Github.
1
u/petertiny1 May 18 '20
Where's the GitHub comment?
1
u/mshoaib9711 May 18 '20
Isn't up yet!
1
u/petertiny1 May 18 '20
Remind me when you have a link please!
1
40
43
u/Eelz_ May 18 '20
Code?
25
u/Cryptokudasai May 18 '20 edited May 18 '20
Os I edam a nothyP dna oniudrA tcejorp taht yllacimanyd segnahc stes eht tneibma gnithgil ot hctam eht detupmoc tnanimod roloc seulav morm eht srepapllaw.
It's a rather simple code.
43
May 18 '20
morm
Boooh
16
u/Cryptokudasai May 18 '20
<EDIT>: morf
your reverse spell checker is better than enim!
<EDIT EDIT>: seriously, wow!
1
1
u/mshoaib9711 May 19 '20
Sorry for the long delay everyone. Here's the repo. https://github.com/mshoaib9711/WallpaperLedstrip.git Hope you guys like it. Thanks!
5
1
u/bamtuk May 18 '20
Could you please explain how you managed to control the light is it directly connected to the arduino or how did you do it?
6
u/mshoaib9711 May 18 '20
The Arduino is hooked up to the PC via USB. I make use of serial communication to send color data from Python to Arduino. Arduino then uses this data to set the lighting.
2
u/bamtuk May 18 '20
Interesting but I kinda wanted to know how you turn on the lighting when the arduino gets the color it should turn on.
2
u/terpaderp May 18 '20
He in another comment he is using WS2812 LEDs, these include a driver IC and lighting level is set via serial connection.
2
u/dscottboggs May 18 '20
In case you were wondering how to do this with driverless LED lights, you need some transistor chips for PD (like an STA412A) and then use a PWM algorithm to switch on the transistors with different intervals which give you longer "on" periods for brighter or longer "off" periods for darker.
1
u/MegaAmoonguss May 18 '20
What controller are you using for light control? I'm familiar with fadecandy but I'm interested in other ways people are going about controlling LEDs with python
2
u/mshoaib9711 May 18 '20
I am using an Arduino. All you need is programmable LEDs and supported microcontroller. You can do it with many controllers that work on circuit python too.
1
1
1
u/the0MIKE May 18 '20
Great project, looks awesome!
Can you please explain the hardware setup a bit more? What lights etc. are you using?
2
1
u/ovo_Reddit May 18 '20
How much did this cost you in parts? I’ve been looking at some that do this over HDMI to have dynamic ambient lighting for my TV but those are crazy expensive.
1
u/mshoaib9711 May 18 '20
An Arduino Uno and a $50 dollar Adafruit Neopixel Led strip are the main components of this project
1
u/the0MIKE May 18 '20
Does this only work with the background or also when you play videos/games?
1
u/mshoaib9711 May 18 '20
As of current, only on images. But I hope to continue and make it work for videos as well.
1
1
u/Dadotox May 18 '20
I think this is really cool, but I would suggest a slower transition between color configurations. It would be way smoother.
1
1
u/Bluhb_ May 18 '20
Do you have a github up for this? if not could you please upload it to somewhere. Would really like to look into the code and see if it works or is adaptable for linux. I can see some projects come in handy where a rpi is connected to a screen and also to a ledlight(read smarttv with ambilight 2 in 1 solution)
1
1
1
u/SayaNevermind May 18 '20
Are you communicating between your python script and the Arduino via serial?
2
1
u/LelandCorner May 18 '20
I am just learning Python for fun bc of lockdown. I didn't realize it could do this. What else it could do or couldn't do? I like to know its limitations.
1
1
May 18 '20
I feel like a gradual fade to the new color may work better than just instantly changing the colors. Still looks amazing though!
2
1
1
u/serious8 May 20 '20
Can somebody do a full video tutorial how to set this up for us total noobs? thank you
1
1
u/dangdatkat Jun 22 '20
This looks really interesting. I have never messed with Arduino before. Would you consider this a "basic" Arduino project that a person learning the platform could setup?
1
u/mshoaib9711 Jun 24 '20
Wouldn't try this as my first Arduino project for sure x)
1
u/dangdatkat Jun 25 '20
Thank you for talking me out of it. :)
1
u/mshoaib9711 Jun 25 '20
Oh I am sorry. Should I suggest you start by building out a Tesla?
1
u/mshoaib9711 Jun 25 '20
On a serious note, I would have had a really tough time if I did this as a newbie, but sure, go ahead give it a try. Let me know if I can help you in any sort.
3
1
u/Kaltane May 18 '20
Can you do it with the current screen colors instead of just the wallpapers? Awesome tho.
2
2
u/Wanstein4 May 18 '20
Wow this is so cool. I've just recently started learning Python. This would surely energize me.
2
u/ThE_JCVP11 May 18 '20
Really cool - glad I got to see you working on it first hand and encourage you through the process xD
2
2
2
u/lambda5x5 May 18 '20
Wow just yesterday I was thinking of doing something like this for geometry dash. This post gave me some motivation so maybe I'll do it!
2
2
2
2
1
1
u/aneurysm_ May 18 '20
Great idea and awesome final outcome!
Could this be done wirelessly using something like the esp8266 wifi module?
2
1
u/atom036 May 18 '20
Looks awesome. What kind of delays are you getting between the change of the image on screen and the LEDs? Are you just taking a screenshot to get the dominant colour or are you using something more clever?
2
u/panalgin May 18 '20
python script calculates all dominant colors of several wallpapers in a directory and uses this at the same time changing the default desktop wallpaper, so its not dynamic screen capturing, and so thats why its fast.
1
u/welsh_will May 18 '20
I was wondering the same, except it looks like it's the other way round, that the lights are changing before the screen image. Or am I just imagining that?
1
u/69shaolin69 May 18 '20
Is it looking at the monitor pixels values or the wallpaper image dir?
1
u/panalgin May 18 '20
python script calculates all dominant colors of several wallpapers in a directory and uses this at the same time changing the default desktop wallpaper, so its not dynamic screen capturing, and so thats why its fast.
processing wallpapers prior to setting them as current desktop wallpaper
1
1
1
1
u/iron_fist96 May 18 '20
Hey! I had a similar idea! Never got around to making it thanks to school.
Great job man.
1
1
1
1
1
1
u/TheHolyHerb May 18 '20
Awesome job! I’d love to check out the code. I made something similar for Linux awhile back that sets a random background then pulls the most common pixels and sets my razer devices and hue lights to that color. It was a good project to learn that the colors you see as dominant in a picture aren’t necessarily the most common pixel color in an image.
1
u/vanhasenlautakasa May 18 '20
Nice work! I did same kind of project while a go. I used Philips Hue and read computer screen realtime to match current color of the screen. Trick was to take screenshot and change the size of the image to 1x n, where n is amount of lamps. Then just send the color of the particular pixel to the right lamp.
1
1
1
u/kindall May 18 '20
Maybe use a contrasting color for the backlighting to make the colors on the screen "pop" more?
1
u/onesmallserving May 18 '20
I love this kind of setup! I've always thought it would be perfect for a home theatre to immerse you in whatever you're watching. You should post a video of it with a game running on your monitor!
1
1
1
1
1
1
1
1
1
1
1
1
0
0
May 18 '20
[deleted]
16
u/mshoaib9711 May 18 '20
I don't think it's very complicated. I am not a professional programmer myself. So I think you are good to go buddy 👍
1
Aug 29 '20
[removed] — view removed comment
1
u/mshoaib9711 Sep 02 '20
Hey man. Not sure what's use of that in my project.
2
18
u/mshoaib9711 May 18 '20
Hey guys! Thank you all for your overwhelming responses. This is my first time ever posting on Reddit. Didn't expect such great responses. Thanks a lot. Definitely motivates me to keep going. Also for everyone asking for code, I will be making the repo ready for public by the end of the day so for those willing to contribute can start right away. Thanks again guys. Means a lot to me🙌🏻