예제 #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
예제 #2
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()
예제 #4
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
예제 #5
0
 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))
예제 #6
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
 def update(*largs):
     global r, w
     print("BEF", w, r.texture, r.texture.width, r.texture.height)
     half = int(
         w.size[0] * w.size[1] * texture_size_hint *
         texture_size_hint / 2,
     )
     if not w.mv:
         r.texture = Texture.create(
             size=(
                 w.size[0]*texture_size_hint,
                 w.size[1]*texture_size_hint,
             ),
             colorfmt="rgba", bufferfmt="ubyte")
         w.ba = bytearray([255, 0, 0] * half + [0, 255, 0] * half)
         w.mv = memoryview(w.ba)
     else:
         for i in range(
             random.randint(0, half*3),
             random.randint(half * 3, 2 * half * 3),
         ):
             w.ba[i] = 255
     beg = time.time()
     r.texture.blit_buffer(w.mv)
     print(time.time() - beg)
     r.size = w.size
     print("AFT", w, r.texture, r.texture.width, r.texture.height)
예제 #9
0
파일: __init__.py 프로젝트: pylover/kivy
    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)
예제 #10
0
 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)
예제 #11
0
파일: video_gi.py 프로젝트: Glebtor/kivy
    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")
예제 #12
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)
예제 #13
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))
예제 #14
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
예제 #15
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",
            )
예제 #16
0
파일: test.py 프로젝트: matham/ffpyplayer
    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']
예제 #17
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
예제 #18
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()
예제 #19
0
파일: grating.py 프로젝트: compmem/smile
    def _update_grating(self, *args):
        '''Update grating variables

        The function calls the _calc_color function to create the
        grating texture which is layered behind the mask.

        '''
        # calculate the num needed for period
        self._period = int(round(360. / self.frequency))

        # make new texture
        self._texture = Texture.create(size=(self._period, 1),
                                       colorfmt='rgb',
                                       bufferfmt='ubyte')

        # fill the buffer for the texture
        grating_buf = list(chain.from_iterable([self._calc_color(x)
                                                for x in range(self._period)]))
        # make an array from the buffer
        grating_arr = b''.join(map(chr, grating_buf))

        # blit the array to the texture
        self._texture.blit_buffer(grating_arr, colorfmt='rgb',
                                  bufferfmt='ubyte')

        # set it to repeat
        self._texture.wrap = 'repeat'
        BindTexture(texture=self._texture, index=0)
예제 #20
0
    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
예제 #21
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)
예제 #22
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
 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))
예제 #24
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)
예제 #25
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')
예제 #26
0
파일: browser.py 프로젝트: rentouch/cefkivy
 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
예제 #27
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)
예제 #28
0
파일: main.py 프로젝트: AydinSakar/kivybits
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
 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
예제 #30
0
파일: video_ffmpeg.py 프로젝트: rubik/kivy
    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")
예제 #31
0
    def __init__(self, **args):
        super(MyWidget, self).__init__(**args)

        texture = Texture.create(size=(2, 1), colorfmt='rgb')

        color1 = 0
        color2 = 255

        buf = ''.join(map(chr, [color1, color2])).encode()

        texture.blit_buffer(buf)

        with self.canvas:
            Rectangle(pos=self.pos, size=self.size, texture=texture)
예제 #32
0
 def update(self, dt):
     ret, frame = self.capture.read()
     if ret:
         # Convert 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
         print("Updated Image...")
예제 #33
0
파일: camera.py 프로젝트: tscung/tailor
    def _update(self, dt):
        if self.stopped:
            return

        if self._texture is None:
            self._texture = Texture.create(self._resolution)
            self._texture.flip_vertical()
            self.dispatch('on_load')
        try:
            self._buffer = self._grab_last_frame()
            self._copy_to_gpu()
        except:
            # Logger.exception('OpenCV: Couldn\'t get image from Camera')
            pass
    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')
    def display_frame(self, frame, dt):
        # display the current video frame in the kivy Image widget

        # create a Texture the correct size and format for the frame
        texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')

        # copy the frame data into the texture
        texture.blit_buffer(frame.tobytes(order=None), colorfmt='bgr', bufferfmt='ubyte')

        # flip the texture (otherwise the video is upside down
        texture.flip_vertical()

        # actually put the texture in the kivy Image widget
        self.main_screen.ids.vid.texture = texture
    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)
