Beispiel #1
0
import cv2
import pathlib
from objdetect import ObjDetectApi

PATH_TO_LABELS = 'data/mscoco_label_map.pbtxt'
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
api = ObjDetectApi(MODEL_NAME, PATH_TO_LABELS)

# 예제 데이터
PATH_TO_TEST_IMAGES_DIR = pathlib.Path('test_images')
TEST_IMAGE_PATHS = sorted(list(PATH_TO_TEST_IMAGES_DIR.glob("*.jpg")))

# 검출 진행
for image_path in TEST_IMAGE_PATHS:
    image, output_dict = api.inference_file(image_path)
    print(output_dict)
    labeled_image = api.visualize(image, output_dict)
    labeled_image = cv2.cvtColor(labeled_image, cv2.COLOR_RGB2BGR)
    cv2.imshow('image', labeled_image)
    cv2.waitKey(0)

cv2.destroyAllWindows()
Beispiel #2
0
import cv2
import net
import json
import numpy as np
from objdetect import ObjDetectApi, NumpyEncoder

PATH_TO_LABELS = 'data/mscoco_label_map.pbtxt'
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'

api = ObjDetectApi(MODEL_NAME, PATH_TO_LABELS)

HOST = '0.0.0.0'
PORT = 5000


def filtering(output_dict):
    classes = []
    boxes = []
    scores = []
    for ix, score in enumerate(output_dict['detection_scores']):
        if score > 0.5:
            print(score)
            classes.append(output_dict['detection_classes'][ix])
            boxes.append(output_dict['detection_boxes'][ix])
            scores.append(score)

    return {
        'detection_classes': np.array(classes),
        'detection_boxes': np.array(boxes),
        'detection_scores': np.array(scores)
    }
Beispiel #3
0
from video import Video
import socket
import json
import net
import cv2
import numpy as np
from objdetect import ObjDetectApi, NumpyDecoder

PATH_TO_LABELS = 'data/mscoco_label_map.pbtxt'
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
api = ObjDetectApi(MODEL_NAME, PATH_TO_LABELS)

HOST = '127.0.0.1'
PORT = 5000

if __name__ == '__main__':
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect((HOST, PORT))
        writer = s.makefile('wb')
        reader = s.makefile('rb')
        with Video(device=0) as v:
            for image in v:
                jpg = Video.to_jpg(image)
                net.send(writer, jpg)

                output_dict = net.receive(reader)[0].decode()
                output_dict = json.loads(output_dict, cls=NumpyDecoder)

                labeled_image = api.visualize(image, output_dict)
                cv2.imshow('frame', labeled_image)
                key = cv2.waitKey(1)