YOLO多张图片预测代码

#
#-------------------------------------#
#       对单张图片进行预测
#-------------------------------------#
# from yolo import YOLO
# from PIL import Image

# yolo = YOLO()

# while True:
#     img = input('Input image filename:')
#     try:
#         image = Image.open(img)
#     except:
#         print('Open Error! Try again!')
#         continue
#     else:
#         r_image = yolo.detect_image(image)
#         r_image.show()
#对多张图片进行检测

from yolo import YOLO
from PIL import Image
import os

yolo = YOLO()
filepath ="/diskb/jyz/ddata/bus2/"
filename = os.listdir(filepath)
while True:
    for i in filename:
        print(i)
        image = i.strip().split(".")
        j=i.split(".")[0]
        # print(image)
        # print(j)
#这条语句完全是为了练习split方法。

    # img = input('Input image filename:')
        try:
            img = image[0]+".jpg"
            imag = os.path.join(filepath,img)
            im = Image.open(imag)
            print(im)
        except:
            
            print('Open Error! Try again!')
            continue
        else:
            r_image = yolo.detect_image(im)
            r_image.save('/diskb/jyz/ddata/bus1/'+ j +'.jpg')
        break

你可能感兴趣的:(图像视觉,图像识别)