Ask Your Question

Kåre Jensen's profile - activity

2018-11-07 17:49:14 -0600 received badge  Notable Question (source)
2018-04-06 08:30:03 -0600 received badge  Popular Question (source)
2016-08-15 15:38:10 -0600 received badge  Famous Question (source)
2016-08-15 15:38:10 -0600 received badge  Popular Question (source)
2016-08-15 15:38:10 -0600 received badge  Notable Question (source)
2015-10-30 08:52:56 -0600 commented question Memory leak using copyTo UMat

@LBerger: That sounds plausible. It is actual a leak of ~6MB I see. But then how to deallocate these 6MB again? Calling frameUMat.release does not? And as I like to convert a Mat to UMat in a Video Reader loop I see this ~6MB leak in loop, and that is fast getting quite heavy.

2015-10-30 08:14:27 -0600 commented question Memory leak using copyTo UMat

@LBerger: You might be right about not measuring the memory correctly. But then on the other hand I would not then expect to get a increase in memory usage after the copyTo method is called?

2015-10-30 07:37:09 -0600 asked a question Memory leak using copyTo UMat

I am having issues converting a Mat image to a UMat using the copyTo method without introducing a memory leak using the OpenCV 3.0.

I have tried tested the using the two code snippets below trying to trace process memory usage step by step: In both cases the orgFrame is a Mat image already allocated and assiged.

Mat version:

Mat frameMat;
orgFrame.copyTo(frameMat); // Memory allocated
frameMat.release(); // Memory deallocated

UMat version:

UMat frameUMat;
orgFrame.copyTo(frameUMat); // Memory allocated
frameUMat.release(); // Expected Memory deallocated - But Not???

I have tracked the memory usage by usin the Performance Monitor (perfmon) Windows tool monitoring the Process - Working Set – Private value.

Can anybody give me an explanation of why the frameUMat.release is not releasing memory as I expect or is this some kind of memory leak bug in the OpenCV code?

2015-07-06 05:27:57 -0600 received badge  Student (source)
2015-07-06 04:28:10 -0600 asked a question OpenCV VideoCapture: Howto get specific frame correctly?

I am trying to get at specific frame from a video file using OpenCV 2.4.11. I have tried to follow the documentation and online tutorials of how to do it correctly and have now tested two approaches:

1) The first method is brute force reading each frame using the video.grab() until I reach the specific frame (timestamp) I want. This method is slow if the specific frame is late in the video sequence!

string videoFile(videoFilename);
VideoCapture video(videoFile);
double videoTimestamp = video.get(CV_CAP_PROP_POS_MSEC);
int videoFrameNumber = static_cast<int>(video.get(CV_CAP_PROP_POS_FRAMES));
while (videoTimestamp < targetTimestamp)
{
    videoTimestamp = video.get(CV_CAP_PROP_POS_MSEC);
    videoFrameNumber = static_cast<int>(video.get(CV_CAP_PROP_POS_FRAMES));

    // Grabe frame (but don't decode the frame as we are only "Fast forwarding")
    video.grab();
}
// Get and save frame
if (video.retrieve(frame))
{
    char txtBuffer[100];
    sprintf(txtBuffer, "Video1Frame_Target_%f_TS_%f_FN_%d.png", targetTimestamp, videoTimestamp, videoFrameNumber);
    string imgName = txtBuffer;
    imwrite(imgName, frame);
}

2) The second method I uses the video.set(...). This method is faster and doesn't seem to be any slower if the specific frame is late in the video sequence.

string videoFile(videoFilename);
VideoCapture video2(videoFile);
videoTimestamp = video2.get(CV_CAP_PROP_POS_MSEC);
videoFrameNumber = static_cast<int>(video2.get(CV_CAP_PROP_POS_FRAMES));
video2.set(CV_CAP_PROP_POS_MSEC, targetTimestamp);
while (videoTimestamp < targetTimestamp)
{
    videoTimestamp = video2.get(CV_CAP_PROP_POS_MSEC);
    videoFrameNumber = (int)video2.get(CV_CAP_PROP_POS_FRAMES);

    // Grabe frame (but don't decode the frame as we are only "Fast forwarding")
    video2.grab();
}
// Get and save frame
if (video2.retrieve(frame))
{
    char txtBuffer[100];
    sprintf(txtBuffer, "Video2Frame_Target_%f_TS_%f_FN_%d.png", targetTimestamp, videoTimestamp, videoFrameNumber);
    string imgName = txtBuffer;
    imwrite(imgName, frame);
}

Problem) Now the issue is that using the two methods does end up with the same frame number of the content of the target image frame is not equal?!?

I am tempted to conclude that Method 1 is the correct one and there is something wrong with the OpenCV video.set(...) method. But if I use the VLC player finding the approximate target frame position it is actually Method 2 that is closest to a "correct" result?

As some extra info: I have tested the same video sequence but in two different video files being encoded with respectively 'avc1' MPG4 and 'wmv3' WMV codec.

Using the WMV file the two found frames are way off?

Using the MPG4 file the two found frames are only slightly off?

Is there anybody having some experience with this, can explain my findings and tell me the correct way to get a specific frame from a video file?