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

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

相关推荐
小白学大数据3 分钟前
实战:Python爬虫如何模拟登录与维持会话状态
开发语言·爬虫·python
FriendshipT6 分钟前
目标检测:使用自己的数据集微调DEIMv2进行物体检测
人工智能·pytorch·python·目标检测·计算机视觉
海森大数据10 分钟前
三步破局:一致性轨迹强化学习开启扩散语言模型“又快又好”推理新时代
人工智能·语言模型·自然语言处理
Tencent_TCB12 分钟前
云开发CloudBase AI+实战:快速搭建AI小程序全流程指南
人工智能·ai·小程序·ai编程·云开发
Sunhen_Qiletian14 分钟前
基于OpenCV与Python的身份证号码识别案例详解
人工智能·opencv·计算机视觉
AustinCyy20 分钟前
【论文笔记】Introduction to Explainable AI
论文阅读·人工智能
平谷一勺31 分钟前
数据清洗-缺失值的处理
python·数据分析
岁月宁静38 分钟前
在富文本编辑器中封装实用的 AI 写作助手功能
前端·vue.js·人工智能
末世灯光39 分钟前
时间序列入门第一问:它和普通数据有什么不一样?(附 3 类典型案例)
人工智能·python·机器学习·时序数据
开心-开心急了41 分钟前
Flask入门教程——李辉 第一、二章关键知识梳理(更新一次)
后端·python·flask