def get_more_data(img, outputs, class_names):
    boxes, objectness, classes, nums = outputs
    boxes, objectness, classes, nums = boxes[0], objectness[0], classes[
        0], nums[0]
    wh = np.flip(img.shape[0:2])
    process_s = []
    nb_image = 0
    for i in range(nums):
        x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
        x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))

        if class_names[int(classes[i])] == "cat" or class_names[int(
                classes[i])] == "dog":
            x1, y1 = x1y1
            x2, y2 = x2y2
            img_crop = img[y1:y1 + (y2 - y1), x1:x1 + (x2 - x1)]
            nb_image = nb_image + 1
            img_to_net = img_t.load_img_opencv(img_crop)
            if class_names[int(classes[i])] == "cat":
                process = ThreadSend("cat", img_to_net)
                process.setDaemon(True)
                process.start()
                process_s.append(process)
            else:
                process = ThreadSend("dog", img_to_net)
                process.setDaemon(True)
                process.start()
                process_s.append(process)
    return nb_image
Exemplo n.º 2
0
def draw_outputs(img, outputs, class_names):
    boxes, objectness, classes, nums = outputs
    boxes, objectness, classes, nums = boxes[0], objectness[0], classes[
        0], nums[0]
    wh = np.flip(img.shape[0:2])
    dog_det = []
    cat_det = []
    for i in range(nums):
        x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
        x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))

        x1, y1 = x1y1
        x2, y2 = x2y2
        img_crop = img[y1:y1 + (y2 - y1), x1:x1 + (x2 - x1)]

        img_to_cnn = img_t.load_img_opencv(img_crop)
        label = ""
        prob = 0
        if class_names[int(classes[i])] == "dog":
            label, prob = cnn_t.get_more_dog(img_to_cnn)
            dog_det.append([prob, label])

        if class_names[int(classes[i])] == "cat":
            prob, label = cnn_t.get_more_cat(img_to_cnn)
            cat_det.append([label, prob])

        img = cv2.rectangle(img, x1y1, x2y2, (0, 0, 0), 2)
        img = cv2.putText(
            img, '{} {:.2f} {} {:.2f}'.format(class_names[int(classes[i])],
                                              objectness[i], label, prob),
            x1y1, cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (255, 255, 255), 2)

    return img, cat_det, dog_det
Exemplo n.º 3
0
def get_more_data(img, model_cat, model_dog, outputs, class_names):
    boxes, objectness, classes, nums = outputs
    boxes, objectness, classes, nums = boxes[0], objectness[0], classes[
        0], nums[0]
    wh = np.flip(img.shape[0:2])
    process_s = []
    for i in range(nums):
        x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
        x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))

        if class_names[int(classes[i])] == "cat" or class_names[int(
                classes[i])] == "dog":
            x1, y1 = x1y1
            x2, y2 = x2y2
            img_crop = img[y1:y1 + (y2 - y1), x1:x1 + (x2 - x1)]

            img_to_cnn = img_t.load_img_opencv(img_crop)
            if class_names[int(classes[i])] == "cat":
                process = ThreadCat(i, "cat", model_cat, img_to_cnn)
                process_s.append(process)
            elif class_names[int(classes[i])] == "dog":
                process = ThreadDog(i, "dog", model_dog, img_to_cnn)
                process_s.append(process)
    for process in process_s:
        process.start()
        process.join()
    return info_cat, info_dog, info_box
Exemplo n.º 4
0
def thread_for_cnn(i, classe, model, img):
    img_to_cnn = img_t.load_img_opencv(img)
    label = ""
    prob = 0
    if classe == "dog":
        label, prob = get_more_dog(model, img_to_cnn)
    else:
        label, prob = get_more_cat(model, img_to_cnn)
    info.append([i, label, prob])
Exemplo n.º 5
0
def send_data(cat, data, s):
    data = img_tools.load_img_opencv(data)
    print("Type : ", type(data), "Dimension : ", np.shape(data))
    message = "1;" + "YOLO" + ";" + cat.upper() + ";" + np.array2string(
        data) + ";"
    logging.info("Send image category : " + cat + " message size = " +
                 str(sys.getsizeof(message)))

    s.send(message.encode('utf-8'))