Beispiel #1
0
    def get_overview_tree(self):
        """
        Get overview tree of session-children

        :return: List of QTreeWidgetItems
        """
        top_tree_items = []
        for session in self.sessions:
            tree_item = QTreeWidgetItem([session.name])
            if session.brain:
                epi_path_item = QTreeWidgetItem(['EPI: ' + session.brain.path.split('/')[-1]])
            else:
                epi_path_item = QTreeWidgetItem(['EPI: None'])

            if session.mask:
                mask_path_item = QTreeWidgetItem(['Mask: ' + session.mask.path.split('/')[-1]])
            else:
                mask_path_item = QTreeWidgetItem(['Mask: None'])

            if session.stimuli:
                stim_path_item = QTreeWidgetItem(['Stimuli: ' + session.stimuli.path.split('/')[-1]])
            else:
                stim_path_item = QTreeWidgetItem(['Stimuli: None'])

            tree_item.addChildren([epi_path_item, mask_path_item, stim_path_item])
            top_tree_items.append(tree_item)

        return top_tree_items
Beispiel #2
0
    def get_overview_tree(self):
        top_tree_items = []
        for individual in self.children:
            tree_item = QTreeWidgetItem([individual.name])
            for session in individual.sessions:
                sess_item = QTreeWidgetItem([session.name])
                tree_item.addChild(sess_item)

                if session.brain:
                    epi_path_item = QTreeWidgetItem(
                        ['EPI: ' + session.brain.path.split('/')[-1]])
                else:
                    epi_path_item = QTreeWidgetItem(['EPI: None'])

                if session.mask:
                    mask_path_item = QTreeWidgetItem(
                        ['Mask: ' + session.mask.path.split('/')[-1]])
                else:
                    mask_path_item = QTreeWidgetItem(['Mask: None'])

                if session.stimuli:
                    stim_path_item = QTreeWidgetItem(
                        ['Stimuli: ' + session.stimuli.path.split('/')[-1]])
                else:
                    stim_path_item = QTreeWidgetItem(['Stimuli: None'])

                sess_item.addChildren(
                    [epi_path_item, mask_path_item, stim_path_item])

            top_tree_items.append(tree_item)
        return top_tree_items
Beispiel #3
0
    def get_overview_tree(self):
        top_tree_items = []
        for individual in self.children:
            tree_item = QTreeWidgetItem([individual.name])
            for session in individual.sessions:
                sess_item = QTreeWidgetItem([session.name])
                tree_item.addChild(sess_item)

                if session.brain:
                    epi_path_item = QTreeWidgetItem(['EPI: ' + session.brain.path.split('/')[-1]])
                else:
                    epi_path_item = QTreeWidgetItem(['EPI: None'])

                if session.mask:
                    mask_path_item = QTreeWidgetItem(['Mask: ' + session.mask.path.split('/')[-1]])
                else:
                    mask_path_item = QTreeWidgetItem(['Mask: None'])

                if session.stimuli:
                    stim_path_item = QTreeWidgetItem(['Stimuli: ' + session.stimuli.path.split('/')[-1]])
                else:
                    stim_path_item = QTreeWidgetItem(['Stimuli: None'])

                sess_item.addChildren([epi_path_item, mask_path_item, stim_path_item])

            top_tree_items.append(tree_item)
        return top_tree_items
Beispiel #4
0
 def _add_items(self):
     for iso_idx, (iso_name, iso_iso3) in enumerate(self.isos):
         top_item = QTreeWidgetItem((iso_name, iso_iso3))
         products_per_iso = self.csv_dataset.products_per_iso(iso_iso3)
         _ = [QTreeWidgetItem(x) for x in products_per_iso]
         top_item.addChildren(_)
         self.tree_widget.addTopLevelItem(top_item)
    def generate_tree_model(self, data_dict):
        """Generate a tree model for specified dictionary

        :param data_dict: A dictionary
        :type data_dict: dict
        :return: list of QTreeWidgetItem
        :rtype list:
        """
        widget_items = []
        font = QFont()
        font.setBold(True)
        for key in data_dict.keys():
            entry = data_dict[key]
            key_item = QTreeWidgetItem()
            key_item.setText(0, str(key))
            key_item.setFont(0, font)
            if isinstance(entry, dict):
                items = self.generate_tree_model(entry)
                key_item.addChildren(items)
            else:
                # value_item = QTreeWidgetItem()
                key_item.setText(1, str(entry))
                key_item.setFlags(key_item.flags() | Qt.ItemIsEditable)
                # key_item.addChild(key_item)
            widget_items.append(key_item)

        return widget_items
