Пример #1
0
 def __is_initial_screen__(self, *args, **kwargs):
     original = cv2.imread(os.path.join(self.assets, "home_page_steam.png"))
     against = self.get_img_from_screen_shot()
     # convert the images to grayscale
     original = mask_image([127], [255], cv2.cvtColor(original, cv2.COLOR_BGR2GRAY), True)
     against = mask_image([127], [255], cv2.cvtColor(against, cv2.COLOR_BGR2GRAY), True)
     (score, diff) = compare_ssim(original, against, full=True)
     if score > .9:
         return True
     return False
Пример #2
0
    def test_initial_pass_through_compare(self):
        original = cv2.imread(
            os.path.join(self.provider.assets, "start_screen.png"))
        against = self.provider.get_img_from_screen_shot()
        wrong = cv2.imread(os.path.join(self.provider.assets, "battle.png"))

        # convert the images to grayscale
        original = mask_image([127], [255],
                              cv2.cvtColor(original, cv2.COLOR_BGR2GRAY), True)
        against = mask_image([127], [255],
                             cv2.cvtColor(against, cv2.COLOR_BGR2GRAY), True)
        wrong = mask_image([127], [255],
                           cv2.cvtColor(wrong, cv2.COLOR_BGR2GRAY), True)
        # initialize the figure
        (score, diff) = compare_ssim(original, against, full=True)
        diff = (diff * 255).astype("uint8")
        self.assertTrue(
            score > .90,
            'If this is less then .90 the initial compare of the app will fail'
        )
        (score, nothing) = compare_ssim(original, wrong, full=True)
        self.assertTrue(score < .90)
        if self.__debug_pictures__:
            # threshold the difference image, followed by finding contours to
            # obtain the regions of the two input images that differ
            thresh = cv2.threshold(diff, 0, 255,
                                   cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
            cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                    cv2.CHAIN_APPROX_SIMPLE)
            cnts = cnts[0]
            # loop over the contours
            for c in cnts:
                # compute the bounding box of the contour and then draw the
                # bounding box on both input images to represent where the two
                # images differ
                (x, y, w, h) = cv2.boundingRect(c)
                cv2.rectangle(original, (x, y), (x + w, y + h), (0, 0, 255), 2)
                cv2.rectangle(against, (x, y), (x + w, y + h), (0, 0, 255), 2)
            # show the output images
            diffs = ("Original",
                     original), ("Modified",
                                 against), ("Diff", diff), ("Thresh", thresh)
            images = ("Original", original), ("Against", against), ("Wrong",
                                                                    wrong)
            self.setup_compare_images(diffs)
            self.setup_compare_images(images)
Пример #3
0
 def get_current_page(self, img):
     img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
     area = crop_image(img, **self.predefined.page_area)
     area = mask_image([254], [255], area)
     height, width = area.shape
     current_page = 0
     for x in range(4):
         box = crop_image(area, (x * width / 4), 0, ((x + 1) * width / 4),
                          height)
         if cv2.countNonZero(box) > 0:
             current_page = x
             break
     return current_page + 1
Пример #4
0
 def prep_for_white_circles(self):
     lower, upper = ([215, 215, 215], [255, 255, 255])
     self.white_query = mask_image(lower,
                                   upper,
                                   self.query,
                                   apply_mask=True)