Exemple #1
0
    def crop_avatar(self, crop_size=400):
        # Crop the recently uploaded avatar
        if not os.path.exists(self.avatar.path):
            raise Exception('Missing avatar file :%s' % self.avatar.file)

        # Do the crop
        crop_image(self.avatar.file, self.avatar.path, crop_size, 'png')
Exemple #2
0
    def crop_avatar(self, crop_size=400):
        # Crop the recently uploaded avatar
        if not os.path.exists(self.avatar.path):
            raise Exception("Missing avatar file :%s" % self.avatar.file)

        # Do the crop
        crop_image(self.avatar.file, self.avatar.path, crop_size, "png")
Exemple #3
0
    def __call__(self, *args, **kwargs):
        self.opening_page()
        while True:
            self.driver.save_screenshot(r'data/images/a.png')
            helpers.crop_image('data/images/a.png', (870, 600, 1050, 650))
            self.filling_form()
            self.buffer()
            self.handling_alert()

            if self.alert is not None:
                return self.alert
Exemple #4
0
def check_last_page(webview_region, roi_region):
    screen_webview = helpers.read_img('screen.png', webview_region)
    screen_roi = helpers.crop_image(screen_webview, roi_region)

    next_screen_webview = helpers.read_img('next_screen.png', webview_region)
    next_screen_roi = helpers.crop_image(next_screen_webview, roi_region)

    result = cv2.matchTemplate(screen_roi, next_screen_roi,
                               cv2.TM_CCOEFF_NORMED)
    _, prob, _, _ = cv2.minMaxLoc(result)

    return prob
def data_augmentation(IMAGES_DIR, GT_DIR, AUG_IMAGES_DIR, AUG_GT_DIR):
    image_names = os.listdir(IMAGES_DIR)

    for i, image_name in enumerate(image_names):
        image = misc.imread(IMAGES_DIR + image_name)
        gt_image = misc.imread(GT_DIR + image_name)

        # First, saving the original image into the new folder (after rescaling to the new image size)
        misc.imsave(AUG_IMAGES_DIR + image_name,
                    resize_image(image, NEW_IMAGE_SIZE))
        misc.imsave(AUG_GT_DIR + image_name,
                    resize_image(gt_image, NEW_IMAGE_SIZE))

        # Generating 4 cropped images from the original one
        for y in range(2):
            y_offset = y * (IMAGE_SIZE - NEW_IMAGE_SIZE)

            for x in range(2):
                x_offset = x * (IMAGE_SIZE - NEW_IMAGE_SIZE)

                cropped_image = crop_image(image, NEW_IMAGE_SIZE, y_offset,
                                           x_offset)
                gt_cropped_image = crop_image(gt_image, NEW_IMAGE_SIZE,
                                              y_offset, x_offset)

                # Keep same name convention, e.g. for first image, the names will be
                # satImage_101, satImage_201, satImage_301 and satImage_401
                new_image_name = "satImage_{:03d}.png".format(y * 200 +
                                                              (x + 1) * 100 +
                                                              (i + 1))

                misc.imsave(AUG_IMAGES_DIR + new_image_name, cropped_image)
                misc.imsave(AUG_GT_DIR + new_image_name, gt_cropped_image)

        # Generating 4 rotated images from the original one
        for j, angle in enumerate(ANGLES):

            # Randomly add a small variation to the defined angle: angle' = angle +/- 5 degrees
            angle += 5 * (random.random() - 0.5)

            rotated_image = rotate_crop_image(image, angle, NEW_IMAGE_SIZE)
            gt_rotated_image = rotate_crop_image(gt_image, angle,
                                                 NEW_IMAGE_SIZE)

            new_image_name = "satImage_{:03d}.png".format(500 + j * 100 +
                                                          (i + 1))

            misc.imsave(AUG_IMAGES_DIR + new_image_name, rotated_image)
            misc.imsave(AUG_GT_DIR + new_image_name, gt_rotated_image)
Exemple #6
0
def find_all_template_locations(str_template,
                                scale,
                                webview_region,
                                roi_region=None):

    screen = helpers.read_img(region=webview_region)
    if roi_region is not None:
        screen = helpers.crop_image(screen, roi_region)

    template = cv2.imread(f'img/{str_template}.png')

    template_resized = cv2.resize(template, None, fx=scale, fy=scale)
    height, width, _ = template_resized.shape

    result = cv2.matchTemplate(screen, template_resized, cv2.TM_CCOEFF_NORMED)
    loc = np.where(result >= 0.8)
    logger.debug(result)
    coords = []
    for pt in zip(*loc[::-1]):
        coords.append([int(pt[0] + width / 2), int(pt[1] + height / 2)])

    data = {
        'coords': coords,
    }
    return data
Exemple #7
0
  def build_crop(self, size=400):
    '''
    For images, build crop
    '''

    # Create new media
    media = PostMedia.objects.create(post=self.post, type='image crop', parent=self, width=size, height=size, size=0)

    # Crop image
    crop_image(self.path, media.path, size)

    # Pillow does not provide file size :(
    media.size = os.stat(media.path).st_size
    media.save()

    return media
Exemple #8
0
def get_webview_region(*_):
    """ Stand alone function """
    screen = helpers.read_img('screen.png')

    # function: threshold green
    threshold_green = lambda screen: cv2.inRange(screen, np.array(
        [[0, 220, 0]]), np.array([40, 255, 40]))

    thresholded = threshold_green(screen)

    # get all pixels that are green
    green_mask = thresholded > 0
    green_coords = np.ix_(green_mask.any(1), green_mask.any(0))
    x_coords = np.squeeze(green_coords[1])
    y_coords = np.squeeze(green_coords[0])

    border_thickness = 4
    xmin = int(x_coords[0] + border_thickness)
    xmax = int(x_coords[-1] - border_thickness)
    ymin = int(y_coords[0] + border_thickness)
    ymax = int(y_coords[-1] - border_thickness)

    if DEBUG:
        cropped = helpers.crop_image(screen, [xmin, xmax, ymin, ymax])
        cv2.imwrite('./temp/webview.png', cropped)

    return [xmin, xmax, ymin, ymax]
Exemple #9
0
    def build_crop(self, size=400):
        '''
    For images, build crop
    '''

        # Create new media
        media = PostMedia.objects.create(post=self.post,
                                         type='image crop',
                                         parent=self,
                                         width=size,
                                         height=size,
                                         size=0)

        # Crop image
        crop_image(self.path, media.path, size)

        # Pillow does not provide file size :(
        media.size = os.stat(media.path).st_size
        media.save()

        return media
	def get(self):
		url = self.request.get("url")
		imgurl = self.request.get("imgurl")
		if imgurl != "False":
			item = models.Item.get_by_key_name(url)
			request = urlfetch.fetch(url=imgurl, method=urlfetch.GET)
			image = helpers.crop_image(request.content, 200)
			if image:
				if item:
					item.img = image
					item.has_img = True
					item.img_scraped = True
					item.put()
			self.response.headers['Content-Type'] = 'image/jpeg'
			self.response.out.write(image)