Beispiel #1
0
 def fbo_create(self, size, tex=None):
     if tex is None:
         tex = Texture.create(size=size, colorfmt='rgba', bufferfmt='ubyte')
         tex.mag_filter = 'nearest'
         tex.min_filter = 'nearest'
     if self.fbo is None:
         self.fbo = Fbo(size=size, texture=tex)
         self.fbo.texture.mag_filter = 'nearest'
         self.fbo.texture.min_filter = 'nearest'
     else:
         self.fbo = Fbo(size=size, texture=tex)
         self.fbo.texture.mag_filter = 'nearest'
         self.fbo.texture.min_filter = 'nearest'
     tool_tex = Texture.create(size=size, colorfmt='rgba', bufferfmt='ubyte')
     tool_tex.mag_filter = 'nearest'
     tool_tex.min_filter = 'nearest'
     if self.tool_fbo is None:
         self.tool_fbo = Fbo(size=size, texture=tool_tex)
         self.tool_fbo.texture.mag_filter = 'nearest'
         self.tool_fbo.texture.min_filter = 'nearest'
     else:
         self.tool_fbo = Fbo(size=size, texture=tool_tex)
         self.tool_fbo.texture.mag_filter = 'nearest'
         self.tool_fbo.texture.min_filter = 'nearest'
     return self.fbo
Beispiel #2
0
    def Start(self):
        if self.img.have_next and self.img2.have_next:
            self.differs = self.next_differs
            #print 'Start working'
            im = self.img.next[0]
            self.img.pil_image = im
            self.img.current_im = im.tostring()
            texture = Texture.create(size=im.size)
            texture.blit_buffer(im.tostring(), colorfmt='rgba', bufferfmt='ubyte')
            texture.flip_vertical()
            self.img.texture = texture
            self.img.image = im

            im = self.img2.next[0]
            self.img2.pil_image = im
            self.img2.current_im = im.tostring()
            texture = Texture.create(size=im.size)
            texture.blit_buffer(im.tostring(), colorfmt='rgba', bufferfmt='ubyte')
            texture.flip_vertical()
            self.img2.texture = texture
            self.img2.image = im

            self.img.thisf = self.e.nextf
            self.begin_next_img()
            self.entropy_label.text = 'Entropy:  %.1f' % (self.e.estimate_entropy())
        else:
            #print 'Start pending'
            Clock.schedule_once(lambda dt: self.Start(), 0.25)
            return
        self.angle1 = SystemRandom().random()*60 - 30
        self.angle2 = SystemRandom().random()*60 - 30
        self.anim_in()
        self.left_button.disabled = False
        self.right_button.disabled = False
Beispiel #3
0
 def make_textures(self):
     xnum = self.xnum
     ynum = self.ynum
     self.k_intensity_texture = Texture.create((xnum,ynum))
     self.k_phase_texture = Texture.create((xnum,ynum))
     self.real_intensity_texture = Texture.create((xnum,ynum))
     self.real_phase_texture = Texture.create((xnum,ynum))
    def update_list_data(self, path, filename):
        exist = False
        if filename:
            print "Path : " + str(path) + " | Filename " + str(filename[0])
            for i in self.root.ids["ViewPreProcess"].ids["SelectionList"].list_adapter.data:
                if filename is i.name:
                    print "Filename "+str(Filename)+" already exist\n"
                    exist = True
            if not exist:
                self.root.ids["ViewPreProcess"].ids["SelectionList"].update_list_data(path,filename)
                defPath = os.path.join(path, filename[0])
                if re.search('.CR2',defPath):
                    image = ImageRaw.ImageRaw(defPath).getndarray()
                    #print "Append \n"
                    self.pictureList.append(DataImage(path=filename[0],image=image))
                    h,l,r = image.shape
                    self.texture = Texture.create(size=(l,h))
                    self.texture.blit_buffer(pbuffer = image.tostring(),bufferfmt="ushort",colorfmt='rgb')
                elif re.search('[.jpg|.png|.gif|.tiff]',defPath):
                    image = io.imread(defPath)
                    self.pictureList.append(DataImage(path=filename[0],image=image))
                    h,l,r = image.shape
                    self.texture = Texture.create(size=(l,h))
                    self.texture.blit_buffer(pbuffer = image.tostring(),bufferfmt="ubyte",colorfmt='rgb')
                    self.texture.flip_vertical()


                self.root.ids["ViewPreProcess"].ids["Image"].ids["currentImage"].texture = self.texture
                self.root.ids["ViewPreProcess"].ids["Image"].ids["currentImage"].size = self.texture.size
                self.root.ids["ViewPreProcess"].ids["Image"].ids["currentImage"].reload()
