Using Region.highlight() conflicts with Find() operations in that Region

Asked by aidma

(I think this is a bug, but maybe it's the intented behaviour, so I'll ask a question)

I have two functions as defined below:

>>> def f1(x, y, w , h):
... region = Region(x, y, w, h)
... image = capture(region)
... region.find(Pattern(image).similar(0.99))
...
>>> def f2(x, y, w, h):
... region = Region(x, y, w, h)
... image = capture(region)
... region.highlight() #Highlight the region to show where's being searched, should be harmless?
... try:
... region.find(Pattern(image).similar(0.99))
... except:
... raise
... finally:
... region.highlight() #turn off highlight even if there's a nasty failure
...

The function 'f1' always passes. The function 'f2' only sometimes passes. The following are some examples showing how 'f2' passes and fails:

CALL: f2(0, 0, 50, 50) | RESULT: fail
CALL: f2(0, 10, 50, 50) | RESULT: fail
CALL: f2(10, 0, 50, 50) | RESULT: fail
CALL: f2(10, 10, 50, 50) | RESULT: pass

The problem seems to be that the highlight overlays the Region when the Region borders the screen. Personally I think that this is incorrect behaviour.

I understand that Region.highlight() may affect Find() operations *in general*, but I do not think that it should affect Find() operations within the Region. It makes more sense for Region.highlight() to always be externally bounding, even if that means part of the highlight being offscreen.

The only problem I can see with my proposed functionality is that using SCREEN.highlight() would display nothing. (though, I think it's more important for Region.highlight() to behave consistently)

What do you think: Bug? Or is this how things are supposed to work?

NOTE: 'f2' never works when used in the Sikulix-IDE, as the Sikulix-IDE transposes the highlighted region

Question information

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

the current implemetation of the highlight() feature does not allow, to find something inside the highlighted region (a snapshot of the region is shown in an overlay with some dimming).

So you might use highlight(1) before the find and after that, but not at the same time.

I have the complete visual annotation stuff on the list for version 2 (former extension Guide).
Hence it is a bug, but "only" a request bug ;-)

BTW: what do you mean by:
as the Sikulix-IDE transposes the highlighted region????
highlight should work the same in all situations.

Revision history for this message
aidma (aidan-mahler13) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
aidma (aidan-mahler13) said :
#3

Oops, I meant translate, not transpose.

When I was using a Windows 7 computer with multi-monitor setup Region.highlight() would shift the highlighted region downwards and to the right. (so the overlay was drawn a few pixels off center). It would also happen to the entire screen when clicking 'Take Screenshot' from wihin the IDE.

Now I'm using a Windows 8 computer with a single monitor and the shift is gone...

Maybe somehow the multiple monitors were causing the issue? I'll be able to investigate more on Monday.

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

there where still multi monitor issues in version 1.1.0, but they should be fixed in the versions after mid April.

version 1.0.1 and earlier versions had problems in this area anyway.

thanks for feedback and testing.