Python kivy.graphics.texture.Texture.create() Examples
The following are 30
code examples of kivy.graphics.texture.Texture.create().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
kivy.graphics.texture.Texture
, or try the search function
.
Example #1
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 7 votes |
def create_drawings(self): from kivy.graphics import Line, RenderContext # very first time, create a texture for the shader if not hasattr(SmoothLinePlot, '_texture'): tex = Texture.create(size=(1, 64), colorfmt='rgb') tex.add_reload_observer(SmoothLinePlot._smooth_reload_observer) SmoothLinePlot._texture = tex SmoothLinePlot._smooth_reload_observer(tex) self._grc = RenderContext( fs=SmoothLinePlot.SMOOTH_FS, use_parent_modelview=True, use_parent_projection=True) with self._grc: self._gcolor = Color(*self.color) self._gline = Line( points=[], cap='none', width=2., texture=SmoothLinePlot._texture) return [self._grc]
Example #2
Source File: SmartBinApp.py From SmartBin with MIT License | 7 votes |
def __init__(self, **kwargs): global cap, frame, frame_size # capture and render the first frame self.frame_size = frame_size frame = cap.read() image = cv2.flip(frame, 0) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = cv2.resize(image, frame_size) buf = image.tostring() self.image_texture = Texture.create(size=(image.shape[1], image.shape[0]), colorfmt='rgb') self.image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte') # coordinates of Trashy self.t_x = 0 self.t_y = 0 self.current_user = 'No user yet' self.tickcount = 0 self.labels = ["can", "bottle", "ken", "grace", "frank", "tim", "shelly"] self.users = ["ken", "grace", "frank", "tim", "shelly"] super(MainView, self).__init__(**kwargs) Clock.schedule_interval(self.tick, 0.06)
Example #3
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 6 votes |
def create_drawings(self): from kivy.graphics import Line, RenderContext from kivy.graphics.texture import Texture # very first time, create a texture for the shader if not hasattr(SmoothLinePlot, '_texture'): tex = Texture.create(size=(1, 64), colorfmt='rgb') tex.add_reload_observer(SmoothLinePlot._smooth_reload_observer) SmoothLinePlot._texture = tex SmoothLinePlot._smooth_reload_observer(tex) self._grc = RenderContext(fs=SmoothLinePlot.SMOOTH_FS, use_parent_modelview=True, use_parent_projection=True) with self._grc: self._gcolor = Color(*self.color) self._gline = Line(points=[], cap='none', width=2., texture=SmoothLinePlot._texture) return [self._grc]
Example #4
Source File: backend_kivy.py From garden.matplotlib with MIT License | 6 votes |
def draw_mathtext(self, gc, x, y, s, prop, angle): '''Draw the math text using matplotlib.mathtext. The position x,y is given in Kivy coordinates. ''' ftimage, depth = self.mathtext_parser.parse(s, self.dpi, prop) w = ftimage.get_width() h = ftimage.get_height() texture = Texture.create(size=(w, h)) if _mpl_ge_1_5: texture.blit_buffer(ftimage.as_rgba_str()[0][0], colorfmt='rgba', bufferfmt='ubyte') else: texture.blit_buffer(ftimage.as_rgba_str(), colorfmt='rgba', bufferfmt='ubyte') texture.flip_vertical() with self.widget.canvas: Rectangle(texture=texture, pos=(x, y), size=(w, h))
Example #5
Source File: camera_opencv.py From Tickeys-linux with MIT License | 6 votes |
def init_camera(self): # create the device self._device = hg.cvCreateCameraCapture(self._index) # Set preferred resolution cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_WIDTH, self.resolution[0]) cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_HEIGHT, self.resolution[1]) # and get frame to check if it's ok frame = hg.cvQueryFrame(self._device) # Just set the resolution to the frame we just got, but don't use # self.resolution for that as that would cause an infinite recursion # with self.init_camera (but slowly as we'd have to always get a # frame). self._resolution = (int(frame.width), int(frame.height)) #get fps self.fps = cv.GetCaptureProperty(self._device, cv.CV_CAP_PROP_FPS) if self.fps <= 0: self.fps = 1 / 30. if not self.stopped: self.start()
Example #6
Source File: camera_opencv.py From Tickeys-linux with MIT License | 6 votes |
def init_camera(self): # create the device self._device = hg.cvCreateCameraCapture(self._index) # Set preferred resolution cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_WIDTH, self.resolution[0]) cv.SetCaptureProperty(self._device, cv.CV_CAP_PROP_FRAME_HEIGHT, self.resolution[1]) # and get frame to check if it's ok frame = hg.cvQueryFrame(self._device) # Just set the resolution to the frame we just got, but don't use # self.resolution for that as that would cause an infinite recursion # with self.init_camera (but slowly as we'd have to always get a # frame). self._resolution = (int(frame.width), int(frame.height)) #get fps self.fps = cv.GetCaptureProperty(self._device, cv.CV_CAP_PROP_FPS) if self.fps <= 0: self.fps = 1 / 30. if not self.stopped: self.start()
Example #7
Source File: video_gi.py From Tickeys-linux with MIT License | 5 votes |
def _update_texture(self, sample): # texture will be updated with newest buffer/frame # read the data from the buffer memory mapinfo = data = None try: buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) # We cannot get the data out of mapinfo, using Gst 1.0.6 + Gi 3.8.0 # related bug report: # https://bugzilla.gnome.org/show_bug.cgi?id=678663 # ie: mapinfo.data is normally a char*, but here, we have an int # So right now, we use ctypes instead to read the mapinfo ourself. addr = mapinfo.__hash__() c_mapinfo = _MapInfo.from_address(addr) # now get the memory data = string_at(c_mapinfo.data, mapinfo.size) finally: if mapinfo is not None: buf.unmap(mapinfo) # upload the data to the GPU info = sample.get_caps().get_structure(0) size = info.get_value('width'), info.get_value('height') # texture is not allocated yet, create it first if not self._texture: self._texture = Texture.create(size=size, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') if self._texture: self._texture.blit_buffer(data, size=size, colorfmt='rgb')
Example #8
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def draw(self, *args): super(ContourPlot, self).draw(*args) data = self.data xdim, ydim = data.shape # Find the minimum and maximum z values zmax = data.max() zmin = data.min() rgb_scale_factor = 1.0 / (zmax - zmin) * 255 # Scale the z values into RGB data buf = np.array(data, dtype=float, copy=True) np.subtract(buf, zmin, out=buf) np.multiply(buf, rgb_scale_factor, out=buf) # Duplicate into 3 dimensions (RGB) and convert to byte array buf = np.asarray(buf, dtype=np.uint8) buf = np.expand_dims(buf, axis=2) buf = np.concatenate((buf, buf, buf), axis=2) buf = np.reshape(buf, (xdim, ydim, 3)) charbuf = bytearray(np.reshape(buf, (buf.size))) self._texture = Texture.create(size=(xdim, ydim), colorfmt='rgb') self._texture.blit_buffer(charbuf, colorfmt='rgb', bufferfmt='ubyte') image = self._image image.texture = self._texture params = self._params funcx = log10 if params['xlog'] else lambda x: x funcy = log10 if params['ylog'] else lambda x: x xmin = funcx(params['xmin']) ymin = funcy(params['ymin']) size = params['size'] ratiox = (size[2] - size[0]) / float(funcx(params['xmax']) - xmin) ratioy = (size[3] - size[1]) / float(funcy(params['ymax']) - ymin) bl = (funcx(self.xrange[0]) - xmin) * ratiox + size[0], (funcy(self.yrange[0]) - ymin) * ratioy + size[1] tr = (funcx(self.xrange[1]) - xmin) * ratiox + size[0], (funcy(self.yrange[1]) - ymin) * ratioy + size[1] image.pos = bl w = tr[0] - bl[0] h = tr[1] - bl[1] image.size = (w, h)
Example #9
Source File: video_pygst.py From Tickeys-linux with MIT License | 5 votes |
def _update_texture(self, buf): # texture will be updated with newest buffer/frame size = None caps = buf.get_caps() _s = caps.get_structure(0) size = _s['width'], _s['height'] if not self._texture: # texture is not allocated yet, so create it first self._texture = Texture.create(size=size, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') # upload texture data to GPU if self._texture: self._texture.blit_buffer(buf.data, size=size, colorfmt='rgb')
Example #10
Source File: textinput.py From Tickeys-linux with MIT License | 5 votes |
def _get_line_options(self): # Get or create line options, to be used for Label creation if self._line_options is None: self._line_options = kw = { 'font_size': self.font_size, 'font_name': self.font_name, 'anchor_x': 'left', 'anchor_y': 'top', 'padding_x': 0, 'padding_y': 0, 'padding': (0, 0)} self._label_cached = Label(**kw) return self._line_options
Example #11
Source File: camera_gi.py From Tickeys-linux with MIT License | 5 votes |
def _update(self, dt): sample, self._sample = self._sample, None if sample is None: return if self._texture is None and self._texturesize is not None: self._texture = Texture.create( size=self._texturesize, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') # decode sample # read the data from the buffer memory try: buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) # We cannot get the data out of mapinfo, using Gst 1.0.6 + Gi 3.8.0 # related bug report: # https://bugzilla.gnome.org/show_bug.cgi?id=6t8663 # ie: mapinfo.data is normally a char*, but here, we have an int # So right now, we use ctypes instead to read the mapinfo ourself. addr = mapinfo.__hash__() c_mapinfo = _MapInfo.from_address(addr) # now get the memory self._buffer = string_at(c_mapinfo.data, mapinfo.size) self._copy_to_gpu() finally: if mapinfo is not None: buf.unmap(mapinfo)
Example #12
Source File: camera_pygst.py From Tickeys-linux with MIT License | 5 votes |
def _update(self, dt): if self._buffer is None: return if self._texture is None and self._texturesize is not None: self._texture = Texture.create( size=self._texturesize, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') self._copy_to_gpu()
Example #13
Source File: camera_videocapture.py From Tickeys-linux with MIT License | 5 votes |
def init_camera(self): # create the device self._device = Device(devnum=self._index, showVideoWindow=0) # set resolution try: self._device.setResolution(self.resolution[0], self.resolution[1]) except: raise Exception('VideoCapture: Resolution not supported') self.fps = 1 / 30.
Example #14
Source File: camera_videocapture.py From Tickeys-linux with MIT License | 5 votes |
def _update(self, dt): data, camera_width, camera_height = self._device.getBuffer() if self._texture is None: # first update, resize if necessary self.size = camera_width, camera_height # and create texture from kivy.graphics.texture import Texture self._texture = Texture.create(size=self.size, colorfmt='rgb') self.dispatch('on_load') # update buffer self._buffer = data self._copy_to_gpu()
Example #15
Source File: __init__.py From Tickeys-linux with MIT License | 5 votes |
def refresh(self): '''Force re-rendering of the text ''' self.resolve_font_name() # first pass, calculating width/height sz = self.render() self._size_texture = sz self._size = (sz[0], sz[1]) # if no text are rendered, return nothing. width, height = self._size if width <= 1 or height <= 1: self.texture = self.texture_1px return # create a delayed texture texture = self.texture if texture is None or \ width != texture.width or \ height != texture.height: texture = Texture.create(size=(width, height), mipmap=self.options['mipmap'], callback=self._texture_fill) texture.flip_vertical() texture.add_reload_observer(self._texture_refresh) self.texture = texture else: texture.ask_update(self._texture_fill)
Example #16
Source File: __init__.py From Tickeys-linux with MIT License | 5 votes |
def populate(self): self._textures = [] fname = self.filename if __debug__: Logger.trace('Image: %r, populate to textures (%d)' % (fname, len(self._data))) for count in range(len(self._data)): # first, check if a texture with the same name already exist in the # cache chr = type(fname) uid = chr(u'%s|%d|%d') % (fname, self._mipmap, count) texture = Cache.get('kv.texture', uid) # if not create it and append to the cache if texture is None: imagedata = self._data[count] source = '{}{}|'.format( 'zip|' if fname.endswith('.zip') else '', self._nocache) imagedata.source = chr(source) + uid texture = Texture.create_from_data( imagedata, mipmap=self._mipmap) if not self._nocache: Cache.append('kv.texture', uid, texture) if imagedata.flip_vertical: texture.flip_vertical() # set as our current texture self._textures.append(texture) # release data if ask if not self.keep_data: self._data[count].release_data()
Example #17
Source File: video_gstplayer.py From Tickeys-linux with MIT License | 5 votes |
def _update_texture(self, buf): width, height, data = buf # texture is not allocated yet, create it first if not self._texture: self._texture = Texture.create(size=(width, height), colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') if self._texture: self._texture.blit_buffer( data, size=(width, height), colorfmt='rgb')
Example #18
Source File: video_gi.py From Tickeys-linux with MIT License | 5 votes |
def _update_texture(self, sample): # texture will be updated with newest buffer/frame # read the data from the buffer memory mapinfo = data = None try: buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) # We cannot get the data out of mapinfo, using Gst 1.0.6 + Gi 3.8.0 # related bug report: # https://bugzilla.gnome.org/show_bug.cgi?id=678663 # ie: mapinfo.data is normally a char*, but here, we have an int # So right now, we use ctypes instead to read the mapinfo ourself. addr = mapinfo.__hash__() c_mapinfo = _MapInfo.from_address(addr) # now get the memory data = string_at(c_mapinfo.data, mapinfo.size) finally: if mapinfo is not None: buf.unmap(mapinfo) # upload the data to the GPU info = sample.get_caps().get_structure(0) size = info.get_value('width'), info.get_value('height') # texture is not allocated yet, create it first if not self._texture: self._texture = Texture.create(size=size, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') if self._texture: self._texture.blit_buffer(data, size=size, colorfmt='rgb')
Example #19
Source File: video_pygst.py From Tickeys-linux with MIT License | 5 votes |
def _update_texture(self, buf): # texture will be updated with newest buffer/frame size = None caps = buf.get_caps() _s = caps.get_structure(0) size = _s['width'], _s['height'] if not self._texture: # texture is not allocated yet, so create it first self._texture = Texture.create(size=size, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') # upload texture data to GPU if self._texture: self._texture.blit_buffer(buf.data, size=size, colorfmt='rgb')
Example #20
Source File: image_viewer.py From deepdiy with MIT License | 5 votes |
def img2texture(self,*arg): self.h,self.w=self.img.shape[:2] self.texture = Texture.create(size=(self.w, self.h), colorfmt='rgb') self.texture.blit_buffer(self.img.tostring(), colorfmt='bgr', bufferfmt='ubyte') self.texture.flip_vertical() w,h=self.size if w*h==0: self.w_out,self.h_out=self.size elif w/h>self.w/self.h: self.h_out=h self.w_out=h*(self.w/self.h) else: self.h_out=w*(self.h/self.w) self.w_out=w
Example #21
Source File: video_viewer.py From deepdiy with MIT License | 5 votes |
def render(self,*args): bug = self.nomalize_to_8_bit_BGR(self.frame) buf = bug.tostring() texture1 = Texture.create(size=(self.frame.shape[1], self.frame.shape[0]), colorfmt='bgr') texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte') self.ids.preview.texture = texture1 self.ids.play_progress.value=self.frame_idx+1
Example #22
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def blittex(self, *args): rgbpixels = [(x, 0, y, 255) for x in range(256) for y in range(256)] pixels = b''.join((b''.join(map(chr, pix)) for pix in rgbpixels)) self.texture = Texture.create(size=(256, 256)) self.texture.blit_buffer(pixels, colorfmt='rgba', bufferfmt='ubyte')
Example #23
Source File: __init__.py From RaceCapture_App with GNU General Public License v3.0 | 5 votes |
def get_drawings(self): if isinstance(self._drawings, (tuple, list)): return self._drawings return [] # method called once to create all the canvas instructions needed for the # plot
Example #24
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 5 votes |
def create_drawings(self): '''called once to create all the canvas instructions needed for the plot ''' pass
Example #25
Source File: camera_gi.py From Tickeys-linux with MIT License | 5 votes |
def _update(self, dt): sample, self._sample = self._sample, None if sample is None: return if self._texture is None and self._texturesize is not None: self._texture = Texture.create( size=self._texturesize, colorfmt='rgb') self._texture.flip_vertical() self.dispatch('on_load') # decode sample # read the data from the buffer memory try: buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) # We cannot get the data out of mapinfo, using Gst 1.0.6 + Gi 3.8.0 # related bug report: # https://bugzilla.gnome.org/show_bug.cgi?id=6t8663 # ie: mapinfo.data is normally a char*, but here, we have an int # So right now, we use ctypes instead to read the mapinfo ourself. addr = mapinfo.__hash__() c_mapinfo = _MapInfo.from_address(addr) # now get the memory self._buffer = string_at(c_mapinfo.data, mapinfo.size) self._copy_to_gpu() finally: if mapinfo is not None: buf.unmap(mapinfo)
Example #26
Source File: __init__.py From kivy-smoothie-host with GNU General Public License v3.0 | 5 votes |
def draw(self, *args): super(ContourPlot, self).draw(*args) data = self.data xdim, ydim = data.shape # Find the minimum and maximum z values zmax = data.max() zmin = data.min() rgb_scale_factor = 1.0 / (zmax - zmin) * 255 # Scale the z values into RGB data buf = np.array(data, dtype=float, copy=True) np.subtract(buf, zmin, out=buf) np.multiply(buf, rgb_scale_factor, out=buf) # Duplicate into 3 dimensions (RGB) and convert to byte array buf = np.asarray(buf, dtype=np.uint8) buf = np.expand_dims(buf, axis=2) buf = np.concatenate((buf, buf, buf), axis=2) buf = np.reshape(buf, (xdim, ydim, 3)) charbuf = bytearray(np.reshape(buf, (buf.size))) self._texture = Texture.create(size=(xdim, ydim), colorfmt='rgb') self._texture.blit_buffer(charbuf, colorfmt='rgb', bufferfmt='ubyte') image = self._image image.texture = self._texture x_px = self.x_px() y_px = self.y_px() bl = x_px(self.xrange[0]), y_px(self.yrange[0]) tr = x_px(self.xrange[1]), y_px(self.yrange[1]) image.pos = bl w = tr[0] - bl[0] h = tr[1] - bl[1] image.size = (w, h)
Example #27
Source File: backend_kivyagg.py From garden.matplotlib with MIT License | 5 votes |
def draw(self): ''' Draw the figure using the agg renderer ''' self.canvas.clear() FigureCanvasAgg.draw(self) if self.blitbox is None: l, b, w, h = self.figure.bbox.bounds w, h = int(w), int(h) buf_rgba = self.get_renderer().buffer_rgba() else: bbox = self.blitbox l, b, r, t = bbox.extents w = int(r) - int(l) h = int(t) - int(b) t = int(b) + h reg = self.copy_from_bbox(bbox) buf_rgba = reg.to_string() texture = Texture.create(size=(w, h)) texture.flip_vertical() color = self.figure.get_facecolor() with self.canvas: Color(*color) Rectangle(pos=self.pos, size=(w, h)) Color(1.0, 1.0, 1.0, 1.0) self.img_rect = Rectangle(texture=texture, pos=self.pos, size=(w, h)) texture.blit_buffer(bytes(buf_rgba), colorfmt='rgba', bufferfmt='ubyte') self.img_texture = texture
Example #28
Source File: backend_kivyagg.py From garden.matplotlib with MIT License | 5 votes |
def _print_image(self, filename, *args, **kwargs): '''Write out format png. The image is saved with the filename given. ''' l, b, w, h = self.figure.bbox.bounds img = None if self.img_texture is None: texture = Texture.create(size=(w, h)) texture.blit_buffer(bytes(self.get_renderer().buffer_rgba()), colorfmt='rgba', bufferfmt='ubyte') texture.flip_vertical() img = Image(texture) else: img = Image(self.img_texture) img.save(filename)
Example #29
Source File: backend_kivy.py From garden.matplotlib with MIT License | 5 votes |
def print_png(self, filename, *args, **kwargs): '''Call the widget function to make a png of the widget. ''' fig = FigureCanvasAgg(self.figure) FigureCanvasAgg.draw(fig) l, b, w, h = self.figure.bbox.bounds texture = Texture.create(size=(w, h)) texture.blit_buffer(bytes(fig.get_renderer().buffer_rgba()), colorfmt='rgba', bufferfmt='ubyte') texture.flip_vertical() img = Image(texture) img.save(filename)
Example #30
Source File: kivy_cv1.py From OpenCV-Python-Tutorial with MIT License | 5 votes |
def update(self, dt): ret, frame = self.capture.read() if ret: # convert it to texture buf1 = cv2.flip(frame, 0) buf = buf1.tostring() image_texture = Texture.create( size=(frame.shape[1], frame.shape[0]), colorfmt='bgr') image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte') # display image from the texture self.texture = image_texture