Hi again!
I really can’t believe it myself, but it works just fine ;-)
All of this is coded in Perl and is only tested on linux. The program uses these modules, if you don’t have them install from CPAN as root. You will need a working version of GCC + all the libs installed.
- Device::SerialPort
- Time::HiRes
- Imager
- Imager::Screenshot
1 2 3 4 5 | perl -MCPAN -e shell install Device::SerialPort install .... install ... exit |
The module Imager::Screenshot is used to capture a screenshot of my current X11 desktop. It supports taking a full screenshot, capturing a specific window giving the window ID, …, or capturing a arbitrary rectangle with the coordinates (top, left, right, bottom) starting with (0,0) in the top left corner of your screen. Running X11 you can get access to cursor coordinates with the xinput tool like this:
This lists all input devices known to your X11 server:
1 | xinput list |
This displays the cursor position of my input device Mouse[1]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | xinput query-state Mouse[1] 2 classes : ButtonClass button[1]=up button[2]=up button[3]=up button[4]=up button[5]=up button[6]=up button[7]=up button[8]=up button[9]=up ValuatorClass Mode=Relative Proximity=In valuator[0]=369 <-- X valuator[1]=406 <-- Y |
You can use this information to narrow down the active region for capturing the image.
The image is taken
36 | $img = screenshot(left=>775,right=>783,top=>488,bottom=>496); |
and scaled down to 8x8 pixels.
37 | $newimg = $img->scale(xpixels=>8, ypixels=>8); |
Then a single line is extracted using
41 | @scanline = $newimg->getscanline(y=>$row); |
Pixel data is extracted from the @scanline object using
43 | ($red,$green,$blue,$alpha) = $scanline[$led]->rgba; |
Reading and transmitting the image data is done with 2 for loops for “row” and “led”.
DONE.
Here’s the code: show_ppm_v4.tgz
To display a box of NxM pixels under your mouse cursor just run the script as
1 | ./screen_video.pl N M |
Here’s an example video:
Related posts:
hi rob,
the 8x8s just get better, any way of this working on windows?
if not il partiton my hdd nd chuck linux on it
Well… the Perl modules I used are also available for windows, so maybe yes.
In the long run I’m planning to get this working with Processing though, which runs on windows as well.
I’d find it even more attractive, if somebody else (hint hint) did the Processing code for me. More time for my Ikea lamp mod ;-)
What I need to install before I can install those modules? Because my cpan can’t make nothing. I installed some gcc things.
Well, you need gcc + libs and make. Some more packages may be pulled in automatically by dependencies. The CPAN installer will also automatically fetch missing dependencies for the perl modules.
What error messages do you get ?
I think I didn’t have make and X11.
I managed to install everything expect Imager::Screenshot.
Error:’/usr/bin/perl Makefile.PL INSTALLDIRS=site’ returned status 512, won’t make
Hmmm. Did you also install the devel packages (libX11-dev and related) ?
Now I managed to install Imager:Screenshot too. It didn’t made Makefile. Wierd.
How powerfull computer you used to send data to matrix? Because I made c# program that send image from screen to matrix. It does something too slow because I can when it is changing row color.
My machine is an Athlon64 X2 running in powersave mode at 1GHz. CPU load for the perl script is about 8-10%.
Finally I managed to install and use everything. It works better than my c# program. So I am going to convert your code to windows. After that I can test is problem windows or my program.
I am running AMD Celeron 1GHz with 512 drr memory.
How do you use the X11 stuff on windows? The screenshot code has win32 support as far as I’ve read.
Anyway, please let me know when it works.
Pingback: Melkein reaaliajassa kuvaa pöydälle. « ISO-Blogi