← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #269311]: compare directory of pictures to screen with loop

 

Question #269311 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/269311

    Status: Open => Answered

RaiMan proposed the following answer:
ok, this should do it (but not tested of course;-)

# collect the image files (import os not needed in Sikuli IDE)
dir = "D:\\stockage\\brush\\new\\original\\images\\new\\"
images = [] # to store the filenames
for e in os.listdir(dir): # this starts the loop
    if not e.endswith(".png"): continue
    images.append(os.path.join(dir, e)) # collect

# see the list
print "*** images in folder"
for e in images:
    print e

# walk through the list and compare with all images further down
imagesToDelete = [] # to store images we want to delete
for i in range(len(images)-1):
  if not images[i]: continue # already deleted
  f = Finder(images[i]) # create the Finder
  for k in range(i+1, len(images)): # compare all images in the rest of the list
    f.find(Pattern(images[k]).similar(0.9)) # to avoid false positives
    if not f.hasNext(): continue # not equal, next image
    # the compared image is equal
    imagesToDelete.append(images[k]) # store as to be deleted
    images[k] = None # take away from file list

# see the list of doubles
print "*** images to be deleted"
for e in imagesToDelete:
    print e
  
exit() # leave here, until the compare works

# delete the double images
for img in imagesToDelete:
  os.remove(img)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.