Exemplo n.º 1
0
 def distanceHist(self,
                  another,
                  method=sci_dist.euclidean,
                  hist_size=None,
                  gray=False,
                  show=True):
     if hist_size is None:
         hist_size = [256]
     assert isinstance(method,
                       types.FunctionType), 'method should be a function!'
     if isinstance(another, np.ndarray):
         another = self.__class__(another)
     elif isinstance(another, type(self)):
         assert self.org().shape == another.org(
         ).shape, 'The shapes should be the same!'
     else:
         assert False, f'Another should be a numpy.ndarray or {type(self)}'
     hist_self = self.hist(show, hist_size=hist_size)
     hist_another = another.hist(show, hist_size=hist_size)
     if gray:
         d = method(hist_self[-1].transpose(), hist_another[-1].transpose())
     else:
         assert len(hist_self) == len(
             hist_another) == 4, 'color mode needs three channels image!'
         d = []
         for c in range(3):
             d.append(
                 method(hist_self[c].transpose(),
                        hist_another[c].transpose()))
         d = mean(d)
     full_size = self.gray().org().size
     ratio = d / full_size
     logger.debug(d, full_size, ratio)
     return d, full_size, ratio
Exemplo n.º 2
0
 def slot_start(self):
     logger.debug('')
     if self.media_model is None:
         return
     self.media_model.start(clear_schedule=True)
     self.mw.btn_play.setText('Pause')
     self.mw.btn_play.setShortcut(QKeySequence(' '))
Exemplo n.º 3
0
 def checkOutput(cls, command):
     """执行命令,返回运行结果,不打印。执行错误抛出异常
     """
     logger.debug(command)
     output = subprocess.check_output(command, shell=True)
     encoding = 'gbk' if platform.system() == 'Windows' else 'utf-8'
     return output.decode(encoding)
Exemplo n.º 4
0
 def slot_pause(self):
     logger.debug('')
     if self.media_model is None:
         return
     self.media_model.pause()
     self.mw.btn_play.setText('Play')
     self.mw.btn_play.setShortcut(QKeySequence(' '))
Exemplo n.º 5
0
 def select_label(self, label: ActionLabel):
     logger.debug(label)
     logger.debug(QRect(label.begin, label.timeline_row, label.end - label.begin + 1, 1))
     self.selectionModel().select(
         QItemSelection(self.model().index(label.timeline_row, label.begin),
                        self.model().index(label.timeline_row, label.end)),
         QItemSelectionModel.ClearAndSelect)
Exemplo n.º 6
0
 def _callExtractorCore(self, img):
     self.datum.cvInputData = img
     self.opWrapper.emplaceAndPop([self.datum])
     logger.debug(self.datum.poseKeypoints)
     return Poses(self.datum.poseKeypoints,
                  self.pose_type), DatumPickleable(self.datum,
                                                   self.pose_type)
Exemplo n.º 7
0
    def _startProducingImgs(self):
        # _newProcessToSeedVideoFrames:
        current_process = psutil.Process()
        children = current_process.children(recursive=True)
        logger.debug(f'parent pid: {current_process.pid}')
        logger.debug(f'children pids: {[c.pid for c in children]}')

        def _loadVideo(path, indices, queue):
            gen_name_img = Video(path).info().readDict(indices=indices,
                                                       yield_=True)
            try:
                while True:
                    if queue.full():
                        time.sleep(1)
                    else:
                        name, img = next(gen_name_img)
                        # self.require_show(img,title=f'{name}:org')
                        img = self._execPrepHooks(img, name)
                        queue.put((name, img))
            except StopIteration:
                queue.put('DONE')

        pw = Process(target=_loadVideo,
                     args=(self.media.fname, self.indices,
                           self.queue_name_img_tuple),
                     name='imgs_producer_process')
        pw.daemon = True
        pw.start()
Exemplo n.º 8
0
 def _filterOutDuplicatePose(
         self, pose_score_entities: List[PoseScore]) -> List[PoseScore]:
     # poses_entities param should be a entities list, and every element's first position should be a pose
     true_means_keep = [True] * len(pose_score_entities)
     for i, pose_score_entity_i in enumerate(pose_score_entities):
         p_i, p_i_score = pose_score_entity_i.pose, pose_score_entity_i.points_scores_sum_after_re_pu
         p_i_x = p_i.key_points[..., 0]
         p_i_x_b = p_i_x > 0
         for j, pose_score_entity_j in enumerate(pose_score_entities[i +
                                                                     1:]):
             p_j, p_j_score = pose_score_entity_j.pose, pose_score_entity_j.points_scores_sum_after_re_pu
             p_j_x = p_j.key_points[..., 0]
             p_j_x_b = p_j_x > 0
             p_i_j_x_b = np.logical_and(p_i_x_b, p_j_x_b)
             if_exceed_this_then_remove = min(p_i_x_b.sum(),
                                              p_j_x_b.sum()) * 0.6
             points_dis_thre = 0.05 * (p_i.torsoHeight() if p_i_score >
                                       p_i_score else p_j.torsoHeight())
             if (np.abs((p_i_x - p_j_x)[p_i_j_x_b]) <
                     points_dis_thre).sum() > if_exceed_this_then_remove:
                 index_to_remove = i + 1 + j if p_i_score >= p_j_score else i
                 true_means_keep[index_to_remove] = False
                 logger.debug(
                     f'Removing duplicate pose: {pose_score_entities[index_to_remove]}'
                 )
     return [
         pose_score_entities[i] for i in range(len(true_means_keep))
         if true_means_keep[i]
     ]
Exemplo n.º 9
0
 def start(self, clear_schedule=False):
     logger.debug('')
     self._flag_playing = True
     if clear_schedule:
         self.scheduled.clear()
     if not self.timer.isActive():
         self.timer.start()
Exemplo n.º 10
0
    def rebuildFromRoiDatum(cls, img, roi_datum_tuple_list,
                            model_type: Type[BasePose]):
        datum_rebuild = namedtuple(
            'datum_rebuild', ['poseKeypoints', 'cvInputData', 'cvOutputData'])
        datum_rebuild.cvInputData = img
        img_fill = np.copy(img)
        datums_pk = []
        for roi_rect, datum in roi_datum_tuple_list:
            if datum.poseKeypoints.shape == ():
                add_one_zero_pose = np.expand_dims(
                    model_type.newZeroPose(False).key_points, axis=0)
                datums_pk.append(add_one_zero_pose)
                continue

            ymin, xmin, ymax, xmax = roi_rect.toInt().yxyx
            img_fill[ymin:ymax, xmin:xmax] = datum.cvOutputData
            pks_incr = np.zeros(datum.poseKeypoints.shape, dtype=np.float32)
            pks_incr[..., 0] = roi_rect.c_l
            pks_incr[..., 1] = roi_rect.r_t
            pks_incr[datum.poseKeypoints == 0] = 0
            datums_pk.append(datum.poseKeypoints + pks_incr)
        logger.debug([d.shape for d in datums_pk])
        datum_rebuild.poseKeypoints = np.vstack(
            datums_pk) if datums_pk else np.array(0.0)
        datum_rebuild.cvOutputData = img_fill
        return cls(datum_rebuild, model_type)
Exemplo n.º 11
0
 def slot_export_labeled(self):
     logger.debug('')
     video_obj = PlayingUnit.only_ins.video_model
     video_info = video_obj and video_obj.get_info()
     video_uri = video_info and video_info['fname']
     video_name = video_uri and os.path.basename(video_uri)
     save_as = CommonUnit.get_save_name(f'{video_name}.json')
     if not save_as:
         return
     pose_obj = PlayingUnit.only_ins.pose_model
     pose_file_uri = pose_obj and pose_obj.file.uri
     pose_file_md5 = pose_file_uri and FileHelper.hashOfFile(pose_file_uri)
     json_file_labels = JsonFileLabels()
     json_file_labels['video_info.uri'] = video_uri
     json_file_labels[
         'video_info.hash_md5'] = video_uri and FileHelper.hashOfFile(
             video_uri)
     json_file_labels['video_info.w'] = video_info and video_info['width']
     json_file_labels['video_info.h'] = video_info and video_info['height']
     json_file_labels['pose_info.uri'] = pose_file_uri
     json_file_labels['pose_info.hash_md5'] = pose_file_md5
     json_file_labels['labels'] = {
         i + 1: {
             'action': label.action,
             'begin': label.begin,
             'end': label.end,
             'pose_index': label.pose_index,
         }
         for i, label in enumerate(self.mw.table_labeled.get_all_labels())
     }
     json_file_labels.dump(save_as)
