예제 #1
0
    def __init__(self, **kwargs):
        super(GroundTruthWidget, self).__init__(**kwargs)
        self.view_size = kwargs['view_size']
        self.img_size = kwargs['img_size']
        self.sample_event = None
        self.boundary_tree = None
        self.pointer = None
        self.gt_rect = None
        self.tt_rect = None
        self.gt_tex = None
        self.tt_tex = None
        self.bt_len_last = None
        self.iter_label = None
        self.max_iters = 10000
        self.epoch = 0.0
        self.epoch_thing = 0
        self.accuracy = 0.0
        self.average_query_time = 0.0
        self.average_depth = 0.0
        self.mul = (self.view_size[0] / self.img_size[0],
                    self.view_size[1] / self.img_size[1])

        self.lines = {}
        mgx, mgy = np.meshgrid(range(self.img_size[0]),
                               range(self.img_size[1]))
        self.img_mesh = np.asarray(zip(mgx.flatten(), mgy.flatten()))
        self.epoch_meter = {}
        for coord in zip(mgx.flatten(), mgy.flatten()):
            self.epoch_meter[tuple(coord)] = 0
        self.epoch_total = float(len(self.epoch_meter.keys()))
        self.iter = 0
        self.gt_img = generate_image(self.img_size, 15)

        self.gt_tex = Texture.create(size=self.view_size, colorfmt='rgb')
        self.tt_tex = Texture.create(size=self.view_size, colorfmt='rgb')
        gt_buf = array('B')
        tt_buf = array('B')
        gt_resize = self.gt_img.resize(size=self.view_size,
                                       resample=Image.NEAREST)
        for t in gt_resize.getdata():
            gt_buf.extend([t[0], t[1], t[2]])
            tt_buf.extend([255, 255, 255])
        self.gt_tex.blit_buffer(gt_buf, colorfmt='rgb', bufferfmt='ubyte')
        self.tt_tex.blit_buffer(tt_buf, colorfmt='rgb', bufferfmt='ubyte')

        with self.canvas:
            self.gt_rect = Rectangle(texture=self.gt_tex,
                                     pos=(0, 0),
                                     size=self.view_size)
            self.tt_rect = Rectangle(texture=self.tt_tex,
                                     pos=(self.view_size[0], 0),
                                     size=self.view_size)
            self.iter_label = Label(text='', font_size='12sp')
            self.iter_label.color = (0, 0, 0)
            self.iter_label.pos = (self.size[0] * 0.43, self.size[1] * 0.81)
예제 #2
0
    def __init__(self, *args, **kwargs):
        super(LevelProgressBar, self).__init__(*args, **kwargs)

        texture = Texture.create(size=(1, 16))

        size = 1 * 16 * 3

        buf = [
            int(
                Color(.66 - (float(data) / size) * .66, .75, .75,
                      mode='hsv').rgb[data % 3] * 255) for data in range(size)
        ]

        buf = b''.join(map(chr, buf))

        texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

        self.progress_bar = Rectangle(texture=texture)
        self.progress_mask = Rectangle()

        group = InstructionGroup()
        group.add(Color(0, 0, 0))
        group.add(self.progress_mask)

        self.canvas.add(Color(1, 1, 1))
        self.canvas.add(self.progress_bar)
        self.canvas.add(group)

        self.bind(pos=self.redraw, size=self.redraw)
예제 #3
0
def get_texture_from_array(array):
    h, w, _ = array.shape
    texture = Texture.create(size=(w, h))
    texture.blit_buffer(np.flip(array, 0).flatten(),
                        colorfmt='rgb',
                        bufferfmt='float')
    return texture
예제 #4
0
    def __init__(self, *args, **kwargs):
        super(LevelProgressBar, self).__init__(*args, **kwargs)

        texture = Texture.create(size=(1, 16))

        size = 1 * 16 * 3

        buf = [
            int(Color(
                .66 - (float(data) / size) * .66,
                .75,
                .75,
                mode='hsv'
            ).rgb[data % 3] * 255) for data in range(size)
        ]

        buf = b''.join(map(chr, buf))

        texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

        self.progress_bar = Rectangle(texture=texture)
        self.progress_mask = Rectangle()

        group = InstructionGroup()
        group.add(Color(0, 0, 0))
        group.add(self.progress_mask)

        self.canvas.add(Color(1, 1, 1))
        self.canvas.add(self.progress_bar)
        self.canvas.add(group)

        self.bind(pos=self.redraw, size=self.redraw)
