def setup(self, count=1, fn=None): self._count = count self._heights = [] self.blob_size = 100 if fn is None: self.process_fn = lambda r, g, b: (g - r).threshold(30).erode() else: self.process_fn = fn self._get_centroids = _get_centroids(count) # setup variables for i in range(count): stream = Stream(title="Height %s" % (i + 1), type=int) setattr(self, "height%s" % (i + 1), stream) self._heights.append(stream) self.image = Image(title="Tracked", fn=self._get_image) self.visualisation = DerivedImage(title="Visualisation") self.status = Property(title="Status", type=str) self.ui = ui(properties=[self.status, self.image, self.visualisation] + self._heights)
def setup (self): # setup variables self.image = Image(title = "Image", fn = self._get_image) self.ui = ui( properties = [self.image] )
def _parse_page(meme_id: int, page_url: str): response = requests.get(page_url, headers={'user-agent': 'vkhack-bot'}) parsed_page = BeautifulSoup(response.text, "html.parser") for meme_url in _extract_meme_urls(parsed_page): url = f'https:' + meme_url if not Image.exists(url=url): logger.info(f'Add image {url}') Image(meme=meme_id, url=url)
def setup(self, fn=None): # setup variables self.height = Stream(title="Height", type=int) self.status = Property(title="Status", type=str) self.image = Image(title="Tracked", fn=self._get_image) self.visualisation = DerivedImage(title="Visualisation") if fn is None: self.process_fn = lambda r, g, b: (g - r).threshold(30).erode() else: self.process_fn = fn self.blob_size = 100 self._get_centroids = _get_centroids(1) self.ui = ui(properties=[ self.status, self.height, self.image, self.visualisation ])
def test_set_name(self): image = Image() image.full_path = "/some/path/name is a string.jpg" image.size = 1234 image.modified = TestConstants.modified_test self.assertEqual(image.modified_time_str, TestConstants.modified_test_str) # Test that an image without captured date retains its name if we want to change only by captured date doc = image.name Folder.set_name(image, name_from_captured_date=True, name_from_modified_date=False, keep_manual_names=False) self.assertEqual(doc, image.name) # An image without captured date but with modified date changes name if we want to change by mod date Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=True, keep_manual_names=False) self.assertEqual(image.name, TestConstants.modified_test_str + '@' + doc) image.name = doc # If the image has a meaningful name, modified date is not prepended if we want to keep manual names Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=True, keep_manual_names=True) self.assertEqual(doc, image.name) # If image has no meaningful name, then modified time IS prepended also if we want to keep manual names image.name = doc = "IMG324342.jpg" Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=True, keep_manual_names=True) self.assertEqual(image.name, TestConstants.modified_test_str + '@' + doc) image.name = doc = "name is a string.jpg" # add now captured date image.captured = TestConstants.captured_test self.assertEqual(image.captured_str, TestConstants.captured_test_str) # if we have a captured date and want to change by it, the whole name is changed Folder.set_name(image, name_from_captured_date=True, name_from_modified_date=False, keep_manual_names=False) self.assertEqual(image.name, TestConstants.captured_test_str + '.' + image.type) # if we want to change by modified name, but we do have captured date, also then captured date is set image.name = doc Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=True, keep_manual_names=False) self.assertEqual(image.name, TestConstants.captured_test_str + '.' + image.type) # if we have some meaningful name, and want to keep it, the captured date is appended to it name, ext = os.path.splitext(doc) image.name = doc Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=False, keep_manual_names=True) self.assertEqual(image.name, name + ' ' + TestConstants.captured_test_str + ext) # if the name is not meaningful, replace it with the captured date even if not asked for image.name = doc = "IMG324342.jpg" name, ext = os.path.splitext(doc) Folder.set_name(image, name_from_captured_date=False, name_from_modified_date=False, keep_manual_names=True) self.assertEqual(image.name, TestConstants.captured_test_str + ext)