예제 #37
0
파일: App.py 프로젝트: gatherheart/POSE_APP
 def update(self, dt):
     # display image from cam in opencv window
     ret, frame = self.capture.read()
     self.image = frame
     overlay = cv2.resize(cv2.imread('human_line.png'), (frame.shape[1], frame.shape[0]))
     added_image = cv2.addWeighted(frame, 1, overlay, 1, 0)
     cv2.imshow("CV2 Image", frame)
     # convert it to texture
     buf1 = cv2.flip(added_image, 0)
     buf = buf1.tostring()
     texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
     texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
     # display image from the texture
     self.ids.imageView.texture = texture1
예제 #38
0
    def update(self, dt):
        ret, frame = self.capture.read()
        if ret:
            # convert 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
            self.canvas.ask_update()
예제 #39
0
 def update(self, dt):
     ret, frame = self.capture.read()
     if ret:
         destFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
         # convert it to texture
         buf1 = cv2.flip(destFrame, 0)
         buf = buf1.tostring()
         image_texture = Texture.create(size=(frame.shape[1],
                                              frame.shape[0]),
                                        colorfmt='rgb')
         image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
         #image_texture.flip_horizontal()
         # display image from the texture
         self.texture = image_texture
예제 #40
0
    def update(self, dt):
        self.ret, self.frame = self.capture.read()
        if self.ret:
            # convert it to texture
            self.output = self.frame.copy()
            cv2.rectangle(self.output, (self.RECTX, self.RECTY), (self.RECTX+self.RECTW, self.RECTY+self.RECTH), (0,255,0), self.RECTT)
            buf1 = cv2.flip(self.output, 0)
            buf = buf1.tostring()
            image_texture = Texture.create(
                size=(self.frame.shape[1], self.frame.shape[0]), colorfmt='bgr')

            image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
            # display image from the texture
            self.texture = image_texture
예제 #41
0
    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
        self._texture.blit_buffer(buf.data, size=size, colorfmt='rgb')
예제 #42
0
    def updateScreen(self, dt):
        # capture frame
        ret, frame = self.capture.read()
        if frame is None:
            return

        buf1 = cv2.flip(frame, 0)
        buf = buf1.tostring()  # convert in texture

        texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                  colorfmt='bgr')
        texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')

        self.img1.texture = texture1
예제 #43
0
 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)
예제 #44
0
    def on_press_stop(self):
        if self.main_screen.ids.video.capture is not None:
            self.main_screen.ids.video.stop()
            self.main_screen.ids.video.capture.release()
            self.main_screen.ids.video.running = ''
            self.main_screen.ids.video.texture = Texture.create(size=(1920,
                                                                      1080),
                                                                colorfmt='bgr')
            self.main_screen.ids.data_grid.clear_widgets()

            self.main_screen.ids.start_button.disabled = False
            self.main_screen.ids.pause_button.disabled = True

            self.main_screen.ids.data_grid.selected_record = None
 def on_texture_image(self, instance, value):
     # Render the image
     # Resize image to the size of the background
     im_resize = self.texture_image.resize(
         (int(self.bgrect.size[0]), int(self.bgrect.size[1])))
     # Create the blank texture
     texture = Texture.create(size=(int(self.bgrect.size[0]),
                                    int(self.bgrect.size[1])),
                              colorfmt="luminance")
     # Convert the image to the texture
     data = im_resize.tobytes()
     texture.blit_buffer(data, bufferfmt="ubyte", colorfmt="luminance")
     # Attach the texture to the table
     self.bgrect.texture = texture
예제 #46
0
 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
         text = detection_image(buf1)
         #image_texture = WidgetRaiz(text=text)
         self.texture = image_texture
예제 #47
0
def cv2kvtexture(img, force3=True):
    if len(img.shape) == 2:
        img2 = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
    elif img.shape[2] == 3 or force3:
        img2 = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  # BGR to RGB
    else:  # with alpha
        img2 = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)  # BGRA to RGBA
    img2 = cv2.flip(img2, 0)  # flip upside down
    height = img2.shape[0]
    width = img2.shape[1]
    texture = Texture.create(size=(width, height))
    colorfmt = 'rgb' if img2.shape[2] == 3 else 'rgba'
    texture.blit_buffer(img2.tostring(), colorfmt=colorfmt)
    return texture
예제 #48
0
 def update(self, dt):
     ret, frame = self.capture.read()
     if ret:
         #frame = adjust_cv_img(frame)
         frame = face_detector(frame)
         # convert it to texture
         buf1 = cv2.flip(frame, 0)
         buf = buf1.tobytes()
         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
