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

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

相关推荐
im_AMBER3 小时前
学习日志19 python
python·学习
白-胖-子4 小时前
深入剖析大模型在文本生成式 AI 产品架构中的核心地位
人工智能·架构
想要成为计算机高手5 小时前
11. isaacsim4.2教程-Transform 树与Odometry
人工智能·机器人·自动驾驶·ros·rviz·isaac sim·仿真环境
mortimer5 小时前
安装NVIDIA Parakeet时,我遇到的两个Pip“小插曲”
python·github
@昵称不存在6 小时前
Flask input 和datalist结合
后端·python·flask
静心问道6 小时前
InstructBLIP:通过指令微调迈向通用视觉-语言模型
人工智能·多模态·ai技术应用
宇称不守恒4.06 小时前
2025暑期—06神经网络-常见网络2
网络·人工智能·神经网络
赵英英俊6 小时前
Python day25
python
东林牧之6 小时前
Django+celery异步:拿来即用,可移植性高
后端·python·django
何双新7 小时前
基于Tornado的WebSocket实时聊天系统:从零到一构建与解析
python·websocket·tornado