Beispiel #6
0
 def create_transaction_item(cls, transaction: DNS_Transaction,
                             number: int) -> QTreeWidgetItem:
     """ Takes a DNS_Transaction object and
         builds a tree widget item out of it.
         Args:
             transaction: The transaction
             number: Specifies the index of the
                 transaction in the current context.
     """
     item = super(ChainHistoryWidget,
                  cls).create_transaction_item(transaction, number)
     if not transaction.data == DNS_Data('', '', ''):
         data = QTreeWidgetItem()
         data.setText(0, 'DNS_Operation: ')
         operation, domain, ip = QTreeWidgetItem(), QTreeWidgetItem(
         ), QTreeWidgetItem()
         operation.setText(0, 'Operation')
         operation.setText(1, transaction.data.type)
         domain.setText(0, 'Domain:')
         domain.setText(1, transaction.data.domain_name)
         ip.setText(0, 'IP-Address:')
         ip.setText(1, transaction.data.ip_address)
         data.addChildren([operation, domain, ip])
         item.addChild(data)
     return item
Beispiel #7
0
    def populateTreeWidget(self):
        """ populates the navigation TreeWidget with the records nested 
        within sites. Also populates site_tree_widget with site numbers"""
        # store the current selection(s)
        itemSelected = self.tree_widget.currentItem()
        sites_Selected = self.getSelectSitesToApply()
        sites_Selected = [f'Site {x}' for x in sites_Selected]
        try:
            text = itemSelected.text(0)
        except AttributeError:
            text = 'All Records'
        self.tree_widget.clear()
        self.site_tree_widget.clear()
        fieldNumbers = self.m.getSiteSpecimens()
        siteNumbers = list(set([x[0] for x in fieldNumbers]))
        try:
            siteNumbers.sort(key=int)
        except ValueError:
            pass
        # build a hierarchical structure of QTreeWidgetItem(s) to fill the tree with
        self.tree_widget.addTopLevelItem(QTreeWidgetItem(["All Records"]))
        for siteNum in siteNumbers:
            site_tree_text = f'Site {siteNum}'
            site_tree_item = QTreeWidgetItem([site_tree_text])
            if site_tree_text in sites_Selected:
                site_tree_item.setCheckState(
                    0, Qt.Checked)  # update site_tree_widget
            else:
                site_tree_item.setCheckState(
                    0, Qt.Unchecked)  # update site_tree_widget
            self.site_tree_widget.addTopLevelItems(
                [site_tree_item])  # fill in site_tree_widget

            # now start on the navigation "tree_widget" object.
            specimenNumbers = list(
                set([y for x, y in fieldNumbers if x == siteNum and y != '#']))
            specimenNumbers.sort(key=int)
            site = QTreeWidgetItem(
                [f'Site {siteNum} ({len(specimenNumbers)})'])
            siteChildren = []
            for i in specimenNumbers:
                # where i is a specimen number for a site
                label = [f'{siteNum}-{i}']
                child = QTreeWidgetItem(label)
                siteChildren.append(child)
            site.addChildren(siteChildren)
            # add the list of sites (with children) to the master list
            self.tree_widget.addTopLevelItems([site])
        # return to the selection (if it exists)
        self.selectTreeWidgetItemByName(text)
Beispiel #8
0
def grow_tree(dct):
    items = []
    for i in top:
        item = QTreeWidgetItem([i])
        item.setIcon(0, folderIcon)
        if i in dct["low"]:
            childs = []
            for child in dct["low"][i]:
                j = QTreeWidgetItem([child])
                j.setIcon(0, folderIcon)
                childs.append(j)
            item.addChildren(childs)
        items.append(item)
    tree.addTopLevelItems(items)
Beispiel #9
0
 def grow_tree(self, folders):
     items = []
     folderIcon = QIcon("./graphics/folder.jpeg")
     for folder in folders:
         item = QTreeWidgetItem([folder])
         item.setIcon(0, folderIcon)
         if folders[folder] != 0:
             childs = []
             for sub in folders[folder]:
                 s = QTreeWidgetItem([sub])
                 s.setIcon(0, folderIcon)
                 childs.append(s)
             item.addChildren(childs)
         items.append(item)
     self.dui.treeW.addTopLevelItems(items)
