class ImageProvider (Machine): protocolFactory = None name = "Provide an image from a webcam" update_frequency = 1 def setup (self): # setup variables self.image = Image(title = "Tracked", fn = self._getImage) self.ui = ui( properties = [self.image] ) def _getImage (self): return self.protocol.image() def start (self): def monitor (): self.image.refresh() self._tick(monitor, self.update_frequency) def stop (self): self._stopTicks() def disconnect (self): self.stop() try: self.protocol.disconnect() except AttributeError: pass
class ImageProvider(Machine): protocolFactory = None name = "Provide an image from a webcam" update_frequency = 1 def setup(self): # setup variables self.image = Image(title="Tracked", fn=self._getImage) self.ui = ui(properties=[self.image]) def _getImage(self): return self.protocol.image() def start(self): def monitor(): self.image.refresh() self._tick(monitor, self.update_frequency) def stop(self): self._stopTicks() def disconnect(self): self.stop() try: self.protocol.disconnect() except AttributeError: pass
def factory(location, register): image = Image() image.filename = original.filename image.mimeType = original.mimeType def afterCopy(translate): image.data = original.data register(afterCopy) return 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): # setup variables self.image = Image(title = "Tracked", fn = self._getImage) self.ui = ui( properties = [self.image] )
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 load(self, filepath: str) -> bool: filepath = Path(filepath) if filepath.suffix == ".raw": data = Image.load(filepath) self.image_layer = ImageLayer(data) if filepath.suffix == ".msk": data = BitMask.load(filepath) self.overlay_layer = BitMaskLayer(data) self.draw()
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 _get_meme_long_desc(meme) -> dict: return { 'id': meme.id, 'url': meme.image, 'name': meme.name, 'about': meme.about, 'origin': meme.origin, 'tags': meme.type.split(',') if meme.type else [], 'images': list( map(lambda it: it.url, Image.select(lambda it: it.meme == meme.id))) }
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)
def set(self, object, value, _getattr=getattr, _setattr=setattr): if self.readonly: raise TypeError("Can't set values on read-only fields " "(name=%s, class=%s.%s)" % (self.__name__, object.__class__.__module__, object.__class__.__name__)) if IImage.providedBy(value): _setattr(object, self.__name__, value) elif IFileData.providedBy(value): data = _getattr(object, self.__name__, None) if not IImage.providedBy(data): data = Image() data.data = value.data data.mimeType = value.mimeType data.filename = value.filename _setattr(object, self.__name__, data) else: data = removeSecurityProxy(data) data.data = value.data data.mimeType = value.mimeType data.filename = value.filename _setattr(object, self.__name__, data) if self.scale and (self.maxWidth < data.width or self.maxHeight < data.height): data.scale(self.maxWidth, self.maxHeight) elif IFileDataClear.providedBy(value): data = _getattr(object, self.__name__, None) if IImage.providedBy(data): data.clear() else: _setattr(object, self.__name__, Image()) elif IFileDataNoValue.providedBy(value): pass else: self.set(object, FileData(value), _getattr, _setattr)