Exemplo n.º 12
0
 def slot_label_created(self, action_label: ActionLabel, emitter):
     logger.debug(f'{action_label}, {emitter}')
     self._label_cells_delete({
         action_label.timeline_row:
         list(range(action_label.begin, action_label.end + 1))
     })
     row_i = self.add_label(action_label)
     self._select_row(row_i)
Exemplo n.º 13
0
    def eventFilter(self, source, event):
        if source == self.mw.label_show:
            if event.type() == QEvent.MouseButtonPress:
                logger.debug(source)
                logger.debug(event)
                self.slot_play_toggle()

        return False
Exemplo n.º 14
0
 def slot_cellPressed(self, qindex):
     r, c = qindex.row(), qindex.column()
     logger.debug(f'{r}, {c}, {self.model().item(r, c)}')
     if not self.model().item(r, c):
         item = QStandardItem('')
         item.setBackground(Qt.white)
         self.model().setItem(r, c, item)
     self.entry_cell_pos = (r, c)
Exemplo n.º 15
0
 def load(cls, path):
     logger.debug(path)
     with open(path, 'r', encoding='utf-8') as f:
         content = json.load(f)
     obj = cls()
     obj.setPath(path)
     obj.content = ZDict(content)
     obj.load_hooks()
     return obj
Exemplo n.º 16
0
 def load(cls, path):
     with open(path, 'r') as f:
         content = f.read()
     obj = cls()
     obj.setPath(path)
     obj.content = content
     obj.load_hooks()
     logger.debug(f'{path} load finished.')
     return obj
Exemplo n.º 17
0
 def closeEvent(self, e: QCloseEvent):
     logger.debug('')
     if self.table_labeled.rowCount() \
             and QMessageBox.Ok != QMessageBox.information(self, 'ActionLabeller',
                                                           "Are you sure to quit, the unsaved labels will be lost?",
                                                           QMessageBox.Ok | QMessageBox.Cancel,
                                                           QMessageBox.Cancel):
         e.ignore()
     logger.debug('Main window closed.')
Exemplo n.º 18
0
 def enhanceBrightnessTo(self, target_brightness):
     org_brightness = self.brightness()
     factor = target_brightness / org_brightness + 0.1
     enhancer = PIL.ImageEnhance.Brightness(self.org())
     enhanced_img = enhancer.enhance(factor)
     self._img = enhanced_img
     logger.debug(f'original brightness is {org_brightness}')
     logger.debug(f'enhanced brightness is {self.brightness()}')
     return self
Exemplo n.º 19
0
    def keyReleaseEvent(self, e: QKeyEvent) -> None:
        if self.state() == QAbstractItemView.EditingState:
            return

        logger.debug(e.key())
        if e.key() in [Qt.Key_Backspace, Qt.Key_D]:
            rows, labels = self._labels_selected()
            mySignals.labeled_delete.emit(labels, MySignals.Emitter.T_LABELED)
            self._delete_rows(rows)
Exemplo n.º 20
0
 def slot_xml_template(self):
     logger.debug('')
     layout = QGridLayout()
     layout.addWidget(QTextBrowser())
     layout.setContentsMargins(2, 2, 2, 2)
     dialog = QDialog(self.mw, flags=Qt.Dialog)
     dialog.setFixedSize(QSize(400, 300))
     dialog.setLayout(layout)
     dialog.setContentsMargins(2, 2, 2, 2)
     dialog.exec_()