Beispiel #10
0
    def create_transaction_item(cls, transaction: DDosTransaction,
                                number: int) -> QTreeWidgetItem:
        """ Takes a DDosTransaction object and builds
            a tree widget item from it.
            Args:
                  transaction: The given transaction
                  number: Specifies the number of the
                    transaction in the current context
        """
        item = QTreeWidgetItem()
        item.setText(0, 'Transaction')
        item.setText(1, '#' + str(number))
        sender = QTreeWidgetItem()
        sender.setText(0, 'Sender:')
        sender.setText(1, str(transaction.sender))
        t_timestamp = QTreeWidgetItem()
        t_timestamp.setText(0, 'Timestamp:')
        t_timestamp.setText(
            1,
            str(
                time.strftime("%d.%m.%Y %H:%M:%S %Z",
                              time.gmtime(transaction.timestamp))))
        signature = QTreeWidgetItem()
        signature.setText(0, 'Signature')
        signature.setText(1, str(transaction.signature))

        data = QTreeWidgetItem()
        data.setText(0, 'Data:')

        d_type = QTreeWidgetItem()
        d_type.setText(0, 'Type:')
        d_type.setText(1, transaction.data.type)

        d_data = QTreeWidgetItem()
        d_data.setText(0, 'Data:')
        d_data.setText(1, str(transaction.data.data))

        data.addChildren([d_type, d_data])

        item.addChildren([sender, t_timestamp, data, signature])
        return item
