openCV imshow 随机失败 [英] openCV imshow fails randomly

查看:67
本文介绍了openCV imshow 随机失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想显示图像时,cv2.imshow() 随机失败.

When I want to display an image, the cv2.imshow() fails randomly.

import cv2

frame = cv2.imread('desk.jpg', cv2.IMREAD_COLOR)

cv2.imshow('test', frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

有时,我得到第一个,有时得到第二个:

Sometimes, I got the first and sometimes the second:

我确定数据已正确加载,因为当我打印帧矩阵时,一切正常.我也尝试将图片转换为其他格式,但结果总是相同的,随机的.

I'm sure that the data is correctly loaded because when I print the frame matrix, everything is ok. I also tried to convert picture to other format but the result is always the same, random.

>>> cv2.__version__
'4.3.0'
# opencv-contrib-python is installed

内核信息:Linux 5.3.0-62-generic #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020 GNU/Linux

编辑:正如 Doch88 所说,从源代码编译解决了我的问题.这是我的 cmake 命令:

Edit: As Doch88 said, compiling from source solve my problem. Here my cmake command:

mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_src/opencv_contrib/modules ../opencv

推荐答案

还有一个问题 有类似问题,根据 这个问题这是一个错误:

There is another question with a similar problem, and according to this issue it is a bug:

OpenCV无法修复此问题,该问题与Qt有关Python轮子和系统中捆绑的Qt4之间的冲突Qt4/5 安装.

This issue cannot be fixed in OpenCV, the issue is related to Qt conflicts between the bundled Qt4 in the Python wheels and system Qt4/5 installations.

一种解决方法可能是从源代码构建 OpenCV.

A way to solve it is probably to build OpenCV from source code.

这篇关于openCV imshow 随机失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