Пример #1
0
class Objectdetecter:
    def __init__(self):
        self.detecter = Detecter()
        self.detecter.setup(
            './data/ssd_mobilenet_v1/frozen_inference_graph.pb',
            './data/label_map.pbtxt')
        self.THRESHOLD = 0.8

    def __check(self, image):
        detect_image = np.copy(image)
        image = np.expand_dims(image, axis=0)
        (boxes, scores, classes, num) = self.detecter.detect(image)
        list = []
        self.detecter.viaulize(detect_image, boxes, classes, scores,
                               self.THRESHOLD)
        for output in zip(classes, scores, boxes):
            if output[1] >= self.THRESHOLD:
                y1, x1, y2, x2 = output[2]
                y = int((y2 - y1) * 480)
                list.append((output, y))

        return list, detect_image

    def order(self, image):
        lists, detect_image = self.__check(image)

        sign = 5
        tra = 5
        st = 300
        fw = 5

        for list in lists:
            if list[0][0] == 5:
                c = list[1]
                if c > sign:
                    return 'stopsign', detect_image

            elif list[0][0] == 6:
                c = list[1]
                if c > tra:
                    return 'trash', detect_image

            elif list[0][0] == 1:
                c = list[1]
                if c < st:
                    return 'stop', detect_image

            elif list[0][0] == 2:
                c = list[1]
                if c > fw:
                    return 'forward', detect_image

        return None, detect_image
Пример #2
0
class ImageViewer(Thread):
    def __init__(self, name, queue):
        super().__init__()
        self.name = name
        self.queue = queue
        self.THRESHOLD = 0.25
        self.detecter = Detecter()
        self.detecter.setup('./frozen_inference_graph.pb',
                            './mscoco_label_map.pbtxt')
        pass

    def run(self):
        while (True):
            frame = self.queue.get(timeout=2)
            frame_ex = np.expand_dims(frame, axis=0)
            (boxes, scores, classes, num) = self.detecter.detect(frame_ex)
            self.detecter.viaulize(frame, boxes, classes, scores,
                                   self.THRESHOLD)
            cv2.imshow(self.name, frame)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        cv2.destroyAllWindows()
        pass
Пример #3
0
        print('go')


# 테스트 이미지 파일 리스트
TEST_IMAGE_PATHS = ['Traffic-Lights.jpg']
THRESHOLD = 0.3

detecter = Detecter()
detecter.setup('./frozen_inference_graph.pb', './mscoco_label_map.pbtxt')

for image_path in TEST_IMAGE_PATHS:
    image, image_ex = get_detect_image(image_path)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    (boxes, scores, classes, num) = detecter.detect(image_ex)

    detecter.viaulize(image, boxes, classes, scores, THRESHOLD)
    cv2.imshow('image', image)

    object_list = filter(lambda item: item[1] > THRESHOLD,
                         zip(boxes, scores, classes))
    (height, width, _) = image.shape
    for ix, object in enumerate(object_list):
        box = object[0]
        classes = object[2]  # 분류맵

        (sy, sx, ey, ex) = (int(box[0] * height), int(box[1] * width),
                            int(box[2] * height), int(box[3] * width))

        sub_image = image[sy:ey, sx:ex]
        imgName = "object." + str(ix)
        # print(sub_image.shape)