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

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

相关推荐
王者鳜錸1 小时前
PYTHON让繁琐的工作自动化-PYTHON基础
python·microsoft·自动化
key_Go1 小时前
7.Ansible自动化之-实施任务控制
python·ansible·numpy
stbomei2 小时前
当 AI 开始 “理解” 情感:情感计算技术正在改写人机交互规则
人工智能·人机交互
Moshow郑锴7 小时前
人工智能中的(特征选择)数据过滤方法和包裹方法
人工智能
TY-20257 小时前
【CV 目标检测】Fast RCNN模型①——与R-CNN区别
人工智能·目标检测·目标跟踪·cnn
CareyWYR8 小时前
苹果芯片Mac使用Docker部署MinerU api服务
人工智能
失散138 小时前
自然语言处理——02 文本预处理(下)
人工智能·自然语言处理
wyiyiyi9 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
mit6.8249 小时前
[1Prompt1Story] 滑动窗口机制 | 图像生成管线 | VAE变分自编码器 | UNet去噪神经网络
人工智能·python
sinat_286945199 小时前
AI应用安全 - Prompt注入攻击
人工智能·安全·prompt