Beispiel #5
0
 def _init_texture(self, resolution):
     width, height = resolution
     # Image looks at self.texture to determine layout, so we create 
     # texture but don't actually display it.
     self.texture = Texture.create(size=(height, width))
     self.texture_size = self.texture.size
     if IsAndroid:
         self._secondary_texture = Texture(width=height, height=width, target=GL_TEXTURE_EXTERNAL_OES, colorfmt='rgba')
         self._secondary_texture.bind()
         self._previewTexture = SurfaceTexture(int(self._secondary_texture.id))
 def __init__(self, **kwargs):
     super(AppScreen, self).__init__( **kwargs)
     self.output_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     self.style_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     self.photo_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     with self.canvas:
         #self.texture = self.video_texture
         self.output_rect = Rectangle(texture=self.output_texture, pos=(-5,0), size=(1, 1))
         self.style_rect = Rectangle(texture=self.style_texture, pos=(-5,0), size=(1, 1))
         self.photo_rect = Rectangle(texture=self.photo_texture, pos=(-5,0), size=(1, 1))
Beispiel #7
0
    def _redraw(self, *args):
        if not self._ffplayer:
            return
        next_frame = self._next_frame
        if not next_frame:
            return

        img, pts = next_frame
        if img.get_size() != self._size or self._texture is None:
            self._size = w, h = img.get_size()

            if self._out_fmt == 'yuv420p':
                w2 = int(w / 2)
                h2 = int(h / 2)
                self._tex_y = Texture.create(
                    size=(w, h), colorfmt='luminance')
                self._tex_u = Texture.create(
                    size=(w2, h2), colorfmt='luminance')
                self._tex_v = Texture.create(
                    size=(w2, h2), colorfmt='luminance')
                self._fbo = fbo = Fbo(size=self._size)
                with fbo:
                    BindTexture(texture=self._tex_u, index=1)
                    BindTexture(texture=self._tex_v, index=2)
                    Rectangle(size=fbo.size, texture=self._tex_y)
                fbo.shader.fs = VideoFFPy.YUV_RGB_FS
                fbo['tex_y'] = 0
                fbo['tex_u'] = 1
                fbo['tex_v'] = 2
                self._texture = fbo.texture
            else:
                self._texture = Texture.create(size=self._size,
                                                colorfmt='rgba')

            # XXX FIXME
            # self.texture.add_reload_observer(self.reload_buffer)
            self._texture.flip_vertical()
            self.dispatch('on_load')

        if self._texture:
            if self._out_fmt == 'yuv420p':
                dy, du, dv, _ = img.to_memoryview()
                if dy and du and dv:
                    self._tex_y.blit_buffer(dy, colorfmt='luminance')
                    self._tex_u.blit_buffer(du, colorfmt='luminance')
                    self._tex_v.blit_buffer(dv, colorfmt='luminance')
                    self._fbo.ask_update()
                    self._fbo.draw()
            else:
                self._texture.blit_buffer(
                    img.to_memoryview()[0], colorfmt='rgba')

            self.dispatch('on_frame')
 def __init__(self, **kwargs):
     super(Screen, self).__init__( **kwargs)
     self.context = zmq.Context()
     self.socket = None
     self.output_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     self.style_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     self.photo_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     with self.canvas:
         #self.texture = self.video_texture
         self.output_rect = Rectangle(texture=self.output_texture, pos=(-5,0), size=(1, 1))
         self.style_rect = Rectangle(texture=self.style_texture, pos=(-5,0), size=(1, 1))
         self.photo_rect = Rectangle(texture=self.photo_texture, pos=(-5,0), size=(1, 1))
     self.counter = 0
     self._keyboard = None
Beispiel #9
0
    def get_thing_texture(self):
        if 'thing' in self.texture_dictionary:
            return self.texture_dictionary['thing']

        print 'generating tree texture'
        texture = Texture.create(size=(128, 128), colorfmt='rgb')
        size = 128 * 128 * 3
        img_data = []
        for pixel in xrange(size):
            img_data.append({
                'r' : 20,
                'g' : 20,
                'b' : 20
            })
        img_buffer = []
        for pixel in img_data:
            img_buffer.append(pixel['r'])
            img_buffer.append(pixel['g'])
            img_buffer.append(pixel['b'])
        
        img_buffer = ''.join(map(chr, img_buffer))
        texture.wrap = 'repeat'
        texture.blit_buffer(img_buffer, colorfmt='rgb', bufferfmt='ubyte')
        self.texture_dictionary['thing'] = texture
        return texture
