how to find same text on different letters and color picture

Asked by srijith

hello guys

i want to know about text on picture it is possible to find same text but in different letter also color on Sikuli IDE

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
RaiMan (raimund-hocke) said :
#1

import shutil
img = capture(SCREEN)
shutil.move(img, r"G:\sikuli\imgname.png")

Revision history for this message
srijith (srijithbhandary) said :
#2

thanks, But I will be taking screenshots inside a while loop and saving in same location...so I dnt want to give absolute fielname.
Is there a way I can give filename like screenshot1.png , screenshot2.png.......... ?

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

LOL, RaiMan's tips are not absolute ;-)
they might be adapted according to your needs ;-)

import shutil
n = 1
while True:
    img = capture(SCREEN)
    shutil.move(img, "G:\\sikuli\\screenshot%d.png"%n)
    n = n+1

Revision history for this message
srijith (srijithbhandary) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Nurbergen (87073525266-w) said :
#5

How to write this code on Java and how to chenge SCREEN to REGION
thenks

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

@Nurbergen
what version of Sikuli?
what system?

Revision history for this message
Nurbergen (87073525266-w) said :
#7

NetBeans IDE 8.0.2 sikuli X 1.0 and i wold know Why when i am want to
import shutil
img = capture(SCREEN)
shutil.move(img, r"G:\sikuli\imgname.png")
chenge Screen to Region it okey but when i am want to use that picture from the region it gives ERROR

that is why i am trying to write know on java but it is to hard to me

it will be better if you will give me good code

i am try ing sreen shot region after use that picture

Revision history for this message
Nurbergen (87073525266-w) said :
#8

system is Widows 7

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

@Nurbergen
does it mean X 1.0 as Sikuli X 1.0rc3 ???
from here https://launchpad.net/sikuli/sikulix/x1.0-rc3
????

--- want to use that picture from the region it gives ERROR
what error exactly

Are you currently using the scripting level (IDE, Python language).
If yes, no need to go down to Java for that.

Be aware:
The folder you are trying to move the image (G:\sikuli in the above case MUST exist)

Revision history for this message
Nurbergen (87073525266-w) said :
#10

yeah i chenged for myself it taking picture yeah it's in C:\sikuli\imgname.png
 folder but when i am trying to use like this
import shutil
img = capture(REGION) // region 1
shutil.move(img, r"G:\sikuli\imgname.png")

if region2.inside().exists(Pattern("G:\sikuli\imgname.png"))
   click (picture)

i hope you will undestand

Revision history for this message
Nurbergen (87073525266-w) said :
#11

info] Windows utilities loaded.

[error] Can't transfer: sun.awt.datatransfer.ClipboardTransferable@11d75b9

[error] Can't transfer: sun.awt.datatransfer.TransferableProxy@831c19

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

not consistent:
taking picture yeah it's in C:\sikuli\imgname.png

but here
shutil.move(img, r"G:\sikuli\imgname.png") # it is G:

and here
if region2.inside().exists(Pattern("G:\sikuli\imgname.png")) # it is again G: and notC:

this would be correct and robust
import os
import shutil
dir = r"C:\sikuli"
img = capture(REGION) // region 1
imagename = os.path.join(dir, "imgname.png")

shutil.move(img, imagename)

if region2.exists(imagename):
   click (picture)

Revision history for this message
Nurbergen (87073525266-w) said :
#13

import os
import shutil
dir = r"C:\" \\ my piture here
img = capture(Region(594,51,24,21)) \\ it take piture
imagename = os.path.join(dir, "imgname.png")

shutil.move(img, imagename) \\ this movet to C:\

if Region(560,12,982,845).exists(imagename):
   click (imagename) // i wanto click for this picture

[error] Stopped
[error] An error occurs at line 3
[error] Error message: SyntaxError: ('mismatched character \'\\n\' expecting \'"\'', ('C:\\Users\\41B5~1\\AppData\\Local\\Temp\\sikuli-tmp8866248239526860988.py', 3, 12, 'dir = r"C:\\"\n'))

Revision history for this message
Nurbergen (87073525266-w) said :
#14

i think this giving mistake becouse
if Region(560,12,982,845).exists(imagename):
   click (imagename) // i wanto click for this picture

it does know picture actually it shold wait for picture

sreen shot will take picture after i can use becouse picture will be done it this moment

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

a raw string r"" cannot end with a backslash.

so if you really want to store the image at c:\ and not in some folder:
dir = "c:\\"

… but I really recommend to use a folder to not spam your c: root folder.

so create folder
c:\sikuli\images

and use
dir = r"c:\sikuli\images"

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

this is a shortcut with wait:

click(wait(imagename, timeout)) # replace timeout with a suitable value

will crash with a findfailed, if imagename does not appear within timeout seconds

Revision history for this message
Nurbergen (87073525266-w) said :
#17

my dear friend thanks a lot now it works
can you give me some useful thing some links for improve myself to write code in sikuli
also could give to me your mail to write if i had trouble

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

you find everything you need at
http://sikulix.com

… and you might contact me directly at any time.

to learn more:
- look for examples in the net
- work through some Python tutorial
- go through the faqs section
- read through the docs (http://sikulix-2014.readthedocs.org/en/latest/index.html)

Revision history for this message
Nurbergen (87073525266-w) said :
#19

okey thanks

Revision history for this message
Nurbergen (87073525266-w) said :
#20

i have also one question how to compare two different picture with text
let's assume we have one picture with text in one region
can we find another picture with same text but other things is different
it is posible if it is posible can you show how to do it

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

@Nurbergen
please start your own question with new things you want to know.

Revision history for this message
Nurbergen (87073525266-w) said :
#22

i want to know about picture text it is possible to find same text but in different letter also color