首页 > 解决方案 > Qt:opencv python中的会话管理错误

问题描述

我正在尝试运行以下脚本

import numpy as np
import cv2

#Capture Video from Camera
cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

当我尝试在 Ubuntu 终端中运行它时,它给了我这个Qt: Session management error和 2 个不需要的帧以及我的输出。

在此处输入图像描述

你们能帮助我如何摆脱这个错误和那些不需要的帧吗?

标签: python-3.xopencvubuntu

解决方案


伙计们,在找到许多博客和资源后,我终于得到了这个,它对我有用。

不要使用 pip 进行 opencv 安装,而是使用以下命令

sudo apt install libopencv-dev python3-opencv

https://linuxize.com/post/how-to-install-opencv-on-ubuntu-20-04/

注意 - 我认为这个问题与 Ubuntu 20.04 有关


推荐阅读