python waitkey(0)_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:

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

and

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

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)

The result:

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

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

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

解决方案

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

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).

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

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

Change this

@implementation CVView

#if defined(__LP64__)

@synthesize image;

#else // 32-bit Obj-C does not have automatic synthesize

@synthesize image = _image;

#endif

To this

@implementation CVView

@synthesize image = _image;

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

Recompile OpenCV and test out your code.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值