Ask Your Question

s-light's profile - activity

2017-02-23 21:33:35 -0600 answered a question OpenCV: VideoCapture::get(CV_CAP_PROP_POS_MSEC ) returns 0

not really an answer.. more the way to eventually one..

i have tested the what happens with some debugging statements in the code: first i added some debug statements in cap_libv4l.cpp#L1414

case CV_CAP_PROP_POS_MSEC:
    if (capture->FirstCapture) {
        fprintf( stderr, "VIDEOIO INFO: V4L: CV_CAP_PROP_POS_MSEC==0 caused by capture->FirstCapture == 1");
        return 0;
    } else {
        //would be maximally numerically stable to cast to convert as bits, but would also be counterintuitive to decode
        return 1000 * capture->timestamp.tv_sec + ((double) capture->timestamp.tv_usec) / 1000;
    }
    break;

and in cap_v4l.cpp#L1651

if(property_id == CV_CAP_PROP_POS_MSEC) {
    if (capture->FirstCapture) {
        fprintf( stderr, "VIDEOIO INFO: V4L2: CV_CAP_PROP_POS_MSEC==0 caused by capture->FirstCapture == 1\n");
        return 0;
    } else {
        return 1000 * capture->timestamp.tv_sec + ((double) capture->timestamp.tv_usec) / 1000;
    }
}

recompiled OpenCV and tested with an simple cam viewer. found that with the current setup it is using cap_v4l.cpp - and that only the first time my debugmessage was triggerd.

so i added some some more debug output to cap_v4l.cpp L1651:

if(property_id == CV_CAP_PROP_POS_MSEC) {
    if (capture->FirstCapture) {
        fprintf( stderr, "VIDEOIO INFO: V4L2: CV_CAP_PROP_POS_MSEC==0 caused by capture->FirstCapture == 1\n");
        return 0;
    } else {
        fprintf( stderr, "VIDEOIO INFO: V4L2: CV_CAP_PROP_POS_MSEC:\n");
        fprintf( stderr, "\tcapture->timestamp.tv_sec %ld\n", capture->timestamp.tv_sec);
        fprintf( stderr, "\tcapture->timestamp.tv_usec %ld\n", capture->timestamp.tv_usec);
        return 1000 * capture->timestamp.tv_sec + ((double) capture->timestamp.tv_usec) / 1000;
    }
}

with this i get

VIDEOIO INFO: V4L2: CV_CAP_PROP_POS_MSEC:
     capture->timestamp.tv_sec 0
     capture->timestamp.tv_usec 0
cv::CAP_PROP_POS_MSEC = 0

the last line comes from my app.. so the capture->timestamp contains 0. it is set in cap_v4l.cpp#L868 directly from the buffer. so it seams OpenCV does not get a timestamp information from the ioctl call back :-(

now at this point i have no idea how to go on... could be a problem in the v4l2 implementation??

2017-02-23 19:51:28 -0600 commented question OpenCV: VideoCapture::get(CV_CAP_PROP_POS_MSEC ) returns 0

i have the same problem. using OpenCV 3.2. self compiled from git. @berak: its not clear which one is used but the functionality is available in both: cap_v4l.cpp https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_v4l.cpp#L159 (L159) https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_v4l.cpp#L1651 (L1651) and cap_libv4l.cpp https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_libv4l.cpp#L194 (L194) https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_libv4l.cpp#L1414 (L1414).

so this should not make a difference. it seems internally capture->FirstCapture evaluates to true all the time.. from a quick poking around in the code i could not find a cause for this... :-( edit: see my 'answer' for more research..