Example #1
0
 def wait_for_match(self, images, similar_degree=0.98, timeout=300):
     """
     Compare VM screenshot with given images, if any image in the list
     matched, then return the image index, or return -1.
     """
     end_time = time.time() + timeout
     image_matched = False
     cropped_image = os.path.join(data_dir.get_tmp_dir(), "croped.ppm")
     while time.time() < end_time:
         vm_screenshot = self.get_screenshot()
         ppm_utils.image_crop_save(vm_screenshot, vm_screenshot)
         img_index = 0
         for image in images:
             logging.debug("Compare vm screenshot with image %s", image)
             ppm_utils.image_crop_save(image, cropped_image)
             h_degree = ppm_utils.image_histogram_compare(
                 cropped_image, vm_screenshot)
             if h_degree >= similar_degree:
                 logging.debug("Image %s matched", image)
                 image_matched = True
                 break
             img_index += 1
         if image_matched:
             break
         time.sleep(1)
     if os.path.exists(cropped_image):
         os.unlink(cropped_image)
     if os.path.exists(vm_screenshot):
         os.unlink(vm_screenshot)
     if image_matched:
         return img_index
     else:
         return -1
Example #2
0
 def wait_for_match(self, images, similar_degree=0.98, timeout=300):
     """
     Compare VM screenshot with given images, if any image in the list
     matched, then return the image index, or return -1.
     """
     end_time = time.time() + timeout
     image_matched = False
     cropped_image = os.path.join(data_dir.get_tmp_dir(), "croped.ppm")
     while time.time() < end_time:
         vm_screenshot = self.get_screenshot()
         ppm_utils.image_crop_save(vm_screenshot, vm_screenshot)
         img_index = 0
         for image in images:
             logging.debug("Compare vm screenshot with image %s", image)
             ppm_utils.image_crop_save(image, cropped_image)
             h_degree = ppm_utils.image_histogram_compare(cropped_image,
                                                          vm_screenshot)
             if h_degree >= similar_degree:
                 logging.debug("Image %s matched", image)
                 image_matched = True
                 break
             img_index += 1
         if image_matched:
             break
         time.sleep(1)
     if os.path.exists(cropped_image):
         os.unlink(cropped_image)
     if os.path.exists(vm_screenshot):
         os.unlink(vm_screenshot)
     if image_matched:
         return img_index
     else:
         return -1