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

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

相关推荐
doubao369 分钟前
审美积累,顶刊论文插图原理图、流程图
人工智能·经验分享·aigc·ai写作·绘图·文献综述·科研绘图
CG大魔王18 分钟前
SenseVoice微调
人工智能·语言模型·音频
爱编程的喵喵19 分钟前
Al Agent开发零基础构建复合智能体
人工智能·agent·智能体
Pocker_Spades_A19 分钟前
论文精读(六):微服务系统服务依赖发现技术综述
人工智能
hrrrrb1 小时前
【Python】文件处理(二)
开发语言·python
灰太狼不爱写代码1 小时前
3DGS输入的三个bin文件的作用
数码相机·计算机视觉·3d
catchadmin2 小时前
PHP 快速集成 ChatGPT 用 AI 让你的应用更聪明
人工智能·后端·chatgpt·php
TechNomad2 小时前
八、OpenCV中的常见滤波方式
opencv
万粉变现经纪人4 小时前
如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘tokenizers’ 问题
python·selenium·测试工具·scrapy·beautifulsoup·fastapi·pip
编程武士6 小时前
从50ms到30ms:YOLOv10部署中图像预处理的性能优化实践
人工智能·python·yolo·性能优化