[1.0.1] Mac: Retina display: Sikuli screenshot images are not found (not scaled to 200%)

Asked by keith Fischer

png file screen capture from OSX command-shift-4 is never found in region. But if I record capture the same image with sikuli IDE it works. Is a png not a sikuli compatible png depending on the tool? Do I really have to use sikuli IDE to record images? It seems on win7 this is not an issue. e.g. I can use windows snipping tool to make png's for sikuli. I spent days spinning on this. The command-shift-4 png output looked ok in the finder and preview so I never suspected the image.
I'm using java and netbeans with all the recommended sikuli jars. Last thing I ever imagined of how the png is saved from which tool being the issue.

So if I save the image with sikuli IDE and copy to my java image lib all works fine.
With no change in code but replacing the png file in the java project image lib.
Fails to work with image saved from command-shift-4.

Below shows the png is loaded ok but fails to be found in the app.window.region
Weird.

Thanks
Keith

======S T A R T ===========
[debug] ResourceLoaderBasic: SikuliX Package Build: 1.0.1 12SEP2013160242
[debug] ResourceLoaderBasic: check: we are running on arch: x86_64
[debug] ResourceLoaderBasic: check: using Java at: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/
[debug] ResourceLoaderBasic: check: Exists libs folder at location of jar? YES: /Users/keithfisher/NetBeansProjects/Sikuli/
[debug] ResourceLoaderBasic: checkLibsDir: /Users/keithfisher/NetBeansProjects/Sikuli/libs
[debug] ResourceLoaderBasic: loadLib: MacUtil
[debug] ResourceLoaderBasic: loadLib: Found: MacUtil
[debug] ResourceLoaderBasic: loadLib: Now loaded: MacUtil
[debug] ResourceLoaderBasic: checkLibsDir: Using libs at: /Users/keithfisher/NetBeansProjects/Sikuli/libs
[debug] ResourceLoaderBasic: check: Using this as OCR directory (tessdata) too
[debug] ResourceLoaderBasic: loadLib: Is already loaded: MacUtil
[debug] Screen: initScreens: basic initialization (2 Screen(s) found)
[debug] *** monitor configuration (primary: 0) ***
[debug] Screen 0: S(0)[0,0 1920x1200]
[debug] Screen 1: S(1)[1920,-720 1200x1920]
[debug] *** end monitor configuration ***
[log] App.open VNC Viewer(0)
[log] openApp: "VNC Viewer"
[log] highlight R[1361,65 540x1018]@S(0)[0,0 1920x1200] E:Y, T:3.0 for 1.0 secs
[log] App.focus VNC Viewer(0) #0
[log] openApp: "VNC Viewer"
[debug] imgFullpath:/Users/keithfisher/NetBeansProjects/testSmartLib/imgs/settings.png
[log] highlight S(0)[0,0 1920x1200] E:Y, T:3.0 for 1.0 secs
[log] App.focus VNC Viewer(0) #0
[log] openApp: "VNC Viewer"
[debug] waiting for /Users/keithfisher/NetBeansProjects/testSmartLib/imgs/settings.png to appear
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] ResourceLoaderBasic: loadLib: VisionProxy
[debug] ResourceLoaderBasic: loadLib: Found: VisionProxy
[debug] ResourceLoaderBasic: loadLib: Now loaded: VisionProxy
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] Screen.capture: java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] RobotDesktop: captureScreen: on 0 using java.awt.Rectangle[x=1361,y=65,width=540,height=1018]
[debug] /Users/keithfisher/NetBeansProjects/testSmartLib/imgs/settings.png has not appeared.

FAILED:can not find /Users/keithfisher/NetBeansProjects/testSmartLib/imgs/settings.png on the screen.
FAILED ***

======D O N E ===========

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
RaiMan Edit question
Solved by:
keith Fischer
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

You are right, this should not be.

And I cannot reproduce the problem on my Mac 10.9 with version 1.0.1 (using the hotkey (direct save to desktop) or the feature inside Preview even cropping the image and then save it)

You might compare 2 screenshots (snipping tool image and the same captured with Sikuli IDE) manually in Preview with some magnification, so you can see possible differences on the pixel level.

... and I do not know, wether the fact that you are using a VNC-Viewer influences the result of the Mac snipping tool.

Revision history for this message
keith Fischer (fischertech00) said :
#2

I have Mac 10.9.1
For now I'll use the sikuli ide to create the png icons for tests with Mac. Another observation is while using sikuli ide for repeated script runs in the ide, the ide will after dozens of successful runs, get in a state where the png patterns are not found on the region. Restarting the IDE will find the png matches in the region again. Normally from the shell script or batch and the problem does not occur.

I'll continue to experiment with the png recognition phenomena on my system and update this post when I have new info.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

thanks for feedback and future contribution

Revision history for this message
keith Fischer (fischertech00) said :
#4

Still researching and I still can't get the mac to create sikuli usable png images from it's native screenshot interface. Tried the hotkeys and the terminal screencapture methods. I'm using png screen capture tools in my fusion win7 VM to manage the hundreds of test images in the library for the mac sikuli testing. Very roundabout way. Does the Sikuli IDE use OSX native screen capture API? Unfortunately I'm not a Mac developer and don't know all the details of OSX system api's like on Win32.

Can anyone with OSX and Sikuli experience, can you suggest any hypothesis of what can be the inhibiting factor for this issue I could research? I'm out of ideas and no one else seems to have the problem. How does Sikuli do the screenshot region? use java library?

1. OS X Sikuli IDE feature "Take screnshot" png works ok and is recognized in sikuli find() flawlessly every time.
2. OS X cmd-shift-4 Native png FAILS to be recognized in sikuli find()
3. Terminal screencapture -t png -i FAILS to be recognized in sikuli find()
4. Third-party tool like SnapNDrag FAILS to be recognized in sikuli find() (probably uses the same osx native api)

The above tests use same UI target region and sikuli code, different png files in same folder.

Thanks
Keith

Revision history for this message
keith Fischer (fischertech00) said :
#5

I'm using MBP with retina display scaled to 1920x1200.

The region is realvnc viewer app window with target client window connected to remote usb vmc server host with vnclite on samsung s3. The realvnc host image is scaled at 75% so whole android screen shows without scrolling.
Sikuli screenshot records png at 100%
Mac OSX screenshot records png at 200% relative to the sikuli png screenshot. Although visibly in the editor looks the same size.

If I take the editor and resize Mac OSX screenshot by 50% it works fine on Sikuli region.find().

So how can I get the Mac to create screenshots at the same image size as Sikuli png screenshot output?

Thanks
Keith

Revision history for this message
RaiMan (raimund-hocke) said :
#6

Uuups, retina display !!?? I do not have experiences with that (I am still pre-retina with my Macs ;-)
That might have an influence on how the native Mac screenshot works and what kind of png it produces.

I never had any problems with the screenshot tools on Mac until now. The only problem I faced was when using Preview to manipulate the images before usage in Sikuli (e.g. crop). This might have something to do with Mac's special colour management.

Could you send me some shots taken from the same target with different techniques silently to my Mail at https://launchpad.net/~raimund-hocke?

BTW: Sikuli internally uses Java's Robot class (createScreenCapture(rectangle)), which hides the system specifics and seems to work the same on all systems and in all cases.

Revision history for this message
keith Fischer (fischertech00) said :
#7

For now I’m grabbing cmd-shift-4 images on an external screen. That works fine on detecting the png in the region on a retina display.

Thanks
Keith

Revision history for this message
RaiMan (raimund-hocke) said :
#8

Thanks for the samples.

The net tells me, that Retina even with Java 7 40+ is not fully supported in all cases. Java 8 promises to have solved the problems.
Apples adapted own Java 6 is said to support Retina correctly.

I have it on my list now.

Revision history for this message
Barry Janzen (barry-janzen) said :
#9

You could also use "sips" on Mac to handle image translation, e.g. - to translate some tiffs that are higher res Retina images that I want to go to 32 pixel wide png's for Sikuli: sips -s format png --resampleWidth 32 *.tiff --out *.png

Revision history for this message
Barry Janzen (barry-janzen) said :
#10

You can also (easier) do a screen capture, then open the image in Preview and click Tools->Adjust Size... and halve the values of width, height and resolution (should step it down from 144 to 72). Just tried it and it works.

The other issue I run into when grabbing images from products or source trees is that png's can (and often do) have transparent backgrounds. You can convert those to jpeg's and back to png's using sips, but they end up with a white background. If someone has a Mac solution, without having to use ImageMagick or something else to be downloaded, I'd be grateful for a solution.

Revision history for this message
RaiMan (raimund-hocke) said :
#11

@Barry
Thanks for the testing and comments.

I will turn this question into a bug about Retina issue and create a new request bug about handling transparency in images.

Revision history for this message
Noktyn (noktyn) said :
#12

@Barry:

Thank you so much, this fixed the issue I was having. I had 2 machines running my java test scripts and one worked with sikuli and one didn't. I kept checking file paths and how I had my .JARs loaded into my project library, but it had to do with retina display -_-.

I halved the pixel values of the .PNG image files it couldn't read and voila, sikuli started working again. Very odd, thank you SO much!

I know the thread is old, but the problem is still relevant. It happened when I moved my project from one machine to another, in order to run the automation separate from my main development machine.

Woo! :D :D :D

Revision history for this message
keith Fischer (fischertech00) said :
#13

I connected a non retina monitor and set mirroring for grabbing png's. Both monitors are screen 0 . This worked well for both mac and pc for test runs using same png's.

Sent from my iPhone

> On Mar 21, 2017, at 5:14 PM, Noktyn <email address hidden> wrote:
>
> Your question #241355 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/241355
>
> Noktyn posted a new comment:
> @Barry:
>
> Thank you so much, this fixed the issue I was having. I had 2 machines
> running my java test scripts and one worked with sikuli and one didn't.
> I kept checking file paths and how I had my .JARs loaded into my project
> library, but it had to do with retina display -_-.
>
> I halved the pixel values of the .PNG image files it couldn't read and
> voila, sikuli started working again. Very odd, thank you SO much!
>
> I know the thread is old, but the problem is still relevant. It happened
> when I moved my project from one machine to another, in order to run the
> automation separate from my main development machine.
>
> Woo! :D :D :D
>
> --
> You received this question notification because you asked the question.