Beispiel #10
0
    def __init__(self, xPosition, yPosition, velocity_x, velocity_y, **kwargs):
        FooBall.__init__(self)

        self.velocity_x = velocity_x
        self.velocity_y = velocity_y
        self.texture = Texture.create(size=(1, 1))
        self.texture.blit_buffer(
            array(
                "B", [self.rgb_color_value, self.rgb_color_value, self.rgb_color_value / 3, self.rgb_color_value + 50]
            ),
            colorfmt="rgba",
            bufferfmt="ubyte",
        )
        self.pos = Vector(xPosition, yPosition)

        def move(self):
            FooBall.move(self)

            self.texture.blit_buffer(
                array(
                    "B",
                    [self.rgb_color_value, self.rgb_color_value / 3, self.rgb_color_value / 3, self.rgb_color_value],
                ),
                colorfmt="rgba",
                bufferfmt="ubyte",
            )
Beispiel #11
0
 def refbo(self):
     tex = Texture.create(size=self.fbo.texture.size, colorfmt='rgba', bufferfmt='ubyte')
     self.fbo = Fbo(size=tex.size, texture=tex)
     self.fbo.texture.mag_filter = 'nearest'
     self.fbo.texture.min_filter = 'nearest'
     self.fbo.draw()
     self.canvas.ask_update()
Beispiel #12
0
def TextureFromPyImage(pyImg):
    raw = pyImg.tostring()
    width, height = pyImg.size
    imdata = ImageData(width, height, 'rgb', raw)
    texture = Texture.create_from_data(imdata)
    texture.flip_vertical()
    return texture
Beispiel #13
0
    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)
Beispiel #14
0
    def __init__(self, **kwargs):
        self.canvas = Canvas()
        with self.canvas.before:
            Callback(self._set_blend_func)

        self.fbo_texture = Texture.create(size=self.size,
                                                  colorfmt='rgba',)
        self.fbo_texture.mag_filter='nearest'

        with self.canvas:
            #self.cbs = Callback(self.prepare_canvas)
            self.fbo = Fbo(size=self.size, texture=self.fbo_texture)
            #Color(1, 1, 1, 0)
            #self.fbo_rect = Rectangle()


        with self.fbo:
            ClearColor(0.0, 0.0, 0.0, 0.0)
            ClearBuffers()
            self.fbo_rect = Rectangle(size=self.size)


        #self.fbo.shader.source = resource_find('./kivy3dgui/gles2.0/shaders/invert.glsl')
        #with self.fbo.after:
        #    self.cbr = Callback(self.reset_gl_context)
        #    PopMatrix()

        with self.canvas.before:
            Callback(self._set_blend_func)

        # wait that all the instructions are in the canvas to set texture

        self.texture = self.fbo.texture
        super(FboFloatLayout, self).__init__(**kwargs)
Beispiel #15
0
    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")

        self._texture.blit_buffer(data, size=size, colorfmt="rgb")
Beispiel #16
0
    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)
Beispiel #17
0
 def realign(self, *largs):
     ts = self.texture.size
     ss = self.size
     schg = (ts[0] != ss[0] or ts[1] != ss[1])
     if schg:
         self.texture = Texture.create(size=self.size, colorfmt='rgba', bufferfmt='ubyte')
         self.texture.flip_vertical()
     if self.__rect:
         with self.canvas:
             Color(1, 1, 1)
             self.__rect.pos = self.pos
             if schg:
                 self.__rect.size = self.size
         if schg:
             self.update_rect()
     if self.browser:
         self.browser.WasResized()
         self.browser.NotifyScreenInfoChanged()
     # Bring keyboard to front
     try:
         k = self.__keyboard.widget
         p = k.parent
         p.remove_widget(k)
         p.add_widget(k)
     except:
         pass
