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

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

相关推荐
Tutankaaa36 分钟前
知识竞赛题库设计全攻略
人工智能·算法
我的xiaodoujiao37 分钟前
API 接口自动化测试详细图文教程学习系列15--项目实战演练2
python·学习·测试工具·pytest
TImCheng060944 分钟前
职场人AI学习周期评估:不同学习路径的时间成本
人工智能·学习
m0_466525291 小时前
酷特AGI:从“自家试验田”到“全球输出”
大数据·人工智能·agi
星爷AG I1 小时前
20-1 记忆概览(AGI基础理论)
人工智能·agi
锕琅1 小时前
OpenAI Codex使用教程-GPT功能配置
人工智能·gpt·codex
鹏子训1 小时前
AI记忆新思路:用SQLite替代向量数据库,去EMBEDDINGS化,谷歌开源Google Always On Memory Agent
数据库·人工智能·sqlite·embedding
xyz5991 小时前
ONNX Runtime(ORT) C++ Windows 深度学习模型部署简易教程
人工智能·深度学习
市象1 小时前
AI带给TCL空调的头部假想
大数据·人工智能
武汉知识图谱科技1 小时前
国家首次探索“词元交易”:大模型时代的知识产权困境与知识图谱的“价值锚定”机会
人工智能·知识图谱