コード例 #1
0
    imageShowed = cv2.imread(filename)
    for r, (x1, y1, x2, y2) in result:
        cv2.rectangle(imageShowed, (y1, x1), (y2, x2), colorMap[r], 1)

    path, filename = os.path.split(filename)
    bfn, ext = os.path.splitext(filename)
    cv2.imwrite(os.path.join(output, bfn+'_wclrd'+ext), imageShowed)

    # cv2.imshow('image', imageShowed)
    # key = 255
    # while key != 27:
    #     key = cv2.waitKey(20) & 0xFF


if __name__ == '__main__':
    import sys
    classifier = load(sys.argv[1])
    output = sys.argv[3]
    FileHelper.create_or_clear_dir(output)

    colorMap = ColorMap((0, 255, 255), (0, 0, 255), 0.0, 1.0)
    wfc = WindowedFeatureClassifier(classifier)
    if os.path.isdir(sys.argv[2]):
        dir = sys.argv[2]
        for filename in os.listdir(dir):
            if os.path.isfile(os.path.join(dir, filename)):
                process_file(wfc, os.path.join(dir, filename), output)
    else:
        process_file(wfc, sys.argv[2], output)
コード例 #2
0
    for r, (x1, y1, x2, y2) in result:
        cv2.rectangle(image, (y1, x1), (y2, x2), colorMap[r], 1)

    path, bf = os.path.split(filename)
    cv2.imwrite(os.path.join(output, bf), image)

if __name__ == '__main__':
    parser = ArgParserWithDefaultHelp(description='Visualising tool for pattern matcher and classifier')
    parser.add_argument('folder', help='Folder, that contains folders with frames')
    parser.add_argument('patterns', help='Folder with patterns')
    parser.add_argument('classifier', help='Classifier')
    parser.add_argument('output', help='Output folder for processed images')
    parser.add_argument('-j', '--jobs', default=-1, type=int, help='Processes amount for parallel processing')
    args = parser.parse_args()

    classifier = load(args.classifier)
    FileHelper.create_or_clear_dir(args.output)

    wfc = WindowedFeatureClassifier(classifier)

    pm = PatternMatcher()
    pm.load_patterns_folder(args.patterns)

    tasks = []
    for dir, filename in FileHelper.read_images_in_dir_recursively(args.folder):
        tasks.append(delayed(process_image)(wfc, pm, os.path.join(dir, filename), args.output))

    p = Parallel(n_jobs=args.jobs, verbose=100)
    p(tasks)