Exemplo n.º 21
0
 def detectBoxer(self):
     assert self._boxer_detector, 'boxer_detector is None'
     self._startProducingImgs()
     res = []
     while True:
         got = self.queue_name_img_tuple.get()
         if got == 'DONE': break
         res.append(self._detectBoxer(got))
     logger.debug(res)
     return res
Exemplo n.º 22
0
 def timed(*args, **kw):
     ts = time.time()
     result = method(*args, **kw)
     te = time.time()
     if 'log_time' in kw:
         name = kw.get('log_name', method.__name__.upper())
         kw['log_time'][name] = int((te - ts) * 1000)
     else:
         logger.debug('Timeit:: %r :: %f s' % (method.__name__, (te - ts)))
     return result
Exemplo n.º 23
0
 def slot_cellClicked(self, qindex):
     r, c = qindex.row(), qindex.column()
     logger.debug(f'{r}, {c}')
     label = self.detect_label(r, c)
     if label is None:
         self.label_clicked = None
     else:
         self.label_clicked = label
         self.select_label(label)
         mySignals.label_selected.emit(label, MySignals.Emitter.T_LABEL)
Exemplo n.º 24
0
 def estimatePose(self):
     assert self._pose_estimator, '_pose_estimator is None'
     self._startProducingImgs()
     res = []
     while True:
         got = self.queue_name_img_tuple.get()
         if got == 'DONE': break
         res.append(self._estimatePose(got))
     logger.debug(res)
     return res
Exemplo n.º 25
0
 def table_timeline_cell_double_clicked(self, qindex):
     logger.debug('')
     r, c = qindex.row(), qindex.column()
     label = self.mw.table_timeline.detect_label(r, c)  # type:ActionLabel
     if not label:
         self.mw.table_timeline.col_to_center(
             self.mw.table_timeline.current_column)
         CommonUnit.status_prompt(
             str(f'Current Frame {self.mw.table_timeline.current_column}'))
         self.mw.table_timeline.label_create_dialog.exec_()
Exemplo n.º 26
0
 def _commit_label(self, label: ActionLabel) -> BResult:
     logger.debug(label)
     bresult = label.is_valid(['action', 'action_id', 'color', 'begin', 'end'])
     if not bresult:
         self.parent.status_prompt(bresult, True)
         return bresult
     if self.parent.settle_label(label) is None:
         return BResult(False, 'label settle failed.')
     mySignals.label_created.emit(label, MySignals.Emitter.T_LABEL)
     return BResult(True)
Exemplo n.º 27
0
 def keyReleaseEvent(self, e: QKeyEvent) -> None:
     logger.debug(e.key())
     if e.key() == Qt.Key_Control:
         self.key_control_pressing = False
     elif e.key() in [Qt.Key_Backspace, Qt.Key_D]:
         cells_deleted = self._del_selected_label_cells()
         mySignals.label_cells_delete.emit(cells_deleted, MySignals.Emitter.T_LABEL)
     elif e.key() == Qt.Key_R:
         if self.label_clicked is not None:
             self._label_play(self.label_clicked)
Exemplo n.º 28
0
 def enhanceBrightnessTo(self, target_brightness):
     org_brightness = self.brightness()
     img = PIL.Image.fromarray(self.org())
     factor = target_brightness / self.brightness() + 0.1
     enhancer = PIL.ImageEnhance.Brightness(img)
     enhanced_img = enhancer.enhance(factor)
     self._img = ImgArray(np.asarray(enhanced_img))
     logger.debug(f'original brightness is {org_brightness}')
     logger.debug(f'enhanced brightness is {self.brightness()}')
     return self
Exemplo n.º 29
0
 def slot_play_toggle(self):
     if self.media_model is None:
         logger.debug('media_model is None.')
         return
     if self.media_model.is_playing():
         logger.info('pause.')
         self.slot_pause()
     else:
         logger.info('start.')
         self.slot_start()
Exemplo n.º 30
0
 def get_all_actions(self):
     logger.debug('')
     actions = []
     for r in range(self.rowCount()):
         try:
             actions.append(self.RowAction(r).to_action())
         except AttributeError as e:
             pass
         except Exception as e:
             logger.error(e.__str__())
     return actions