Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV 3.1.0 simple VideoCapture and waitKey crashes after a while on OS X 10.11.2 #5874

Closed
mahiuchun opened this issue Dec 24, 2015 · 65 comments

Comments

@mahiuchun
Copy link

OpenCV 3.1.0 is installed through brew install opencv3 --with-contirb --with-qt5 and the following program crashes after a while:

#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>

int main(int argc, const char * argv[]) {
    cv::VideoCapture cap(0);
    cv::Mat frame;
    while (cap.read(frame)) {
        imshow("Frame", frame);
        if (cv::waitKey(1) == 'q') {
            break;
        }
    }
    return 0;
}

The stack trace is the following:

2015-12-24 09:54:22.297 basic-capture[86100:4481590] -[CaptureDelegate doFireTimer:]: unrecognized selector sent to instance 0x103600680
2015-12-24 09:54:22.313 basic-capture[86100:4481590] An uncaught exception was raised
2015-12-24 09:54:22.313 basic-capture[86100:4481590] -[CaptureDelegate doFireTimer:]: unrecognized selector sent to instance 0x103600680
2015-12-24 09:54:22.313 basic-capture[86100:4481590] (
    0   CoreFoundation                      0x00007fff95766ae2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff90699f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff95769b9d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff956a2601 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff956a2188 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x00007fff9c7d385b __NSFireTimer + 95
    6   CoreFoundation                      0x00007fff956acbc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    7   CoreFoundation                      0x00007fff956ac853 __CFRunLoopDoTimer + 1075
    8   CoreFoundation                      0x00007fff9572ae6a __CFRunLoopDoTimers + 298
    9   CoreFoundation                      0x00007fff95667cd1 __CFRunLoopRun + 1841
    10  CoreFoundation                      0x00007fff95667338 CFRunLoopRunSpecific + 296
    11  HIToolbox                           0x00007fff8f2f3935 RunCurrentEventLoopInMode + 235
    12  HIToolbox                           0x00007fff8f2f3677 ReceiveNextEventCommon + 184
    13  HIToolbox                           0x00007fff8f2f35af _BlockUntilNextEventMatchingListInModeWithFilter + 71
    14  AppKit                              0x00007fff967d10ee _DPSNextEvent + 1067
    15  AppKit                              0x00007fff96b9d943 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    16  libqcocoa.dylib                     0x000000010555ae5a _ZN21QCocoaEventDispatcher13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 1034
    17  libopencv_highgui.3.1.dylib         0x000000010083c596 cvWaitKey + 178
    18  basic-capture                       0x0000000100001666 main + 246
    19  libdyld.dylib                       0x00007fff8a0335ad start + 1
    20  ???                                 0x0000000000000001 0x0 + 1
)
2015-12-24 09:54:22.314 basic-capture[86100:4481590] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CaptureDelegate doFireTimer:]: unrecognized selector sent to instance 0x103600680'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff95766ae2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff90699f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff95769b9d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff956a2601 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff956a2188 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x00007fff9c7d385b __NSFireTimer + 95
    6   CoreFoundation                      0x00007fff956acbc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    7   CoreFoundation                      0x00007fff956ac853 __CFRunLoopDoTimer + 1075
    8   CoreFoundation                      0x00007fff9572ae6a __CFRunLoopDoTimers + 298
    9   CoreFoundation                      0x00007fff95667cd1 __CFRunLoopRun + 1841
    10  CoreFoundation                      0x00007fff95667338 CFRunLoopRunSpecific + 296
    11  HIToolbox                           0x00007fff8f2f3935 RunCurrentEventLoopInMode + 235
    12  HIToolbox                           0x00007fff8f2f3677 ReceiveNextEventCommon + 184
    13  HIToolbox                           0x00007fff8f2f35af _BlockUntilNextEventMatchingListInModeWithFilter + 71
    14  AppKit                              0x00007fff967d10ee _DPSNextEvent + 1067
    15  AppKit                              0x00007fff96b9d943 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    16  libqcocoa.dylib                     0x000000010555ae5a _ZN21QCocoaEventDispatcher13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE + 1034
    17  libopencv_highgui.3.1.dylib         0x000000010083c596 cvWaitKey + 178
    18  basic-capture                       0x0000000100001666 main + 246
    19  libdyld.dylib                       0x00007fff8a0335ad start + 1
    20  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@ahundt