Beispiel #18
0
    def draw(self, *args):
        super(FilledRect, self).draw(*args)

        self._texture = Texture.create(size=(1, 1), colorfmt='rgb')
        self._texture.blit_buffer(
            b''.join(map(chr, self.color)), 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)
    def create_tex(self, *args):
        center_color = 255, 255, 0
        border_color = 100, 0, 0

        size = (64, 64)
        tex = Texture.create(size=size)

        sx_2 = size[0] / 2
        sy_2 = size[1] / 2

        buf = ''
        for x in xrange(-sx_2, sx_2):
            for y in xrange(-sy_2, sy_2):
                a = x / (1.0 * sx_2)
                b = y / (1.0 * sy_2)
                d = (a ** 2 + b ** 2) ** .5

                for c in (0, 1, 2):
                    buf += chr(max(0,
                                   min(255,
                                       int(center_color[c] * (1 - d)) +
                                       int(border_color[c] * d))))

        tex.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
        return tex
 def __init__(self, **kwargs):
     super(Screen, self).__init__( **kwargs)
     cap = self.cap = cv2.VideoCapture(0)
     self.video_texture = Texture.create(size=(640, 480), colorfmt='rgb')
     """
     sleep(2)
     bgs = []
     while len(bgs)<5:
         r, bg = cap.read()
         bg = cv2.flip(bg, 1)
         bg = bg.astype(float)
         if all(np.mean(np.linalg.norm(bg-bg0, axis=2)) < 30 for bg0 in bgs):
             bgs.append(bg)
             print("append")
         else:
             bgs=[bg]
             print("init")
         bg0 = bg
         sleep(0.2)
     self.bgs = bgs
     """
     with self.canvas:
         w, h = Window.width, Window.height
         rh = int(h *0.8)
         rw = rh*4//3
         Rectangle(texture=self.video_texture, pos=( (w-rw)//2,0), size=(rw, rh))
Beispiel #21
0
    def on_size(self, *largs):
        self.canvas.clear()
        self.rectangles = []

        for idx in xrange(2):
            star_size = 3

            # create a texture, defaults to rgb / ubyte
            self.texture = Texture.create(size=self.size, colorfmt='rgba')
            self.texture.wrap = 'repeat'

            # create a white star's pixel array (255)
            texture_size = star_size * 4
            buf = [255 for x in xrange(texture_size)]

            # then, convert the array to a ubyte string
            buf = ''.join(map(chr, buf))

            for x in xrange(int(self.density * 256)):
                # then blit the buffer randomly across the texture
                self.texture.blit_buffer(buf,
                    pos=(random.randint(0, self.size[0] - 1),
                        random.randint(0, self.size[1] - 1)),
                    size=(star_size, star_size),
                    colorfmt='rgba',
                    bufferfmt='ubyte'
                )

            with self.canvas:
                self.rectangles.append(Rectangle(texture=self.texture, pos=self.pos, size=self.size))
Beispiel #22
0
 def Start(self):
     self.right_button.text = 'Same'
     if self.img.have_next:
         self.differs = self.next_differs
         #print 'Start working'
         im = self.img.next[0]
         self.img.old_im = self.img.current_im
         self.img.current_im = im.tostring()
         assert(not (self.e.nextf == 0 and self.img.current_im != self.img.old_im))
         texture = Texture.create(size=im.size)
         texture.blit_buffer(im.tostring(), colorfmt='rgba', bufferfmt='ubyte')
         texture.flip_vertical()
         self.img.texture = texture
         self.img.thisf = self.e.nextf
         self.begin_next_img()
         self.entropy_label.text = 'Entropy:  %.1f  f %g' % (self.e.estimate_entropy(), self.img.thisf)
     else:
         #print 'Start pending'
         self.left_button.disabled = True
         self.right_button.disabled = True
         Clock.schedule_once(lambda dt: self.Start(), 0.25)
         return
     anim = Animation(x=0, t='out_back', duration=animtime)
     anim.start(self.img)
     self.left_button.disabled = False
     self.right_button.disabled = False
 def set_image(self, value):
     image = np.rot90(np.swapaxes(value, 0, 1))
     if self.texture is None:
         self.texture = Texture.create(size=(image.shape[1], image.shape[0]), colorfmt='rgb')
     self.texture.blit_buffer(image.flatten(), colorfmt='bgr', bufferfmt='ubyte')
     self.tex_size = self._get_new_size(self.texture.size[0], self.texture.size[1])
     self.tex_pos = (self.x + (self.width - self.tex_size[0]) / 2, self.y + (self.height - self.tex_size[1]) / 2)
Beispiel #24
0
def widgetshot(widget, filename='output.png'): 
# detach the widget from the parent 
    parent = widget.parent
    if parent:
        parent.remove_widget(widget)

    # put the widget canvas on a Fbo
    texture = Texture.create(size=widget.size, colorfmt='rgb')
    fbo = Fbo(size=widget.size, texture=texture)
    fbo.add(widget.canvas)

    # clear the fbo background
    fbo.bind()
    fbo.clear_buffer()
    fbo.release()

    # draw!
    fbo.draw()

    # get the fbo data
    fbo.bind()
    data = glReadPixels(0, 0, widget.size[0], widget.size[1], GL_RGBA, GL_UNSIGNED_BYTE)
    fbo.release()

    # save to a file
    surf = pygame.image.fromstring(data, widget.size, 'RGBA', True)
    pygame.image.save(surf, filename)

    # reattach to the parent
    if parent:
        parent.add_widget(widget)

    return True
Beispiel #25
0
 def on_index(self, instance, value):
     self.queue = Queue()
     self.texture = Texture.create((640, 480))
     self.kinect = Kinect(self.process_kinect, index=value,
                          colorfmt='luminance', use_video=True,
                          use_depth=False)
     Clock.schedule_interval(self.pop_queue, 0)
 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()
     with self.canvas:
         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
Beispiel #27
0
    def _update(self, dt):
        if self._do_load:
            self._player.open()
            self._do_load = False
            return

        player = self._player
        if player is None:
            return
        if player.is_open is False:
            self._do_eos()
            return

        frame = player.get_next_frame()
        if frame is None:
            return

        # first time we got a frame, we know that video is readed now.
        if self._texture is None:
            self._texture = Texture.create(size=(player.get_width(), player.get_height()), colorfmt="rgb")
            self._texture.flip_vertical()
            self.dispatch("on_load")

        self._texture.blit_buffer(frame)
        self.dispatch("on_frame")
Beispiel #28
0
 def update(self, dt):
     # 基本的にここでOpenCV周りの処理を行なってtextureを更新する
     ret, frame = self._cap.read()
     frame = cv2.flip(frame, 0)
     kvTexture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
     kvTexture1.blit_buffer(frame.tostring(), colorfmt='bgr', bufferfmt='ubyte')
     self.kvImage1.texture = kvTexture1
Beispiel #29
0
 def on_touch_up(self, touch):
     if touch.grab_current is not self:
         return super(CollideTester, self).on_touch_up(touch)
     touch.ungrab(self)
     if self.state == 'drawing':
         self.state = 'testing'
         self.collider = Collide2DPoly(touch.ud['line'].points, cache=True)
         collider = self.collider
         texture = Texture.create(size=self.size)
         inside = [255, 255, 0]
         outside = [255, 0, 255]
         x_off, y_off = self.pos
         width = int(self.width)
         height = int(self.height)
         buf = bytearray(width * height * 3)
         for x in range(width):
             for y in range(height):
                 pos = (x + y * width) * 3
                 buf[pos:pos + 3] = (inside if (x + x_off, y + y_off)
                                     in collider else outside)
         texture.blit_buffer(bytes(buf), colorfmt='rgb',
                             bufferfmt='ubyte')
         self.canvas.remove_group('12345')
         with self.canvas:
             Rectangle(texture=texture, pos=self.pos, size=self.size,
                       group='12345')
Beispiel #30
0
    def redraw(self, dt=0, force_refresh=False):
        if not self.ffplayer:
            return
        if self.next_frame:
            img, pts = self.next_frame
            if img.get_size() != self.size or self.texture is None:
                self.root.image.canvas.remove_group(str(self)+'_display')
                self.texture = Texture.create(size=img.get_size(),
                                              colorfmt='rgb')
                # by adding 'vf':'vflip' to the player initialization ffmpeg
                # will do the flipping
                self.texture.flip_vertical()
                self.texture.add_reload_observer(self.reload_buffer)
                self.size = img.get_size()
                logging.debug('ffpyplayer: Creating new image texture of '
                              'size: {}.'.format(self.size))
            self.texture.blit_buffer(img.to_memoryview()[0])
            self.root.image.texture = None
            self.root.image.texture = self.texture
            self.root.seek.value = pts
            logging.debug('ffpyplayer: Blitted new frame with time: {}.'
                          .format(pts))

        if self.root.seek.value:
            self.root.seek.max = self.ffplayer.get_metadata()['duration']
 def _draw_bitmap(self):
     if self._bitmap is None:
         print "No bitmap!"
         return
     self._img_texture = Texture.create(size=(self.bt_w, self.bt_h))
     self._img_texture.blit_buffer(self._bitmap,
                                   colorfmt="rgb",
                                   bufferfmt='ubyte')
     self._img_texture.flip_vertical()
 def load_image(self, path, filename):
     image = ImageRecognition(os.path.join(path, filename[0]))
     width, height, texture_data = image.getTextureData()
     texture = Texture.create(size=(width, height))
     texture.blit_buffer(texture_data, colorfmt='bgr', bufferfmt='ubyte')
     self.loaded_image = texture
     width, height = image.getWidthHeight()
     self.predict([width, height, None])
     self.dismiss_popup()
Beispiel #33
0
 def turnFrameIntoImage(self, frame, colorFormat):
     # convert it to texture
     buf1 = cv2.flip(frame, 0)
     buf = buf1.tostring()
     image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                    colorfmt=colorFormat)
     image_texture.blit_buffer(buf, colorfmt=colorFormat, bufferfmt='ubyte')
     # display image from the texture
     self.texture = image_texture
Beispiel #34
0
 def update(self, dt):
     buf = ''
     buf = sv.SocketServer.tmpl_kivy
     if buf != '':
         test = buf.tostring()
         textimg = Texture.create(size=(buf.shape[1], buf.shape[0]),
                                  colorfmt='rgba')
         textimg.blit_buffer(test, colorfmt='rgba', bufferfmt='ubyte')
         self.texture = textimg
    def update(self, dt):
        try:
            camera = self.ids['camera']
            self.snapshot = camera.texture
            if self.snapshot != None:

                image = self.ids['image']
                nparr = np.fromstring(camera.texture.pixels,
                                      dtype=np.uint8).copy()
                a = np.reshape(nparr, (480, 640, 4))
                texture = Texture.create(size=(a.shape[1], a.shape[0]),
                                         colorfmt='rgba')
                # TODO: PROCESS FRAME HERE
                image2 = cv2.imread(IS.current_image)
                image2 = cv2.flip(image2, 1)
                # image2 = cv2.imread('/home/alex/Загрузки/test.jpg')
                image2 = cv2.rotate(image2, cv2.ROTATE_90_COUNTERCLOCKWISE)
                b_c, g_c, r_c = cv2.split(image2)
                a_c = np.ones(b_c.shape, dtype=b_c.dtype) * 100
                image2 = cv2.merge((b_c, g_c, r_c, a_c))
                Logger.info('\n\n\n\n{}\n\n\n\n'.format(image2.shape))
                shadow = out_shadow(a, image2)
                Logger.info('\n\n\n\n{}\n\n\n\n'.format(IS.current_image))
                res = blend_transparent(a, shadow)
                b_c, g_c, r_c = cv2.split(res)
                a_c = np.ones(b_c.shape, dtype=b_c.dtype) * 100
                res = cv2.merge((b_c, g_c, r_c, a_c))
                ##########################
                texture.blit_buffer(res.tostring(),
                                    bufferfmt='ubyte',
                                    colorfmt="rgba")
                image.texture = texture

        except Exception as e:
            Logger.error('\n\n\n\n{}\n\n\n\n'.format(e))
            camera = self.ids['camera']
            nparr = np.fromstring(camera.texture.pixels, dtype=np.uint8).copy()
            a = np.reshape(nparr, (480, 640, 4))
            texture = Texture.create(size=(a.shape[1], a.shape[0]),
                                     colorfmt='rgba')
            texture.blit_buffer(a.tostring(),
                                bufferfmt='ubyte',
                                colorfmt="rgba")
            image.texture = texture
Beispiel #36
0
 def update_image(self):
     if self.thehash.have_next:
         im = self.thehash.next[0]
         texture = Texture.create(size=im.size)
         texture.blit_buffer(im.tostring(), colorfmt='rgba', bufferfmt='ubyte')
         texture.flip_vertical()
         self.thehash.texture = texture
     else:
         Clock.schedule_once(lambda dt: self.update_image(), 0.5)
         return
Beispiel #37
0
    def __init__(self, main, **kwargs):
        self.ratio = 1
        self.srcImg = Texture.create(size=(0, 0))
        self.convImg = Texture.create(size=(0, 0))

        # Create Filter selector button and bound content
        self.filterselector = ClickMenuButton(main=main, contentLength=0.6)

        super(Previewer, self).__init__(**kwargs)

        # Set the height of bound content
        self.ids.mainview.bind(
            height=self.filterselector.lockChild.setter('height'))
        self.add_widget(self.filterselector.lockChild)
        self.add_widget(self.filterselector)

        # Set press-actions for buttons
        self.ids.brbutton.on_press = main.browseButtonFunction
        self.ids.applybutton.on_press = main.applyButtonFunction
Beispiel #38
0
 def on_dsm(self, instance, value):
     if self.dsm is not None:
         self.colorfmt = self.dsm.get_colorfmt()
         x, y = self.dsm.get_dims()
         buf_shape = (dp(x), dp(y))
         self.image.texture = Texture.create(size=buf_shape,
                                             colorfmt=self.colorfmt)
         self.is_x_flipped = False
         self.is_y_flipped = False
         self.need_init = False
Beispiel #39
0
    def build(self):
        tex = self.bits_texture = Texture.create(size=(1, 1))
        tex.mag_filter = 'nearest'
        tex.min_filter = 'nearest'

        root = Builder.load_string(kv)
        grid = root.bits
        for i in range(23, -1, -1):
            grid.add_widget(Factory.BitToggleButton(text=str(i)))
        return root
Beispiel #40
0
 def update_image(self, dt):
     image = self.capture.get_image()
     image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
     image = cv2.flip(image, 0)
     texture = Texture.create(size=(image.shape[1], image.shape[0]))
     texture.blit_buffer(image.tostring())
     with self.w.canvas:
         Rectangle(texture=texture,
                   pos=(0, 0),
                   size=(image.shape[1], image.shape[0]))
Beispiel #41
0
 def get_texture_from_frame(self, frame, flipped):
     buffer_frame = cv2.flip(frame, flipped)
     buffer_frame_str = buffer_frame.tostring()
     image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                    colorfmt='bgr')
     #print('('+str(frame.shape[1])+';'+str(frame.shape[0])+')')
     image_texture.blit_buffer(buffer_frame_str,
                               colorfmt='bgr',
                               bufferfmt='ubyte')
     return image_texture
 def update(self, dt):
     _, frame = self.capture.read()
     frame = self.mirrorizeFrame(frame)
     frame = self.detectFace(frame)
     buf1 = cv2.flip(frame, 0)
     buf = buf1.tostring()
     texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]),
                               colorfmt='bgr')
     texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     self.img1.texture = texture1
 def cam_update(self, dt):
     try:
         _, frame = self.capture.read()
         buf1 = cv2.flip(frame, 0)
         buf = buf1.tostring()
         texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='rgb')
         texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
         self.ids['img_cam'].texture = texture1
     except Exception as e:
         pass
