Ask Your Question

Revision history [back]

I finally solved this issue and 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.