Copy link

ahundt commented Dec 27, 2015

I can confirm issues with waitkey crashing frequently on OS X.

@alalek
Copy link
Member

alalek commented Dec 27, 2015

Please add result of cv::getBuildInformation()

@mahiuchun
Copy link
Author

Attached
buildInfo.txt

@alalek
Copy link
Member

alalek commented Dec 28, 2015

Thanks!
QT backend is used here for UI interaction.
Are you able to reproduce this problem with Cocoa backend?

@kesinger
Copy link
Contributor

kesinger commented Jan 6, 2016

I'm seeing a similar problem with a similar program and what I thought was the Cocoa backend. A slightly censored file is attached with the output from cv::getBuildInformation() and the stacktraces.

One thing I noticed is when I step through in a debugger is I get breakpoints triggered at constant locations in cap_qtkit.mm. Line 335 always triggers twice, then line 299 triggers twice, then 435 triggers once, then the program works as intended.

edit: osx 10.10.5, opencv commit version 92387b1

buildinfo.txt

@alalek
Copy link
Member

alalek commented Jan 6, 2016

@kesinger Thanks for information! QT framework is not used in your build, but problem is still here.

Looks like, both QTKit capture + cv::waitKey are required to reproduce this bug.

@Tobiasgeek
Copy link

Hi,

I am also have the same issue, but I'm not using the QT framework. My program is just plain simple c++ running on Xcode. (Update: Xcode's CoreFoundation uses QTKit Framework by default)

The error occurs after a couple of minutes my video capture c++ program. I even tried on a simple video capture program, and it repeats the same error.

openCV-error.txt

openCV-config.txt

@gbumgard
Copy link

Same install as OP, same stack trace, same problem. I did not see this in OpenCV 3.0. However, I also upgraded to 10.11 (El Capitan) near same time (which now I regret - SIP in OS X complicated the build process for latest versions of OpenCV+CUDA/cuDNN+Caffe w/Python2.7).

@Tobiasgeek
Copy link

I'm using Yosemite 10.10, and I just downgraded to 3.0.0 and works pretty good. I need to run the program for longer period of time to see. But at the moment everything seems fine.

@gbumgard
Copy link

Reverting to 3.0 also solved the problem for me under OSX 10.11.

@BuiltInParris
Copy link

Also experiencing this problem with OpenCV 3.1.0, OSX version 10.11.2.

@mron
Copy link

mron commented Jan 19, 2016

Same problem with OpenCV 3.1.0, OSX version 10.11.2. Not using cv::waitKey().

@mron
Copy link

mron commented Jan 19, 2016

Same problem with OpenCV 3.0.0, OSX version 10.11.2. Not using cv::waitKey(). Should I be?
-[CaptureDelegate doFireTimer:]: unrecognized selector sent to instance 0x60800007e980

@mron
Copy link

mron commented Jan 20, 2016

Found this in: "opencv-3.1.0/modules/videoio/src/cap_qtkit.mm"
....
bool CvCaptureCAM::grabFrame(double timeOut)
// Create a dummy timer so that runUntilDate does not exit immediately:
[NSTimer scheduledTimerWithTimeInterval:100 target:nil selector:@selector(doFireTimer:) userInfo:nil repeats:YES];

This looks like it runs about 100sec then looks for nil and sends it doFireTimer:.
I can't find doFilreTimer(), and what happens when the timer target is nil?

on a site called fossies.org, the same line has "capture" as a target.
[NSTimer scheduledTimerWithTimeInterval:100 target:capture selector:@selector(doFireTimer:) userInfo:nil repeats:YES];

@rtielking
Copy link

I can confirm consistent crash exactly 100 seconds after starting my program. I also have OS X 10.11.2 and OpenCV 3.1.0 using the VideoCapture class.