Beispiel #44
0
    def insert(self, input):
        if input.format == Eidon.Format.RGBA:
            fmt = 'rgba'
        elif input.format == Eidon.Format.RGB:
            fmt = 'rgb'

        tex = Texture.create(size=(input.width, input.height), colorfmt=fmt)
        tex.blit_buffer(input.data, colorfmt=fmt, bufferfmt='ubyte')
        with self.ids['picture'].canvas:
            Rectangle(texture=tex, size=self.ids['camera'].texture.size)
Beispiel #45
0
 def update_texture(self, frame):
     # updates image with a cv2 image
     print('updated frame')
     buf1 = cv2.flip(frame, 0)
     buf = buf1.tostring()
     texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]),
                               colorfmt='bgr')
     texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     self.img.texture = texture1
     print('updated frame')
Beispiel #46
0
 def update(self, dt):
     return_value, frame = self.capture.read()
     if return_value:
         texture = self.texture
         w, h = frame.shape[1], frame.shape[0]
         if not texture or texture.width != w or texture.height != h:
             self.texture = texture = Texture.create(size=(w, h))
             texture.flip_vertical()
         texture.blit_buffer(frame.tobytes(), colorfmt='bgr')
         self.canvas.ask_update()
Beispiel #47
0
    def update_plot(self, data):
        arr = array('B', data[0])

        if self.texture.size[0] != data[2] or self.texture.size[1] != data[3]:
            texture = Texture.create(size=(data[2], data[3]))
            self.texture = texture
            self.texture.blit_buffer(arr, colorfmt='rgb', bufferfmt='ubyte')
            self.my_redraw_state_bits()
        else:
            self.texture.blit_buffer(arr, colorfmt='rgb', bufferfmt='ubyte')
