def _segmentImage(self, imgPath):
        """Segment the given image into sections to for smoke classificaiton

        Args:
            imgPath (str): filepath of the image

        Returns:
            List of dictionary containing information on each segment
        """
        img = Image.open(imgPath)
        ppath = pathlib.PurePath(imgPath)
        segments = rect_to_squares.cutBoxes(img, str(ppath.parent), imgPath)
        img.close()
        return segments
Exemple #2
0
def main():
    global fen
    reqArgs = [
        ["i", "image", "filename of the image"],
        ["o", "output", "output directory name"],
    ]
    optArgs = [[
        "d", "display",
        "(optional) specify any value to display image and boxes"
    ], ["f", "fixedSize", "(optional) use 299x299 segments"]]
    args = collect_args.collectArgs(reqArgs, optionalArgs=optArgs)
    # print(args)
    imgOrig = Image.open(args.image)
    callBackFn = None
    if args.display:
        imageDisplay(imgOrig)
        callBackFn = showSquares
    if args.fixedSize:
        rect_to_squares.cutBoxesFixed(imgOrig, args.output, args.image,
                                      callBackFn)
    else:
        rect_to_squares.cutBoxes(imgOrig, args.output, args.image, callBackFn)
    if args.display:
        fen.mainloop()
Exemple #3
0
def main():
    reqArgs = [
        ["i", "image", "filename of the image"],
        ["o", "output", "output directory name"],
    ]
    optArgs = [["l", "labels", "labels file generated during retraining"],
               ["m", "model", "model file generated during retraining"],
               [
                   "d", "display",
                   "(optional) specify any value to display image and boxes"
               ]]
    args = collect_args.collectArgs(reqArgs, optionalArgs=optArgs)
    model_file = args.model if args.model else settings.model_file
    labels_file = args.labels if args.labels else settings.labels_file

    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    graph = tf_helper.load_graph(model_file)
    labels = tf_helper.load_labels(labels_file)
    segments = []
    with tf.Session(graph=graph) as tfSession:
        if True:  # chops image in segment files and classifies each segment
            imgOrig = Image.open(args.image)
            segments = rect_to_squares.cutBoxes(imgOrig, args.output,
                                                args.image)
            tf_helper.classifySegments(tfSession, graph, labels, segments)

        if False:  # version that classifies entire image without cropping
            imgOrig = Image.open(args.image)
            segments = [{'imgPath': args.image}]
            tf_helper.classifySegments(tfSession, graph, labels, segments)

        if False:  # chops image into in-memory segments and classifies each segment
            calcScoresInMemory(args.model, args.labels, args.image)

        for segmentInfo in segments:
            print(segmentInfo['imgPath'], segmentInfo['score'])
        if args.display:
            drawBoxesAndScores(imgOrig, segments)
            displayImageWithScores(imgOrig, [])
Exemple #4
0
def segmentImage(imgPath):
    img = Image.open(imgPath)
    ppath = pathlib.PurePath(imgPath)
    return rect_to_squares.cutBoxes(img, str(ppath.parent), imgPath)