@mron
Copy link

mron commented Jan 20, 2016

This code doesn't make sense to me:
...
[NSTimer scheduledTimerWithTimeInterval:100 target:nil selector:@selector(doFireTimer:) userInfo:nil repeats:YES];
while (![capture updateImage] && (total += sleepTime)<=timeOut) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:sleepTime]];
}
...

The first line : " [NSTimer scheduledTimerWithTimeInterval ... " adds a timer to the current run loop, which isn't created until the while loop is executed. The "while" loop creates run loops to act essentially like sleep(). I don't think run loops act that way. [NSThread sleepForTimeInterval:] might work if there is a separate thread running. Also, if the timer is needed, it should be invalidated when no longer needed, and fixed so it references a valid object.

@alalek
Copy link
Member

alalek commented Jan 20, 2016

There is a patch for file cap_qtkit.mm between OpenCV 3.0.0 and OpenCV 3.1.0:
e8bf441#diff-2a81486ed8ebf4c35433ebaa5f2c5e75
Could someone revert this fix for cap_qtkit.mm and re-check this problem?
target:capture --> target:nil

@mron Could you try to use dummy cv::waitKey call (OpenCV 3.0.0):

void main(...)
{
    cv::waitKey(1);
    ... your code without waitKey ...
}

@mron
Copy link

mron commented Jan 20, 2016

I'm very new to opencv and github, so please bear with me. I did try putting the waitKey() call in. The timer still fires and crashes. Changing "nil" to "capture" will not help unless a "doFireTimer:" method is added to the capture's ( CaptureDelegate? ) class. I'm also new to objc.. sorry.

@jackyliang
Copy link

@rtielking did you fix this? I timed the code, and it crashes in exactly 100 seconds.

@rtielking
Copy link

yes i was able to fix the crash at 100sec by commenting out the following line

[NSTimer scheduledTimerWithTimeInterval:100 target:capture selector:@selector(doFireTimer:) userInfo:nil repeats:YES];

in the /modules/videoio/src/cap_qtkit.mm file and recompiling

@jackyliang
Copy link

@rtielking I believe I installed OpenCV through Homebrew + Luarocks - how would I recompile it manually?

@rtielking
Copy link

Download the source at https://github.com/Itseez/opencv/archive/3.1.0.zip
and extract the source code. Install XCode from Apple's App Store so you will have the developer tools you need. Find the line I mentioned above and comment it out. Then open a terminal and cd to the directory where you extracted the source code and run the following commands:

brew install cmake
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE ..
make -j4
sudo make install

Then it should work for you on the mac.

@jackyliang
Copy link

@rtielking following these instructions should theoretically allow my program to know which OpenCV version to use right? Should I remove my existing OpenCV installation first?

@rtielking
Copy link

Might be a good idea to remove existing installation first just to be sure. I always built from source, so don't know where brew puts things when it installs.

@jackyliang
Copy link

@rtielking I compiled it.. commented out the line with the 100.. Then re-compiled it using the build instructions. However, the crash still happened at the 100 mark =/ I am also not 100% sure if the old installation is gone even though I deleted that folder.

@mron
Copy link

mron commented Jan 25, 2016

I was able to recompile with the line commented out. The crashes have stopped. I did have the same problem of Xcode using the old framework. I'm not sure exactly how I got Xcode to use the new library. I "make uninstall" on both 3.0 and 3.1, deleted both 3.0 and 3.1 frameworks, "make clean" on both 3.0 and 3.1. In Xcode I did Project->Clean and deleted "Derived Data" folder and removed the framework reference. Rebuilt 3.1, rebuilt the framework, add the framework. The changes were then used and new changes show up as I make them.

@cedricve
Copy link

Having the same issue

@shawnsnyder
Copy link

Same issue here. Reverting to 3.0....

@alalek
Copy link
Member

alalek commented Feb 4, 2016

Could someone check this fix: #6051?

@LukasKalinski
Copy link