Beispiel #48
0
 def update(self, dt):
     # フレームを読み込み
     ret, self.frame = self.capture.read()
     # Kivy Textureに変換
     buf1 = cv2.flip(self.frame, 0)
     buf = buf1.tostring()
     texture = Texture.create(size=(self.frame.shape[1], self.frame.shape[0]), colorfmt='bgr') 
     texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     # インスタンスのtextureを変更
     self.texture = texture
Beispiel #49
0
 def update(self, instance):
     _, self.frame = self.capture.read()
     self.frame = extract_all_faces(self.frame)
     buf1 = cv2.flip(self.frame, 0)
     buf = buf1.tostring()
     texture = Texture.create(size=(self.frame.shape[1],
                                    self.frame.shape[0]),
                              colorfmt='bgr')
     texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     self.img.texture = texture
Beispiel #50
0
 def _update_texture(self, buf):
     # texture will be updated with newest buffer/frame
     caps = buf.get_caps()[0]
     size = caps['width'], caps['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()
     # upload texture data to GPU
     self._texture.blit_buffer(buf.data, size=size, colorfmt='rgb')
Beispiel #51
0
 def __init__(self):
     self.size_x = SIZE_X
     self.size_y = SIZE_Y
     self.pixel_size = 16
     self.texture = Texture.create(size=(self.size_x * self.pixel_size,
                                         self.size_y * self.pixel_size))
     # open shared memory
     self.fd = os.open(SHM_FILE, os.O_RDONLY)
     self.grid_file = mmap.mmap(self.fd, BUF_SIZE, mmap.MAP_SHARED,
                                mmap.PROT_READ)
Beispiel #52
0
    def refresh_widget(self, img, format_img):
        if self.texture is None or\
                self.texture.size != [img.shape[1], img.shape[0]]:
            self.allow_stretch = True
            self.texture = Texture.create(size=[img.shape[1], img.shape[0]],
                                          colorfmt=format_img)
            self.texture.flip_vertical()

        self.texture.blit_buffer(img.reshape(-1), colorfmt=format_img)
        self.canvas.ask_update()
Beispiel #53
0
    def noise(size=(64, 64)):
        tex = Texture.create(size=size)

        buf = [
            int(random.uniform(0, 255)) for x in range(size[0])
            for y in range(size[1]) for c in range(3)
        ]
        #print(buf)
        tex.blit_buffer(bytes(buf), colorfmt='rgb', bufferfmt='ubyte')
        return tex
Beispiel #54
0
 def showImage(self, frame):
     # Inverts the image so it not upside down
     flippedFrame = cv2.flip(frame, 0)
     # Converts into a texture to use with kivy
     buf = flippedFrame.tostring()
     texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                              colorfmt='bgr')
     texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     # Shows the image on screen
     self.img_video.texture = texture
