示例#1
0
    resultPath = os.path.split(FLAGS.model_path)[0]
    resultPath = os.path.join(resultPath, 'detections.txt')
    resultFile = open(resultPath, 'w')

    firstStart = time.time()
    cont = testFile.readlines()
    for i in range(0, len(cont)):
        print("detecting image: {}".format(cont[i].rstrip()))

        imgPath = imgsPath + cont[i].rstrip() + '.jpg'
        try:
            image = Image.open(imgPath)
        except:
            print('Image Open Error')

        out_boxes, out_scores, out_classes = yolo.get_boxes(image)

        if visualise:
            r_image = yolo.detect_image(image)
            r_image.show()

        for idx, c in reversed(list(enumerate(out_classes))):
            predicted_class = 'plum'
            box = out_boxes[idx]
            score = out_scores[idx]

            top, left, bottom, right = box  #left,top,right,bottom = x0,y0,x1,y1
            top = max(0, np.floor(top + 0.5).astype('int32'))
            left = max(0, np.floor(left + 0.5).astype('int32'))
            bottom = min(image.size[1], np.floor(bottom + 0.5).astype('int32'))
            right = min(image.size[0], np.floor(right + 0.5).astype('int32'))
示例#2
0
#-------------------------------------#
#       对单张图片进行预测
#-------------------------------------#
from yolo import YOLO
from PIL import Image
import numpy as np

yolo = YOLO()

while True:
    #img = input('Input image filename:')
    img = '../input/global-wheat-detection/test/cc3532ff6.jpg'
    try:
        image = Image.open(img)
    except:
        print('Open Error! Try again!')
        continue
    else:
        boxes = yolo.get_boxes(image)
        #r_image = yolo.detect_image(image)
    for i in boxes:
        print(i)
    break