Golang, how can i get color value of a particular pixel on the screen in real time - image

I need to get the value of a single pixel of the screen at a predetermined location, in something like hex or rgb and it should be quite fast. How can i do that in Go?

Rosetta Code has a page with solutions for this problem in various languages, including Go.
https://rosettacode.org/wiki/Color_of_a_screen_pixel
Using the RobotGo library you can call GetPixelColor to get the color of a screen pixel as a hex string.
RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x86-amd64.

Related

OSX: automated (every 1-2sec) screenshot (not full screen but (x,y,w,h)) using python

I want to make screenshots on OSX using python. I dont want make full screen shots but only certain rectangles on the screen. Something like (291,305,213,31). I need the correct pixel because afterwards the image files are processed by OCR (python-tesseract) to extract the text.
By the way this is since 6 years the first time I am programming, so far I only know Java a bit. I started yesterday and gave up this morning at 4am. So basically I have no clue yet...For example I still cannot build with Sublime because of path settings, but thats a different story. Cant figure out everything on one day.
I was trying already the following:
- wxPython
But the result are black images, see also:
stackoverflow.com/questions/8644908/take-screenshot-in-python-cross-platform
Additionally it only works in 32-bit mode, but when I do OCR using python-tesseract openCV requires 64-bit....
autopy
when trying to install I got errors, see also:
stackoverflow.com/questions/12993126/errors-while-installing-python-autopy
ImageGrab
only Windows
effbot.org/imagingbook/imagegrab.htm
commandline screencapture
os.system('screencapture test.png')
When I found this I thought, nice but only fullscreen when checking man screencapture. But then I found this: guides.macrumors.c om/screencapture
-R capture screen rect
That would be already enough, but on OSX 10.7.5 I dont have this option. Any ideas?
import Quartz.CoreGraphics
neverfear.org/blog/view/156/OS_X_Screen_capture_from_Python_PyObjC
Create screenshot as CGImage
image = CG.CGWindowListCreateImage(
region,
CG.kCGWindowListOptionOnScreenOnly,
CG.kCGNullWindowID,
CG.kCGWindowImageDefault)
Unfortunately the image is not in file format but a CGImage, no idea how to save as file.
So if possible I would like to use the commandline screencapture with -R if somebody knows how. Just as a start to continue.
Are there any other command line tools available?
What about other libs that I have missed?
Cheers
M
Given that you can get a CGImageRef, you can get its pixel data using the techniques described in Technical Q&A QA1509: Getting the pixel data from a CGImage object. In particular, it shows a function to get the pixel data as a CFDataRef using this function:
CFDataRef CopyImagePixels(CGImageRef inImage) { return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); }
and says:
The pixel data returned by CGDataProviderCopyData has not been color
matched and is in the format that the image is in, as described by the
various CGImageGet functions …
It shows an alternative for getting the pixel data in other formats if you need that.

How can I capture the screen with Haskell on Mac OS X?

How can I capture the screen with Haskell on Mac OS X?
I've read Screen capture in Haskell?. But I'm working on a Mac Mini. So, the Windows solution is not applicable and the GTK solution does not work because it only captures a black screen. GTK in Macs only captures black screens.
How can I capture the screen with … and OpenGL?
Only with some luck. OpenGL is primarily a drawing API and the contents of the main framebuffer are undefined unless it's drawn to by OpenGL functions themself. That OpenGL could be abused was due to the way graphics system did manage their on-screen windows' framebuffers: After a window without predefined background color/brush was created, its initial framebuffer content was simply everything that was on the screen right before the window's creation. If a OpenGL context is created on top of this, the framebuffer could be read out using glReadPixels, that way creating a screenshot.
Today window compositing has become the norm which makes abusing OpenGL for taking screenshots almost impossible. With compositing each window has its own off-screen framebuffer and the screen's contents are composited only at the end. If you used that method outlined above, which relies on uninitialized memory containing the desired content, on a compositing window system, the results will vary wildly, between solid clear color, over wildly distorted junk fragments, to data noise.
Since taking a screenshot reliably must take into account a lot of idiosyncrasy of the system this is to happen on, it's virtually impossible to write a truly portable screenshot program.
And OpenGL is definitely the wrong tool for it, no matter that people (including myself) were able to abuse it for such in the past.
I programmed this C code to capture the screen of Macs and to show it in an OpenGL window through the function glDrawPixels:
opengl-capture.c
http://pastebin.com/pMH2rDNH
Coding the FFI for Haskell is quite trivial. I'll do it soon.
This might be useful to find the solution in C:
NeHe Productions - Using gluUnProject
http://nehe.gamedev.net/article/using_gluunproject/16013/
Apple Mailing Lists - Re: Screen snapshot example code posted
http://lists.apple.com/archives/cocoa-dev/2005/Aug/msg00901.html
Compiling OpenGL programs on Windows, Linux and OS X
http://goanna.cs.rmit.edu.au/~gl/teaching/Interactive3D/2012/compiling.html
Grab Mac OS Screen using GL_RGB format

GUI to view values in image using OpenCV in ubuntu12.04

Is it possible to simultaneously display an image and the pixel,coordinate values based on the mouse pointer positions?
I am asking an OpenCV equivalent of imview function in MATLAB.
You don't need Qt to do that. Just use default OpenCV function imshow to show image and SetMouseCallback to set callback on mouse click.
It can be done using mouse call back events. You can find a good example in \opencv\samples\cpp\grabcut.cpp
I had a few problems trying to do this with OpenCV alone using an old code I wrote a while back. At this point I'm not sure if I missed something or if it's a bug in OpenCV. I'll investigate this further.
But I shared a short, self contained, correct (compilable), example at my repository, check cvImage. It's written in C++ with Qt and OpenCV. It's a Qt application that loads an image with OpenCV and displays the RGB values as the title of the Qt window.
Move the mouse around and place the cursor on top of the pixel that you are interested at to see it's RGB value.
Opencv with Qt support will do that.