예제 #49
0
 def show_frame_bgra(self, frame):
     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')
     image_texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                    colorfmt='bgra')
     image_texture.blit_buffer(buf, colorfmt='bgra', bufferfmt='ubyte')
     #self.ids.image.texture = image_texture
     new_image = Image()
     new_image.texture = image_texture
     #new_image.color = [1,1,1,self.bg_opacity]
     self.ids.screen.add_widget(new_image)
 def update(self, dt):
     ret, frame = self.capture.read()
     if ret:
         # convert it to texture
         found, frame = self.personDetect.run(frame)
         print(found)
         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
예제 #51
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        Tex1 = Texture.create(size=T_SIZE, colorfmt="rgba", bufferfmt="float")
        Tex2 = Texture.create(size=T_SIZE, colorfmt="rgba", bufferfmt="float")
        Tex3 = Texture.create(size=T_SIZE, colorfmt="rgba", bufferfmt="float")
        Tex4 = Texture.create(size=T_SIZE, colorfmt="rgba", bufferfmt="float")
        Tex4.mag_filter = "linear"

        self.fbo_edit = Fbo(clear_color=(0.5,0.5,0,1),size=(T_SIZE),texture=Tex1)
        self.fbo_edit.shader.vs = open("data/shaders/vs.glsl").read()
        self.fbo_edit.shader.fs = open("data/shaders/fs_edit.glsl").read()
        self.fbo_edit["viewport"] = [float(s) for s in W_SIZE]
        self.fbo_edit["mode"] = 0

        self.fbo_mix = Fbo(clear_color=(0.5,0.5,0,1),size=(T_SIZE),texture=Tex2)
        self.fbo_mix.shader.vs = open("data/shaders/vs.glsl").read()
        self.fbo_mix.shader.fs = open("data/shaders/fs_mix.glsl").read()
        self.fbo_mix["tex1"] = 1
        self.fbo_mix["tex2"] = 2
        self.fbo_mix["viewport"] = [float(s) for s in W_SIZE]

        self.fbo_save = Fbo(clear_color=(0.5,0.5,0,1),size=(T_SIZE),texture=Tex3)
        self.fbo_save.shader.vs = open("data/shaders/vs.glsl").read()
        self.fbo_save.shader.fs = open("data/shaders/fs_save.glsl").read()
        self.fbo_save["tex"] = 3
        self.fbo_save["viewport"] = [float(s) for s in W_SIZE]

        self.fbo_warp = Fbo(size=(T_SIZE),texture=Tex4)
        self.fbo_warp.shader.vs = open("data/shaders/vs.glsl").read()
        self.fbo_warp.shader.fs = open("data/shaders/fs_warp.glsl").read()
        self.fbo_warp["tex"] = 4
        self.fbo_warp["warp"] = 5
        self.fbo_warp["viewport"] = [float(s) for s in W_SIZE]

        self.tex = Texture.create(size=T_SIZE,colorfmt="rgb",bufferfmt="ubyte")
        self.tex.blit_buffer(IMG)
예제 #52
0
    def __init__(self, *args, **kwargs):
        #init the firsttouch and call the super
        super(SegmentationWidget, self).__init__(*args, **kwargs)

        self.firstTouch = True
        self.isKeep = True

        self.bind(size=self._update_rect, pos=self._update_rect)

        #keyboard stuff
        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        imgName = sys.argv[1]
        img = cv2.imread(imgName).astype(np.uint8)
        img = np.flip(img,axis=0)
        #align image

        self.imgWidth = img.shape[1]
        self.imgHeight = img.shape[0]
        self.flatShape = (self.imgHeight,self.imgWidth,1)
        self.flatestShape = (self.imgHeight,self.imgWidth)

        #attach the image to a texture
        self.texture = Texture.create(size=(self.imgWidth , self.imgHeight), colorfmt="bgr")
        self.texture.blit_buffer(img.tostring(), bufferfmt="ubyte", colorfmt="bgr")

        #create the copy
        
        self.imgOut = img
        self.img = img
        self.intensity = np.average(img,axis=2).astype(np.uint8).reshape(self.flatShape)

        img = np.flip(img,axis=0)
        cv2.imwrite('out2.jpg', img)

        #create the graph and do initialization
        self.g = maxflow.Graph[int]()
        self.nodes = self.g.add_grid_nodes(self.flatShape)

        self.f = np.zeros(self.flatShape)
        self.b = np.full(self.flatShape,np.inf,dtype=np.float)

        self.wf = np.zeros(self.flatShape)
        self.wb = np.zeros(self.flatShape)

        with self.canvas.before:
            #attach the texture to the app
            self.rect = Rectangle(texture=self.texture, size=self.size, pos=self.pos)