Beispiel #55
0
    def build(self):
        self.gradient = Texture.create(size=(1, 2), colorfmt='rgb')
        color1 =[45,40,80,1]
        color2 =[45,75,90,1]
        buf = bytes(color1+color2)
        self.gradient.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

        Builder.load_file('shareapp.kv')
        sm.add_widget(MainScreen(name='MainScreen'))
        return sm
Beispiel #56
0
	def load_texture(self, *args):
		tex = None
		if self.captured_data and self.captured_size:
			tex = Texture.create(size=self.captured_size, colorfmt='rgba')
			tex.blit_buffer(self.captured_data, colorfmt='rgba', bufferfmt='ubyte')
			tex.flip_vertical()
			self.captured_texture = tex
		self.captured_data = self.captured_size = None
		self.captured_texture = tex
		self.dispatch('on_capture_completed', self.captured_texture, self.captured_size)
Beispiel #57
0
 def init_texture(self):
     if len(self.transforms) == 0:
         self.tf_texture = self._camera.texture
     else:
         self.tf_texture = Texture.create(size=self.texture.size,
                                          colorfmt=self.texture.colorfmt)
     texture = self._camera.texture
     self.texwidth = texture.size[0]
     self.texheight = texture.size[1]
     self.texfmt = texture.colorfmt
Beispiel #58
0
    def __init__(self, ocv_property, **kwargs):
        super(OCVViewer, self).__init__(**kwargs)
        self.ocv_video = OCVVideo('post', SIZE)
        self.path = ''

        self.ocv_video.create_video_capture(self.path)

        self.texture = Texture.create(size=(SIZE))
        self.texture.flip_vertical()
        self.state = 0
Beispiel #59
0
    def frame_to_buf(self, frame):

        if frame is None:
            return
        buf1 = cv2.flip(frame, 0)
        if buf1 is not None:
            buf = buf1.tostring()
            self.texture = Texture.create(size=(640, 480))
            self.texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
            return True
Beispiel #60
0
 def update(self, dt):
     ret, frame = self.capture.read()
     if ret:
         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')
         self.texture = image_texture