Beispiel #11
0
    def type_tree(self, name, root):
        if root.children[0].data == 'primitive_type':
            return QTreeWidgetItem([name, root.children[0].children[0].value])
        elif root.children[0].data == 'row_type':
            root_widget = QTreeWidgetItem([name, 'row'])
            for i in range(len(root.children[0].children) // 2):
                name = root.children[0].children[i * 2].value
                child_type = root.children[0].children[i * 2 + 1]
                root_widget.addChild(self.type_tree(name, child_type))
            return root_widget
        elif root.children[0].data == 'array_type':
            if root.children[0].children[0].children[
                    0].data == 'primitive_type':
                return QTreeWidgetItem([
                    name, 'array(' +
                    root.children[0].children[0].children[0].children[0].value
                    + ')'
                ])
            else:
                root_widget = QTreeWidgetItem([name, 'array(row)'])
                for i in range(
                        len(root.children[0].children[0].children[0].children)
                        // 2):
                    name = root.children[0].children[0].children[0].children[
                        i * 2].value
                    child_type = root.children[0].children[0].children[
                        0].children[i * 2 + 1]
                    root_widget.addChild(self.type_tree(name, child_type))
                return root_widget

        elif root.children[0].data == 'map_type':
            root_widget = QTreeWidgetItem([name, 'map'])
            key = self.type_tree('_key', root.children[0].children[0])
            value = self.type_tree('_value', root.children[0].children[1])
            root_widget.addChildren([key, value])
            return root_widget
        else:
            pass
    def setupTab6(self, tab):
        """Advance widgets for preview panel"""
        container = QHBoxLayout()
        scrollArea = QScrollArea()
        scrollArea.setWidgetResizable(True)
        w = QWidget()
        w.setMinimumSize(QSize(400, 500))
        layout = QVBoxLayout()
        w.setLayout(layout)
        scrollArea.setWidget(w)
        container.addWidget(scrollArea)
        tab.setLayout(container)

        # List
        lay = QHBoxLayout()
        layout.addLayout(lay)
        list1 = QListWidget()
        list1.addItems(["aaa", "bbb", "ccc"])
        list2 = QListWidget()
        list2.addItem(
            QListWidgetItem(QIcon(":appres.img/Flag_blueHS.png"), "blue"))
        list2.addItem(
            QListWidgetItem(QIcon(":appres.img/Flag_redHS.png"), "red"))
        list2.addItem(
            QListWidgetItem(QIcon(":appres.img/Flag_greenHS.png"), "green"))
        list2.setViewMode(QListWidget.IconMode)
        lay.addWidget(list1)
        lay.addWidget(list2)

        # Table
        lay = QHBoxLayout()
        layout.addLayout(lay)
        t1 = QTableWidget()
        t1.setRowCount(3)
        t1.setColumnCount(3)
        for i in range(3):
            for j in range(3):
                t1.setItem(i, j, QTableWidgetItem(str((i + 1) * (j + 1))))
                t1.item(i, j).setTextAlignment(Qt.AlignCenter)
        t1.setColumnWidth(0, 50)
        t1.setColumnWidth(1, 50)
        t1.setColumnWidth(2, 50)
        t1.setEditTriggers(QTableWidget.AllEditTriggers)
        t2 = QTableWidget()
        t2.setRowCount(3)
        t2.setColumnCount(3)
        t2.setHorizontalHeaderLabels(["Name", "Gender", "Age"])
        t2.setVerticalHeaderLabels(["1st", "2rd", "3th"])
        t2.setItem(0, 0, QTableWidgetItem("july"))
        c = QComboBox()
        c.addItems(["Male", "Famale"])
        t2.setCellWidget(0, 1, c)
        t2.cellWidget(0, 1).setCurrentIndex(1)
        t2.setItem(0, 2, QTableWidgetItem("10"))
        t2.setItem(1, 0, QTableWidgetItem("john"))
        c = QComboBox()
        c.addItems(["Male", "Famale"])
        c.setEditable(True)
        t2.setCellWidget(1, 1, c)
        t2.setItem(1, 2, QTableWidgetItem("11"))
        t2.resizeColumnsToContents()
        t2.setEditTriggers(QTableWidget.EditKeyPressed
                           | QTableWidget.SelectedClicked
                           | QTableWidget.AnyKeyPressed
                           | QTableWidget.DoubleClicked)

        lay.addWidget(t1)
        lay.addWidget(t2)

        # Tree
        lay = QHBoxLayout()
        layout.addLayout(lay)
        tree1 = QTreeWidget()
        tree1.setColumnCount(2)
        tree1.setHeaderLabels(["Key", "Value"])
        node1 = QTreeWidgetItem()
        node1.setText(0, "root")
        node1.setText(1, "0")
        node1.setIcon(0, QIcon(":appres.img/home.png"))
        tree1.addTopLevelItem(node1)
        node11 = QTreeWidgetItem()
        node11.setText(0, "child1")
        icon = QIcon(":appres.img/book_angle.png")
        icon.addPixmap(QPixmap(":appres.img/book_open.png"), QIcon.Normal,
                       QIcon.On)
        node11.setIcon(0, icon)
        nodea = QTreeWidgetItem()
        nodea.setText(0, "red")
        nodea.setBackground(1, QBrush(Qt.red))
        nodeb = QTreeWidgetItem()
        nodeb.setText(0, "gray")
        nodeb.setBackground(1, QBrush(Qt.gray))
        nodec = QTreeWidgetItem()
        nodec.setText(0, "green")
        nodec.setBackground(1, QBrush(Qt.green))
        node11.addChildren([nodea, nodeb, nodec])
        node12 = QTreeWidgetItem()
        node12.setText(0, "child2")
        node12.setText(1, "child2")
        node13 = QTreeWidgetItem()
        node13.setText(0, "child3")
        node13.setText(1, "child3")
        node12.setIcon(0, icon)
        node13.setIcon(0, icon)
        node1.addChild(node11)
        node1.addChild(node12)
        node1.addChild(node13)
        tree1.expand(tree1.model().index(0, 0))
        tree1.expandItem(node11)
        tree2 = QTreeView()
        folder = QDirModel()
        tree2.setModel(folder)
        lay.addWidget(tree1)
        lay.addWidget(tree2)
Beispiel #13
0
    def face_rec(self, image):
        """
        Nhận diện dáng người và tay từ ảnh đã cho
        :param image: ảnh từ camera
        :return: image: ảnh đuọc xử lý sau khi nhận diện
        """
        width = image.shape[1]
        height = image.shape[0]

        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        raw_img = image
        image = self.process_frame(image)

        # Bắt đầu nhận diện
        faces = self.face.process(raw_img)
        hands = self.hand.process(raw_img)

        image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

        if not faces.multi_face_landmarks:
            self.Warnings_List.clear()
            return image

        count = 0
        for face_landmarks in faces.multi_face_landmarks:
            if self.settings.print_results:
                draw_landmarks(image, face_landmarks,
                               mp.solutions.face_mesh.FACEMESH_CONTOURS)
            """
            nose_tip 1
            chin = 199
            left_eye_outer = 249
            right_eye_outer = 7
            mouth_left = 291
            mouth_right = 61
            """
            nose_tip = normalize_to_pixel_coordinates(
                face_landmarks.landmark[1].x, face_landmarks.landmark[1].y,
                width, height)
            chin = normalize_to_pixel_coordinates(
                face_landmarks.landmark[199].x, face_landmarks.landmark[199].y,
                width, height)
            left_eye_outer = normalize_to_pixel_coordinates(
                face_landmarks.landmark[249].x, face_landmarks.landmark[249].y,
                width, height)
            right_eye_outer = normalize_to_pixel_coordinates(
                face_landmarks.landmark[7].x, face_landmarks.landmark[7].y,
                width, height)
            mouth_left = normalize_to_pixel_coordinates(
                face_landmarks.landmark[291].x, face_landmarks.landmark[291].y,
                width, height)
            mouth_right = normalize_to_pixel_coordinates(
                face_landmarks.landmark[61].x, face_landmarks.landmark[61].y,
                width, height)

            if chin is None or left_eye_outer is None or right_eye_outer is None or mouth_left is None or mouth_right is None:
                return image

            image_points = np.array([
                nose_tip, chin, left_eye_outer, right_eye_outer, mouth_left,
                mouth_right
            ],
                                    dtype="double")

            focal_length = width
            camera_matrix = np.array(
                [[focal_length, 0, width / 2], [0, focal_length, height / 2],
                 [0, 0, 1]],
                dtype="double")

            dist_coeffs = np.zeros((4, 1))
            (success, rotation_vector,
             translation_vector) = cv2.solvePnP(model_points,
                                                image_points,
                                                camera_matrix,
                                                dist_coeffs,
                                                flags=cv2.SOLVEPNP_ITERATIVE)

            if self.Warnings_List.topLevelItemCount() <= count:
                item = QTreeWidgetItem(["Thí sinh #" + str(count + 1)])
                item.addChildren([QTreeWidgetItem(), QTreeWidgetItem()])
                self.Warnings_List.addTopLevelItem(item)
                self.Warnings_List.topLevelItem(count).setExpanded(True)

            rotation_mat, _ = cv2.Rodrigues(rotation_vector)
            pose_mat = cv2.hconcat((rotation_mat, translation_vector))
            _, _, _, _, _, _, euler_angles = cv2.decomposeProjectionMatrix(
                pose_mat)
            angle = round(abs(euler_angles[1][0]), 2)
            self.Warnings_List.topLevelItem(count).child(0).setText(
                0, "Đầu di chuyển ngang " + str(angle) + " độ so với camera")
            color = int(angle / self.settings.head_angle_limit * 255)
            if color > 255:
                if self.prev_waring_code_1 != 3:
                    self.warnings.append(
                        QDateTime.currentDateTime().toString() + " - " +
                        "Thí sinh #" + str(count + 1) +
                        " - : Đầu di chuyển ngang " + str(angle) +
                        " độ so với camera")
                    self.prev_waring_code_1 = 3
                color = 255
            self.Warnings_List.topLevelItem(count).child(0).setBackground(
                0, QColor(color, 255 - color, 0))

            angle = round(abs(euler_angles[2][0]), 2)
            self.Warnings_List.topLevelItem(count).child(1).setText(
                0, "Đầu di chuyển dọc " + str(angle) + " độ so với camera")
            color = int(angle / self.settings.head_angle_limit * 255)
            if color > 255:
                if self.prev_waring_code_2 != 5:
                    self.warnings.append(
                        QDateTime.currentDateTime().toString() + " - " +
                        "Thí sinh #" + str(count + 1) +
                        " - : Đầu di chuyển dọc " + str(angle) +
                        " độ so với camera")
                    self.prev_waring_code_2 = 5
                color = 255
            self.Warnings_List.topLevelItem(count).child(1).setBackground(
                0, QColor(color, 255 - color, 0))

            if self.settings.print_results:
                (nose_end_point2D,
                 jacobian) = cv2.projectPoints(np.array([
                     (0.0, 0.0, 500.0)
                 ]), rotation_vector, translation_vector, camera_matrix,
                                               dist_coeffs)
                '''
                for p in image_points:
                    cv2.circle(image, (int(p[0]), int(p[1])), 2, (0, 0, 255), -1)
                '''

                cv2.line(image,
                         (int(image_points[0][0]), int(image_points[0][1])),
                         (int(nose_end_point2D[0][0][0]),
                          int(nose_end_point2D[0][0][1])), (255, 0, 0), 2)
            count += 1

        while self.Warnings_List.topLevelItemCount() > len(
                faces.multi_face_landmarks):
            self.Warnings_List.takeTopLevelItem(len(
                faces.multi_face_landmarks))

        if not hands.multi_hand_landmarks:
            for i in range(len(faces.multi_face_landmarks)):
                if self.Warnings_List.topLevelItem(i).childCount() == 2:
                    self.Warnings_List.topLevelItem(i).addChild(
                        QTreeWidgetItem())
                self.Warnings_List.topLevelItem(i).child(2).setText(
                    0, "Không tìm thấy tay!")
                self.Warnings_List.topLevelItem(i).child(2).setBackground(
                    0, QColor("red"))
                if self.prev_waring_code != 0:
                    self.warnings.append(
                        QDateTime.currentDateTime().toString() + " - " +
                        "Thí sinh #" + str(i + 1) + " - : Không tìm thấy tay!")
                    self.prev_waring_code = 0
            return image

        face_list = {}
        for hand_landmarks in hands.multi_hand_landmarks:
            if self.settings.print_results:
                draw_landmarks(image, hand_landmarks,
                               mp.solutions.hands.HAND_CONNECTIONS)

            hand_x = hand_landmarks.landmark[0].x
            hand_y = hand_landmarks.landmark[0].y

            best_face = -1
            best_face_value = 1

            count = 0
            for face_landmarks in faces.multi_face_landmarks:
                if count in face_list and face_list[count] == 2:
                    count += 1
                    continue
                face_x = face_landmarks.landmark[0].x
                face_y = face_landmarks.landmark[0].y
                dist = math.sqrt(
                    pow(abs(face_x - hand_x), 2) +
                    pow(abs(face_y - hand_y), 2))
                if dist < best_face_value:
                    best_face_value = dist
                    best_face = count
                count += 1
            if best_face != -1:
                if best_face in face_list:
                    face_list[best_face] = 2
                else:
                    face_list[best_face] = 1

        for i in range(len(faces.multi_face_landmarks)):
            if self.Warnings_List.topLevelItem(i).childCount() == 2:
                self.Warnings_List.topLevelItem(i).addChild(QTreeWidgetItem())
            if i in face_list:
                if face_list[i] == 1:
                    self.Warnings_List.topLevelItem(i).child(2).setText(
                        0, "Chỉ phát hiện được một tay!")
                    self.Warnings_List.topLevelItem(i).child(2).setBackground(
                        0, QColor("yellow"))
                    if self.prev_waring_code != 1:
                        self.warnings.append(
                            QDateTime.currentDateTime().toString() + " - " +
                            "Thí sinh #" + str(count + 1) +
                            " - Chỉ phát hiện được một tay!")
                        self.prev_waring_code = 1
                else:
                    if self.Warnings_List.topLevelItem(i).childCount() == 3:
                        self.Warnings_List.topLevelItem(i).takeChild(2)
            else:
                self.Warnings_List.topLevelItem(i).child(2).setText(
                    0, "Không tìm thấy tay!")
                self.Warnings_List.topLevelItem(i).child(2).setBackground(
                    0, QColor("red"))
                if self.prev_waring_code != 0:
                    self.warnings.append(
                        QDateTime.currentDateTime().toString() + " - " +
                        "Thí sinh #" + str(count + 1) +
                        " - : Không tìm thấy tay!")
                    self.prev_waring_code = 0
        """
        blob = cv2.dnn.blobFromImage(raw_img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
        self.net.setInput(blob)
        outs = self.net.forward(get_output_layers(self.net))

        class_ids = []
        confidences = []
        boxes = []

        for out in outs:
            for detection in out:
                scores = detection[5:]
                class_id = np.argmax(scores)
                confidence = scores[class_id]
                if confidence > 0.5:
                    center_x = int(detection[0] * width)
                    center_y = int(detection[1] * height)
                    w = int(detection[2] * width)
                    h = int(detection[3] * height)
                    x = center_x - w / 2
                    y = center_y - h / 2
                    class_ids.append(class_id)
                    confidences.append(float(confidence))
                    boxes.append([x, y, w, h])

        indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)

        for i in indices:
            i = i[0]
            box = boxes[i]
            x = box[0]
            y = box[1]
            w = box[2]
            h = box[3]

            color = self.colors[class_ids[i]]
            cv2.rectangle(image, (x, y), (x + w, y + h), color, 2)
            cv2.putText(image, str(self.classes[class_ids[i]]), (x - 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color,
                        2)
        """
        return image