예제 #53
0
파일: test2.py 프로젝트: hindhinge/Spectro
    def __init__(self, **kwargs):
        super(RectBlock, self).__init__(**kwargs)
        texture = Texture.create(size=(8,800))
        size = 8 * 800 * 3
        buf = []
        cnt = 0
        for i in range(100):
            for j in range(64):
                for k in range(3):
                    buf.append(color[i][k])
        arr = array('B', buf)
        texture.blit_buffer(arr, colorfmt='rgb', bufferfmt='ubyte')

        with self.canvas:
            Rectangle(texture=texture, pos=self.pos, size=(8,800))
    def update(self, event):

        ret, img = self.capture.read()

        if ret:
            self.imgArray = img

            faces = self.classifier.detectMultiScale(img, 1.2, 5)

            if len(faces) >= 1:
                x, y, w, h = faces[0]
                faceCut = img[y:y + h, x:x + w]
                outface = cv2.resize(faceCut, (100, 100))
                gray = cv2.cvtColor(outface, cv2.COLOR_BGR2GRAY)

                names = model.predict([gray.flatten()])
                self.lbl.text = str(names[0])

                fliped = outface[::-1]
                face_buf = fliped.tobytes()
                texture = Texture.create(size=(fliped.shape[1],
                                               fliped.shape[0]),
                                         colorfmt='bgr')
                texture.blit_buffer(face_buf,
                                    colorfmt='bgr',
                                    bufferfmt='ubyte')

                self.faceWidget.texture = texture

            fliped = img[::-1]
            buf = fliped.tobytes()
            texture = Texture.create(size=(img.shape[1], img.shape[0]),
                                     colorfmt='bgr')
            texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')

            self.imgWidget.texture = texture
예제 #55
0
 def update(self, dt):
     global roi
     return_value, frame = self.capture.read()
     frame = cv2.flip(frame, 1)
     cv2.rectangle(frame, (300, 100), (600, 400), (0, 255, 0), 0)
     roi = frame[100:400, 300:600]
     roi = draw_rect(roi)
     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()
예제 #56
0
 def update(self, dt):
     global text, word, count_same_frame, threshold
     ret, frame = self.capture.read()
     if ret:
         # convert it to texture
         b = cv2.flip(threshold, 0)
         buf = b.tostring()
         image_texture = Texture.create(size=(threshold.shape[1],
                                              threshold.shape[0]),
                                        colorfmt='luminance')
         image_texture.blit_buffer(buf,
                                   colorfmt='luminance',
                                   bufferfmt='ubyte')
         # display image from the texture
         self.texture = image_texture
예제 #57
0
파일: config.py 프로젝트: dain-kim/ASLingo
    def on_update(self):
        if self.predict:
            result = self.video.get_next_frame()
            if result is not None:
                frame, pred, score = result
                buf = cv2.flip(frame, 0)
                buf = buf.tostring()
                texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                         colorfmt='bgr')
                texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
                self.texture = texture
                return pred, score

        else:
            frame = self.video.get_frame()
            if frame is not None:
                buf = cv2.flip(frame, 0)
                buf = cv2.flip(buf, 1)
                buf = buf.tostring()
                texture = Texture.create(size=(frame.shape[1], frame.shape[0]),
                                         colorfmt='bgr')
                texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
                self.texture = texture
                return True
예제 #58
0
def createInsetBoxShadow(w, h, r, alpha = 1.0):
    w, h, r = int(w), int(h), int(r) 

    texture = Texture.create(size=(w, h), colorfmt='rgba')
    
    im = Image.new('RGBA', (w, h), color=(0, 0, 0, int(255 * alpha)))

    draw = ImageDraw.Draw(im)
    draw.rectangle((r, r, w - r, h - r), fill=(255, 255, 255, 0))
    
    im = im.filter(ImageFilter.GaussianBlur(0.25 * r))

    texture.blit_buffer(im.tobytes(), colorfmt='rgba', bufferfmt='ubyte')

    return texture
예제 #59
0
    def update(self, dt):
        self.frame_count = (self.frame_count + 1) % (self.fps / 10)
        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

            if self.frame_count == 0:
                self.recognize_emotion(frame)
                self.update_emoji_preview()
예제 #60
0
    def update(self, dt):
        # display image from cam in opencv window
        ret, img = self.capture.read()
        # cv2.imshow("CV2 Image", img)

        img = self.detector.findHands(img)
        lmList = self.detector.findPosition(img)
        # convert it to texture
        buf1 = cv2.flip(img, 0)
        buf = buf1.tostring()
        texture1 = Texture.create(size=(img.shape[1], img.shape[0]), colorfmt='bgr')
        #if working on RASPBERRY PI, use colorfmt='rgba' here instead, but stick with "bgr" in blit_buffer.
        texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
        # display image from the texture
        self.img1.texture = texture1