Ejemplo n.º 1
0
def processing(threshold, jsonFile):

    coco_demo = COCODemo(cfg,
                         min_image_size=800,
                         confidence_threshold=threshold)

    imageList = []
    for i, imagePath in enumerate(imagePathList):
        print("loading:{}".format(i))
        imagefilepath = os.path.join(IMAGE_PATH, imagePath)
        image = Image.open(imagefilepath).convert("RGB")
        image = np.array(image)[:, :, [2, 1, 0]]
        imageList.append(image)

    # compute predictions
    predictions, errorList, successList = coco_demo.run_on_imageList(
        imageList, imagePathList, jsonFile)

    for i, prediction in enumerate(predictions):
        print("writting:{}".format(i))
        targetPath = os.path.join(TARGET_PATH, successList[i])
        cv2.imwrite(targetPath, prediction)
        imagePathList.remove(successList[i])
        if successList[i] in errorPathList:
            errorImagePath = os.path.join(ERROR_PATH, successList[i])
            errorPathList.remove(successList[i])
            os.remove(errorImagePath)

    for i, name in enumerate(errorList):
        print("writting:{}".format(i))
        errorImagePath = os.path.join(IMAGE_PATH, name)
        errorImage = cv2.imread(errorImagePath)
        targetPath = os.path.join(ERROR_PATH, name)
        cv2.imwrite(targetPath, errorImage)
Ejemplo n.º 2
0

imagePathList = os.listdir(IMAGE_PATH)
imageList = []
jsonFile = open(JSON_PATH, 'w')

for i, imagePath in enumerate(imagePathList):
    print("loading:{}".format(i))
    imagefilepath = os.path.join(IMAGE_PATH, imagePath)
    image = Image.open(imagefilepath).convert("RGB")
    image = np.array(image)[:, :, [2, 1, 0]]
    imageList.append(image)

# compute predictions
start = time.time()
predictions, errorList, successList = coco_demo.run_on_imageList(
    imageList, imagePathList, jsonFile)

for i, prediction in enumerate(predictions):
    print("writting:{}".format(i))
    targetPath = os.path.join(RESULT_PATH, successList[i])
    cv2.imwrite(targetPath, prediction)

for i, name in enumerate(errorList):
    print("writting:{}".format(i))
    errorImagePath = os.path.join(IMAGE_PATH, name)
    errorImage = cv2.imread(errorImagePath)
    targetPath = os.path.join(ERROR_PATH, name)
    cv2.imwrite(targetPath, errorImage)

end = time.time()
print("run time is {}s".format(end - start))