QT_xcb 问题

1.错误显示

使用xshell远程连接服务器,运行以下代码的时候发生错误

python 复制代码
import cv2

from ultralytics import solutions

# 打开视频文件
cap = cv2.VideoCapture("datasets/1.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))

# Define region points
region_points = [(230, 230), (500, 230), (500, 1130), (230, 1130)]

# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))

# Init trackzone (object tracking in zones, not complete frame)
trackzone = solutions.TrackZone(
    show=False,  # display the output
    region=region_points,  # pass region points
    model="runs/detect/train/weights/best.pt",
)

# Process video
while cap.isOpened():
    success, im0 = cap.read()
    if not success:
        print("Video frame is empty or video processing has been successfully completed.")
        break
    results = trackzone(im0)
    video_writer.write(results.plot_im)

cap.release()
video_writer.release()
cv2.destroyAllWindows()
python 复制代码
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/root/anaconda3/envs/yolov11/lib/python3.10/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

2.错误分析以及解决方法

用户可能在无显示环境下 运行程序(因为我是xshell远程连接服务器),这时候可以考虑使用虚拟显示服务器,比如Xvfb。安装Xvfb并运行程序前启动虚拟显示,例如xvfb-run -a python script.py,这可以避免需要实际显示设备的问题。

使用Xvfb虚拟显示(适用于无界面环境)

安装Xvfb:

bash 复制代码
sudo apt-get install -y xvfb

使用xvfb-run运行脚本

bash 复制代码
xvfb-run -a python your_script.py

运行上述命令就可以顺利运行程序了。

相关推荐
回眸&啤酒鸭2 分钟前
【回眸】Jockey By TwelveLabs 视频智能体应用场景大纲
人工智能
小虎AI生活3 分钟前
ChatGPT 浏览器扩展升级详解:装扩展、给权限、派第一个活(附可抄话术)
人工智能·chatgpt·超级个体·一人公司·青玥ai
YH_Analytics4 分钟前
2026 洁净室环境在线监测系统行业排名与份额对比销量与份额解析
大数据·网络·人工智能
惊讶的猫7 分钟前
langchain-agent的基础使用
python·langchian
kaixin_啊啊13 分钟前
【零基础学AI】第 12 章课后练习与答案
人工智能·ai
啥都鼓捣的小yao16 分钟前
机器人领域的基础模型:应用、挑战与未来
人工智能·机器人
这张生成的图像能检测吗17 分钟前
(论文速读)RT-DETRv4:借助视觉基础模型,无额外推理开销地提升实时目标检测
人工智能·目标检测·计算机视觉
把我格子衫拿来1 小时前
VTK 体绘制入门到排错:传递函数、采样距离与透明度的关系
python·vtk·可视化·医学影像·体绘制
在所不辞兄6 小时前
【零基础学智能仿真-53】多智能体协作——有限元自动化实战从工程需求到可审核的仿真报告
人工智能·深度学习·神经网络·机器学习·有限元