diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index 45ef08281b..6c2cd9a5a1 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -494,11 +494,15 @@ bool VideoCapture::retrieve(Mat& image, int channel) bool VideoCapture::read(Mat& image) { - if (get(CV_CAP_PROP_POS_FRAMES) < get(CV_CAP_PROP_FRAME_COUNT)) - if(!grab()) - image.release(); - else - retrieve(image); + double frame_pos = get(CV_CAP_PROP_POS_FRAMES); + double frame_count = get(CV_CAP_PROP_FRAME_COUNT); + if (frame_pos < frame_count || frame_pos < 0 || frame_count < 0) + { + if(grab()) + retrieve(image); + else + image.release(); + } else image.release(); return !image.empty(); @@ -506,10 +510,7 @@ bool VideoCapture::read(Mat& image) VideoCapture& VideoCapture::operator >> (Mat& image) { - if(!grab()) - image.release(); - else - retrieve(image); + read(image); return *this; }