Ask Your Question

Video window not loading frame

asked 2017-06-14 10:51:17 -0500

updated 2017-06-14 10:58:08 -0500

I know this question has been asked multiple times but none of the solutions have worked for my context plus my window is actually getting loaded.

When I run this program, the webcam lights up and the window actually appears but without the footage. The same thing happens when I try to load an image. I tried with and without the namedWindow() method but still no luck. My frame matrix consists of data and everything seems to run smoothly with exception to actually displaying the image/video.

I compiled OpenCV3.2.0 from source and running it on Mac OS Sierra.

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

VideoCapture cap(0);

void grabVideoFeed(Mat& frame)
    if (!cap.isOpened()) cerr << "Issue grabbing camera";;

int main(int argc, const char * argv[])
    Mat frame;


        if (frame.empty()) break;

        namedWindow("Main", CV_WINDOW_AUTOSIZE);
        imshow("Main", frame);

        if (waitKey(30) >= 0) break;


    return 0;

When I execute this program, the created window looks like this.Window is loaded but no image is shown.

edit retag flag offensive close merge delete


looks more like an apple gui problem to me, specifically this one

berak gravatar imageberak ( 2017-06-14 10:59:46 -0500 )edit

That's very weird because I was able to load video feeds through OpenCV with Python.

eshirima gravatar imageeshirima ( 2017-06-14 11:12:55 -0500 )edit

maybe try with different window flags, with or without namedWindow()

there seems to be a weird bug in opencv <--> cocoa present (my opinion)

did you build the python version locally ? might be helpful to check cv2.printBuildInformation() against your c++ one

berak gravatar imageberak ( 2017-06-14 11:18:11 -0500 )edit

A quick inspection into their build info reveals no significant difference actually. I might be wrong but have a peek and see. Python and C++

eshirima gravatar imageeshirima ( 2017-06-14 12:47:33 -0500 )edit

your python one was build by the conda guys, on 2017-03-30, your c++ one is from 2017-06-13

(it's a detective story, should you accept this mission. this note will self-destruct in 5 seconds)

berak gravatar imageberak ( 2017-06-14 12:58:06 -0500 )edit

I know that but looking at the Video/GUI and Media sections, they're both the same. Both of them use AVFoundation and Cocoa. The only reasonable explanation I can come up with is that this bug was introduced recently and wasn't there when the conda guys were compiling theirs. I found this suggested solution but yet to be added to master.

eshirima gravatar imageeshirima ( 2017-06-14 13:09:00 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2017-06-16 12:09:45 -0500

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 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; 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;

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.

edit flag offensive delete link more


What do you mean with "Do the same thing for the CVWindow and CVSlider"? What we need to change? please, may you show your (Sorry for mi bad English)

paulo gravatar imagepaulo ( 2017-06-27 21:23:30 -0500 )edit

Its fine no worries. The above change is for the CVView implementation. Make the same changes to the implementations of CVWindow and CVSlider code segments respectively. Search @implementation CVSlider and @implementation CVWindow in your file and make the same changes I've shown above.. Please don't forget to upvote the answer since it helped resolve your problem :)

eshirima gravatar imageeshirima ( 2017-06-27 22:49:04 -0500 )edit

Solamente volví a instalar openCV 3.2.0 y funcionó perfecto. I only install again openCV 3.2.0 and every it's perfect. I watch de and it was changed like you wrote, I don't touch nothing. Thanks for all. I can't upvote, it's say I need 5 points, sorry

paulo gravatar imagepaulo ( 2017-06-28 00:08:28 -0500 )edit

how would i recompile OpenCV. (sorry, I'm pretty new with terminal/opencv stuff). Thank you in advance!

luigimon gravatar imageluigimon ( 2017-07-05 21:35:19 -0500 )edit

@luigimon No its fine, I'm glad to help. Follow these instructions from step 6 onwards. If you feel inclined, you may start from step 3 as well should you feel like making some amendments to your modules

eshirima gravatar imageeshirima ( 2017-07-06 11:55:02 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2017-06-14 10:51:17 -0500

Seen: 412 times

Last updated: Jun 16 '17