예제 #5
0
    def __getitem__(self, item):
        if not self._loaded_textures[item]:
            # first, check if a texture with the same name already exist in the
            # cache
            # pylint: disable-msg=redefined-builtin
            chr = type(self._filename)
            uid = chr(u'%s|%d|%d') % (self._filename, self._mipmap, item)
            texture = Cache.get('kv.texture', uid)

            # if not create it and append to the cache
            if texture is None:
                zfilename = self._index_list[item]
                # read file and store it in mem with fileIO struct around it
                tmpfile = BytesIO(self._zip_file.read(zfilename))
                ext = zfilename.split('.')[-1].lower()
                image = None
                for loader in ImageLoader.loaders:
                    if (ext not in loader.extensions()
                            or not loader.can_load_memory()):
                        continue
                    Logger.debug('Image%s: Load <%s> from <%s>',
                                 loader.__name__[11:], zfilename,
                                 self._filename)
                    try:
                        image = loader(zfilename,
                                       ext=ext,
                                       rawdata=tmpfile,
                                       inline=True)
                    except:  # pylint: disable-msg=bare-except   # noqa
                        # Loader failed, continue trying.
                        continue
                    break
                if image is None:
                    raise AssertionError("Could not load image {} (index {}) "
                                         "from zip {}".format(
                                             zfilename, item, self._filename))

                self.width = image.width
                self.height = image.height

                imagedata = image._data[
                    0]  # pylint: disable-msg=protected-access

                source = '{}{}|'.format(
                    'zip|' if self._filename.endswith('.zip') else '',
                    self._no_cache)
                imagedata.source = chr(source) + uid
                texture = Texture.create_from_data(imagedata,
                                                   mipmap=self._mipmap)
                if not self._no_cache:
                    Cache.append('kv.texture', uid, texture)
                if imagedata.flip_vertical:
                    texture.flip_vertical()

            self._loaded_textures[item] = texture

        return self._loaded_textures[item]
예제 #6
0
    def build(self):
        self.widget = Widget()
        self.sct = mss()
        self.rect = {'top': 0, 'left': 0, 'width': WIDTH, 'height': HEIGHT}
        self.fgbg = cv2.createBackgroundSubtractorMOG2()

        self.texture = Texture.create(size=(WIDTH, HEIGHT))

        Clock.schedule_interval(self.update, 0)

        return self.widget
 def update(self, dt):
     pose = camaracontroller.capturepose()
     self.userinputbox.poselabel.text = "Brazos: " + pose.name
     rostro = camaracontroller.capturegesture()
     self.userinputbox.rostrolabel.text = "Rostro: " + rostro.name
     if SelectorDeIconos.iconoderostro(rostro) is not None:
         self.userinputbox.rostroimage.source = SelectorDeIconos.iconoderostro(rostro)
     buf = camaracontroller.captureposeimage()
     self.soundwave.draw()
     if buf is not False:
         texture1 = Texture.create(size=(640, 480), colorfmt='bgr')
         texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
         self.camara.texture = texture1
예제 #8
0
 def get_texture(self, data):
     bt = data['image']
     full: PillowImage = PillowImage.open(io.BytesIO(bt))
     exif_data = full._getexif()
     angle = 0
     vFlip = True
     hFlip = False
     # is there a rotation?
     rotation = 1
     if exif_data is not None and 274 in exif_data:
         rotation = exif_data[274]
     if rotation == 1:
         full = full.transpose(PillowImage.FLIP_LEFT_RIGHT)
     if rotation == 2:
         full = full.transpose(PillowImage.FLIP_LEFT_RIGHT)
     elif rotation == 3:
         full = full.transpose(PillowImage.ROTATE_180)
     elif rotation == 4:
         pass
     elif rotation == 5:
         full = full.transpose(PillowImage.FLIP_LEFT_RIGHT).transpose(
             PillowImage.ROTATE_270)  #swap 90 and 270
     elif rotation == 6:
         full = full.transpose(PillowImage.FLIP_LEFT_RIGHT).transpose(
             PillowImage.ROTATE_90)  #here too
     elif rotation == 7:
         full = full.transpose(PillowImage.ROTATE_90)
     elif rotation == 8:
         full = full.transpose(PillowImage.FLIP_LEFT_RIGHT).transpose(
             PillowImage.ROTATE_270)
     coreImage = CoreImageData(full.size[0], full.size[1],
                               full.mode.lower(), full.tobytes())
     texture = Texture.create_from_data(coreImage)
     data['angle'] = angle
     data['vflip'] = vFlip
     data['hflip'] = not hFlip
     return texture
예제 #9
0
def create_brush(color=(0, 0, 0, 0), format_c='rgba'):
    tex = Texture.create(size=(10, 10))
    buf = []
    for i in range(100):
        buf += [restriction(c, 0, 255) for c in color]
    tex.blit_buffer(bytes(buf), colorfmt=format_c, bufferfmt='ubyte')
예제 #10
0
    def update(self, dt):
        # Код для калибровки 1 камеры
        if App.get_running_app().root.scrncond.text == 'cal1':
            qr_w = int(App.get_running_app().root.cal1.qr_w.text)
            qr_h = int(App.get_running_app().root.cal1.qr_h.text)
            _, frame = self.capture.read()
            self.delta = Functions.detectMark(frame, qr_w, qr_h)
            texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
            result = cv2.flip(frame, 0)
            texture.blit_buffer(result.tostring(), colorfmt='bgr', bufferfmt='ubyte')
            App.get_running_app().root.cal1.cam.texture = texture
        # Код для одной камеры, экран выделения
        if App.get_running_app().root.scrncond.text == 'onecam':
            _, frame = self.capture.read()
            result = cv2.flip(frame, 0)
            texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
            H_Firstobj = App.get_running_app().root.onecam.wrapper.hue.value
            H_Secondobj = App.get_running_app().root.onecam.wrapper.hue2.value
            saturationFirst = App.get_running_app().root.onecam.wrapper.saturation.value
            saturationSecond = App.get_running_app().root.onecam.wrapper.saturation2.value
            valueFirst = App.get_running_app().root.onecam.wrapper.value.value
            valueSecond = App.get_running_app().root.onecam.wrapper.value2.value
            lowFirst = np.array([H_Firstobj[0], saturationFirst[0], valueFirst[0]])
            highFirst = np.array([H_Firstobj[1], saturationFirst[1], valueFirst[1]])
            lowSecond = np.array([H_Secondobj[0], saturationSecond[0], valueSecond[0]])
            highSecond = np.array([H_Secondobj[1], saturationSecond[1], valueSecond[1]])
            blur = int(App.get_running_app().root.onecam.wrapper.blur.value)
            masksecondobject = Functions.getMask(frame, lowSecond, highSecond, blur)
            maskfirstobject = Functions.getMask(frame, lowFirst, highFirst, blur)
            if saturationFirst == [0, 0] and H_Firstobj == [0, 0] and valueFirst == [0, 0]:
                cv2.destroyWindow('Mask1')
            else:
                Functions.getPoint(maskfirstobject, result, self.PathOfFirstobject, (0, 255, 0))
                cv2.imshow('Mask1', maskfirstobject)
            if saturationSecond == [0, 0] and H_Secondobj == [0, 0] and valueSecond == [0, 0]:

                cv2.destroyWindow('Mask2')
            else:
                Functions.getPoint(masksecondobject, result, self.PathOfSecondobject, (0, 0, 255))
                cv2.imshow('Mask2', masksecondobject)
            texture.blit_buffer(result.tostring(), colorfmt='bgr', bufferfmt='ubyte')
            App.get_running_app().root.onecam.wrapper.cam1.texture = texture

            # Начать запить видео
            if App.get_running_app().root.onecam.wrapper.recbtn.text == 'Пауза':
                if saturationSecond == [0, 0] and H_Secondobj == [0, 0] and valueSecond == [0, 0]:
                    self.rec_pathsecondobject.append([-999, -999, -999])
                else:
                    Functions.getPoint(masksecondobject, result, self.rec_pathsecondobject, (0, 0, 255))
                if saturationFirst == [0, 0] and H_Firstobj == [0, 0] and valueFirst == [0, 0]:
                    self.rec_pathfirstobject.append([-999, -999, -999])
                else:
                    Functions.getPoint(maskfirstobject, result, self.rec_pathfirstobject, (0, 255, 0))
                print(len(self.rec_pathsecondobject),len(self.rec_pathfirstobject))


                self.video_writer.write(result)
                record_is_running = True
                self.timer.append(str(stop))
                self.coord_count += self.coord_count
                App.get_running_app().root.onecam.wrapper.seconds.text = str(stop)
            else:
                record_is_running = False
        if App.get_running_app().root.onecam.wrapper.save_btn.text == 'Сохранено' and App.get_running_app().root.scrncond.text == 'analyse':
            FilePath = cv2.os.getcwd()
            self.distance = App.get_running_app().root.cal1.qr_dist.text
            Param = FilePath + FileName + '.xlsx'
            heightfirst = float(App.get_running_app().root.cal1.heightFirst.text)
            widthfirst = float(App.get_running_app().root.cal1.widthFirst.text)
            self.hypotenuseFirst = float(Functions.hypotenuse(heightfirst, widthfirst))
            heightsecond = float(App.get_running_app().root.cal1.heightSecond.text)
            widthsecond = float(App.get_running_app().root.cal1.widthSecond.text)
            self.hypotenuseSecond = float(Functions.hypotenuse(heightsecond, widthsecond))
            self.MakeNewExcelFile()
            self.workbook.save(Param)
            App.get_running_app().root.onecam.wrapper.save_btn.text = 'Сохранить'
예제 #11
0
 def update_img(self, width, height, img):
     texture = Texture.create(size=(width, height))
     texture.blit_buffer(img.tobytes())
     texture.flip_vertical()
     texture.flip_horizontal()
     self.ids.img.texture = texture