Printing a graphic to a Zebra LP2844 with the GW EPL command?

I need to print an image that is being returned to me through a web service (the data is returned as RAW) and I cannot for the life of me figure out how to print a graphic to a label with EPL.
The EPL manual defines the Graphic Write instruction as:
GWp1, p2, p3, p4, DATA
All of the parameters are returned to me, so I don't have to worry about calculating the height, width, etc., but my problem is that I don't know how to format the DATA.
The manual says DATA should be
Raw binary data without graphic file formatting. Data must be in bytes.
I've tried passing a binary string and a hex string, but nothing seems to work. There is no example on how to use this command in the EPL manual and after hours of searching online I have not been able to find a single example of how to use the command (i.e. example EPL commands that I can copy & paste to send to the printer).
Does anyone have an idea of how to use this command? Could you provide me with an example? (by example I don't mean a framework, code, etc., what I mean is just the plain EPL commands).
I can confirm that the data is in raw, uncompressed binary. It is also inverted-- that is, the 0 bits print as black, at least on my UPS-firmware LP-2844. I have no idea why all the examples from Zebra show the data as encoded into a hex representation.
It's worth noting that most print servers (HP Jetdirect, Lantronix LPS1-T, and almost certainly the Zebra built-in and external print servers) will form a binary connection to the printer if you spit data at them on port 9100 (using netcat for example):
nc printer_hostname_or_ip_address 9100 < test_file.txt
You get no feedback from the printer, except for the label having printed or not.
It takes my LP-2844 (UPS Firmware) printer about 5-6 seconds to print a label containing a 816 wide x 1218 tall downloaded bitmap onto a 4" wide x 6" tall label. It seems to be all imaging time: sending three labels at once is not any faster, and the network connection (through a Lantronix LPS1-T) is held open until the final label prints. That image is at the native resolution of the printer (203 dots/inch), and there is no dithering or resizing going on (I don't think EPL2 even knows how to dither or resize).
It might be possible to speed up the imaging time by optimizing the label into many smaller bitmaps (and horizontal and vertical line segments, and perhaps filled-in rectangular blocks). This wouldn't be a very hard optimization because the image is a single-bit black and white bitmap, and the code would be fairly simple. I don't know if it would really speed it up, though.
A more modern Zebra GX420 running ZPL with a built-in ethernet port ($500 online) can print the same label (with essentially the same graphic download encoding) in 1-2 seconds.
By the way, since I haven't yet actually answered the question, the raw EPL code for this is:
(a blank line)
N
q816
Q1218,20
GW10,10,102,1218,(124236 bytes of inverted bitmap data)
P
all the newlines are 0x0a (unix-style).
Maybe this will help, it has examples (and corrects an error in the manual). Also, it may be easier to use the GM command instead and just delete the image each time (see here for a stackexhange related question).
That being said, I've never gotten my Eltrons to successfully print an image (but my jobs don't require it).
Good luck!!
EDIT: Here's another link with example Perl code. They're aiming for Chinese characters but show how to print the Great Wave image (which oddly is Japanese).
I found that it is not possible to send a graphic to a Zebra printer with EPL using ASCII characters. The data must actually be sent as RAW data. So, for example, you can't send a graphic to the printer using Zebra Setup Utilities, or through any other means that cannot write RAW data from a file directly through the printer.
The only way around this I've found is to create the label as an image and send that image to the printer via a print command within your application.

Save matrix of double values in OpenCV

I have an OpenCV matrix of double (CV_32F) values. I'd like to save it to the disk. I know, I could convert it to an 1-Channel 8-bit IplImage and save it. But that way, I loose precision. Is there a way to save it directly in the 32-bit format, without having to convert it first? It also would be nice, if the resulting file would have an image format, so I can view the result as an image.
You can always save any "object" (CvMat, IplImage, anything..) from OpenCV "as is" by using cvSave() and loading it back with cvLoad(). As to my experience, most floating-point image stuff does not work correctly, I usually save my floating point data this way.
However, you cannot directly view the stored data.
Another possibility we have used frequently is including an own built of OpenEXR. You can easily store full precision floating point images using this library and many third party applications are able to open EXR files. Note that OpenCV includes OpenEXR, if i am not mistaken, but the last time i've tried, saving/loading floating point images did not work correctly. However, you should first try to save an fp image as *.exr, maybe that already does the magic with recent versions.
You could always iterate over the matrix and write it out yourself. If you want it to be viewable as an image, you can use a variant of PPM. I'm not sure what programs would be able to natively read your image format if you use values out of the 0-255 range though.
This is old, but thought I'd throw in my two cents.
If you just want to save float images to disk, and you don't need to view them, you may want to look at Portable Float Map (PFM) image format. Very simple format, just saves floats to disk, no compression, minimal header. You can write your own read/write code for this very quickly. That's what I'm using for HDR research.
As the others pointed out, to "view" float images you need to ask yourself some questions about their contents and how to sensibly scale them back into an 8-bit range you can display on your monitor. You might consider Matlab's image viewer (imshow function) which offers some double scaling functionality.
You might also consider saving to either EXR or HDR format and using Photomatix's built-in HDR image viewer which gives you a little separate window that shows you a real-time tonemapped window around your current cursor position. It's a good way to navigate an HDR or floating point image to get a sense of "what's really there" without tonemapping the whole thing.

Resources