Python OpenCV 3.2 imshow()没有带有waitKey(0)的图像内容! [英] Python OpenCV 3.2 imshow() no image content with waitKey(0)!

查看:446
本文介绍了Python OpenCV 3.2 imshow()没有带有waitKey(0)的图像内容!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从

I installed OpenCV3.2 + python3.6.1 from this installation guide. (For the paths needed in guide I typed:

编辑:我不确定,但是我想应该在3.6(而不是3.6.1)下安装opencv,请不要使用我的安装路径!

Edit: I'm not sure, but I guess that I should install opencv under 3.6, not 3.6.1, please don't use my paths for your installation!

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib

ls -d /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m/)

我的测试代码与 OpenCV 3.2教程完全相同文档,但输出屏幕仅显示标题:

My testing code is completely the same as the tutorial of OpenCV 3.2 documentation, but the output screen show nothing but a title:

import numpy as np
import cv2

img = cv2.imread('1.jpg',0)
cv2.imshow('image', img)
cv2.waitKey(0)

结果:

如图所示,图像的内容丢失了.

As the picture shown the content of the image is missing.

似乎与我的python有关,图标已损坏:

and it seems that it has something to do with my python, the icon is broken:

请帮助我!我只想在我的学校项目中使用opencv ...

Please help me! I just want to use opencv for my school project...

推荐答案

我遇到了类似的问题,但从C ++ API的角度来看.致谢 mattmyne .

I ran into a similar issue but on the C++ API perspective. Credits go out to mattmyne.

使用可可粉,窗口自动调整大小不适用于macOS.找不到窗口的图像尺寸.通过删除window_cocoa.mm中的IP64特定合成已解决此问题,该合成导致cvShowImage中窗口的contentView image属性的空引用(图像引用未链接到_image).

Window autosize was not working for macOS using cocoa. The window's image dimensions could not be found. This has been fixed by removing IP64 specific synthesize in window_cocoa.mm that was causing null reference for the window's contentView image property in cvShowImage (image reference was not linked to _image).

简而言之,OpenCV尝试同时支持32位和64位ObjC编译器,但是由于Apple不再支持32位,因此某些图像合成操作导致64位计算机中的空引用.更多信息

In a nutshell, OpenCV tried to support both 32 and 64-bit ObjC compilers but since Apple no longer supports 32-bit, some image synthesizing operations resulted in null references in 64-bit machines. More info

要解决此问题,请找到文件 window_cocoa.mm ;如果是从源代码构建的,它将位于 opencv/modules/highgui/src 中.

To resolve this, locate the file window_cocoa.mm; if built from source it'll be in opencv/modules/highgui/src.

更改此

@implementation CVView
#if defined(__LP64__)
@synthesize image;
#else // 32-bit Obj-C does not have automatic synthesize
@synthesize image = _image;
#endif

对此

@implementation CVView
@synthesize image = _image;

CVWindowCVSlider实施也做同样的事情,以容纳视频.

Do the same thing for the CVWindow and CVSlider implementations to accommodate videos as well.

重新编译OpenCV并测试您的代码.

Recompile OpenCV and test out your code.

这篇关于Python OpenCV 3.2 imshow()没有带有waitKey(0)的图像内容!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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