patrikhuber / superviseddescent

C++11 implementation of the supervised descent optimisation method
http://patrikhuber.github.io/superviseddescent/
Apache License 2.0
404 stars 188 forks source link

Fixed crash with video source and added compatibility with OpenCV 3.0 #15

Closed MichaelGrupp closed 9 years ago

MichaelGrupp commented 9 years ago

The example app rcr-track.cpp crashes when using a video as input image source because it does not stop the loop after the last frame.

My bugfix takes account of the limited number of frames in a video while a continuous image source (camera) behaves just like before (quit by keystroke).

Furthermore, helpers.hpp uses the circle function of OpenCV which has moved from core to imgproc in version 3.0. I don't think the additional include affects a build with OpenCV 2.x, but maybe you can test that.

patrikhuber commented 9 years ago

I thought I fixed that, but I see I didn't commit it yet. I fixed it a bit differently, I just added a check after cap >> image;:

    if (image.empty()) { // stop if we're at the end of the video
        break;
    }

I think a potential problem with your fix is that the fact that CV_CAP_PROP_FRAME_COUNT returns -1 for a camera is not documented behaviour, so it may be the case on your system and even on mine, but it may not on any other (see OpenCV 3.0 docs, same on 2.4.11). What do you think? If you want you can take my changes and I'll merge them along with your OpenCV 3.0 fix.

MichaelGrupp commented 9 years ago

Ok, I think that we should use your solution to avoid the crash for the reasons you pointed out.

Please have a look at my commit.

patrikhuber commented 9 years ago

Great, thanks! :+1: