Ejemplo n.º 1
0
#-------------------------------------#
#       对单张图片进行预测
#-------------------------------------#
from efficientdet import EfficientDet
from PIL import Image

efficientdet = EfficientDet()

while True:
    img = input('Input image filename:')
    try:
        image = Image.open(img)
    except:
        print('Open Error! Try again!')
        continue
    else:
        r_image = efficientdet.detect_image(image)
        r_image.show()
Ejemplo n.º 2
0
    tf.config.experimental.set_memory_growth(gpu, True)

efficientdet = EfficientDet()

capture = cv2.VideoCapture(0)  # capture=cv2.VideoCapture("1.mp4")
fps = 0.0
while (True):
    t1 = time.time()
    # 读取某一帧
    ref, frame = capture.read()
    # 格式转变,BGRtoRGB
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    # 转变成Image
    frame = Image.fromarray(np.uint8(frame))

    # 进行检测
    frame = np.array(efficientdet.detect_image(frame))

    # RGBtoBGR满足opencv显示格式
    frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
    fps = (fps + (1. / (time.time() - t1))) / 2
    print("fps= %.2f" % (fps))
    frame = cv2.putText(frame, "fps= %.2f" % (fps), (0, 40),
                        cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)

    cv2.imshow("video", frame)
    c = cv2.waitKey(1) & 0xff
    if c == 27:
        capture.release()
        break
Ejemplo n.º 3
0
                    help='num img 2 show',
                    default=1)
parser.add_argument('-r',
                    "--root",
                    type=str,
                    help='root dir filled with *.jpg')
parser.add_argument('-i', "--filename", type=str, help='filename', default='')

args = parser.parse_args()

efficientdet = EfficientDet(args.model_path, args.version, args.conf,
                            args.cuda)

if args.num2show == 1:
    image = Image.open(os.path.join(args.root, args.filename))
    res, cls, score = efficientdet.detect_image(image)
    print(cls, score)
    # r_image.show()

else:
    print('结果将会保存到temp.png')
    files = os.listdir(args.root)
    idx = [
        int(len(os.listdir(args.root)) * random.random())
        for i in range(args.num2show)
    ]
    imgs = [Image.open(os.path.join(args.root, files[id])) for id in idx]
    ress, clss, scores = [], [], []
    print(len(imgs))
    for img in imgs:
        res, cls, score = efficientdet.detect_image(img)