Same error and same stack trace here. Did the following:
brew remove opencv3 (effectively cleaned everything and Xcode immediately noticed it)
brew cleanup
brew install --HEAD opencv3
(might be unstable, but hopefully more stable than current 3.1)

@foundry
Copy link

foundry commented Mar 10, 2016

thanks mateuszmikusz and LukasKalinski (and everyone) ... i've just updated my SO answer with your better advice

heinemml added a commit to heinemml/homebrew-science that referenced this issue Mar 17, 2016
heinemml added a commit to heinemml/homebrew-science that referenced this issue Mar 17, 2016
@Ghifarahadian
Copy link

Hi guys. Thank you for all the advices. I reinstall the opencv yet I still have the problem.

Im running Yosemite version 10.10.5 and I also install opencv_contrib. Any suggestions? Or perhaps downgrading is the only way to go. How to downgrade it? Thank you

@mron
Copy link

mron commented Mar 31, 2016

I’m not familiar with github enough to help. Maybe send a more descriptive message about your install procedure and someone with more understanding can help.

On Mar 31, 2016, at 5:49 AM, Ghifarahadian notifications@github.com wrote:

Hi guys. Thank you for all the advices. I reinstall the opencv yet I still have the problem.

Im running Yosemite version 10.10.5 and I also install opencv_contrib. Any suggestions? Or perhaps downgrading is the only way to go. How to downgrade it? Thank you


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub #5874 (comment)

@Ghifarahadian
Copy link

I am using this (https://github.com/Itseez/opencv_contrib) to install. Oh and initially i use this (https://www.youtube.com/watch?v=U49CVY8yOxw) to install openCV 3.1.0 on Mac. I am not sure whether the openCV installed this way is removed when using brew remove opencv3

@geraldstanje
Copy link

hi, is this issue already solved?

@zhonghh
Copy link

zhonghh commented Nov 23, 2016

Same problem, after a few captures the opencv crashes. I am using python bindings in Mac. This makes video capture unusable. I have to rely on some other frameworks to do the job.

@casparwylie
Copy link

any fixes for python bindings ? Deleting derived data is irrelevant in this case unfortunately.. cheers.

@hndr91
Copy link

hndr91 commented Dec 31, 2016

I have same problem in Sierra 10.12. v3.1.0 installed from anaconda

@mron
Copy link

mron commented Dec 31, 2016 via email

@jkearse3
Copy link

Having this same problem on OSX 10.10.5. Any update on the fix?

@mron
Copy link

mron commented Feb 24, 2017 via email

@sushanb
Copy link

sushanb commented Mar 2, 2017

Having the same problem on OSX 10.11.5 . I am using the python interface for opencv2

@jkearse3
Copy link

jkearse3 commented Mar 8, 2017

Bumping the issue. By any chance could this be reopened so that a fix can happen to the repo?

@mron
Copy link

mron commented Mar 8, 2017 via email

@nuksss
Copy link

nuksss commented Jun 13, 2017

I use Anaconda for Python and Opencv on my Mac. How shall I recompile if that's the case?

@mron
Copy link

mron commented Jun 13, 2017 via email

@alexscluk
Copy link

in anaconda prompt, type in:

conda install -c menpo opencv3

according to this website:

https://anaconda.org/menpo/opencv3

@ahundt
Copy link

ahundt commented Jun 16, 2017

I created #8931 so hopefully it can actually be fixed. :-)

@mron
Copy link

mron commented Jun 16, 2017 via email

@ShangxuanWu
Copy link

This issue still occurs. OSX 10.12.5 with python 2.7.13 and python-opencv2

@htzy
Copy link

htzy commented Sep 28, 2017

me too.
2017-09-20 23:20:24.579 python2.7[17999:2038663] -[CaptureDelegate doFireTimer:]: unrecognized selector sent to instance 0x7facf99ed4f0

@vasyaivanov
Copy link

Is someone looking at this issue?
Or at least, how can we install OpenCV 3.0? It seams brew or Pycharm can see only 3.1 and above.
Thanks.

@ahundt
Copy link

ahundt commented Dec 30, 2017

If you're still having this problem with the latest release say so on #8931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests