12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- # from PIL import Image
- # from ultralytics import YOLO
- # import time
- # # 加载预训练的YOLOv8n模型
- # model = YOLO('/home/nvidia/newdisk/hkpc/ultralytics-main/best.pt')
- # time.sleep(5)
- # # 在'bus.jpg'上运行推理
- # start_time = time.time()
- # model.predict('data/1.jpg', save=False, imgsz=320, conf=0.5)
- # # results = model('data/1.jpg') # 结果列表
- # # # 展示结果
- # # for r in results:
- # # print(r.boxes.data)
- # # print(r.names)
- # #print(r.probs) # 打印包含检测到的类别概率的Probs对象
- # # im_array = r.plot() # 绘制包含预测结果的BGR numpy数组
- # # im = Image.fromarray(im_array[..., ::-1]) # RGB PIL图像
- # # im.show() # 显示图像
- # # im.save('results.jpg') # 保存图像
- # # 记录结束时间
- # end_time = time.time()
- # # 计算代码运行时间
- # elapsed_time = end_time - start_time
- # print(f"代码运行时间: {elapsed_time} 秒")
- import cv2
- from ultralytics import YOLO
- import time
- # Load the YOLOv8 model
- model = YOLO('/home/nvidia/newdisk/hkpc/ultralytics-main/best.pt')
- # Loop through the video frames
- while 1:
- start_time = time.time()
- # Run YOLOv8 inference on the frame
- results = model('data/1.jpg')
- # Visualize the results on the frame
- # annotated_frame = results[0].plot()
- # # Display the annotated frame
- # cv2.imshow("YOLOv8 Inference", annotated_frame)
- # # Break the loop if 'q' is pressed
- # if cv2.waitKey(1) & 0xFF == ord("q"):
- # break
- end_time = time.time()
- elapsed_time = end_time - start_time
- print(f"代码运行时间: {elapsed_time} 秒")
- time.sleep(0.5)
- # cv2.destroyAllWindows()
|