1 | initial version |
Okay first of all the cap interface isn't the best at retrieving properties. Many of it underlying interfaces for camera capture don't support more than half of the get and set parameters. Getting the total amount of frames will be 100% correctly if you just calculated it manually. If this suits your needs and time is not an issue, then simply go for that approach.
A quick code sample
VideoCapture interface("location_to_file"); int counter = 0; Mat frame; while(cap >> frame){ if(frame.empty()){ break; } counter++ }
2 | No.2 Revision |
Okay first of all the cap interface isn't the best at retrieving properties. Many of it underlying interfaces for camera capture don't support more than half of the get and set parameters. Getting the total amount of frames will be 100% correctly if you just calculated it manually. If this suits your needs and time is not an issue, then simply go for that approach.
A quick code sample
VideoCapture interface("location_to_file");
int counter = 0;
Mat frame;
while(cap >> frame){
if(frame.empty()){
break;
}
counter++
3 | No.3 Revision |
Okay first of all the cap interface isn't the best at retrieving properties. Many of it underlying interfaces for camera capture don't support more than half of the get and set parameters. Getting the total amount of frames will be 100% correctly if you just calculated it manually. If this suits your needs and time is not an issue, then simply go for that approach.
A quick code sample
VideoCapture interface("location_to_file");
int counter = 0;
Mat frame;
while(cap >> frame){
if(frame.empty()){
break;
}
counter++
}
Update:
Since the introduction of this solution, there was a new videocapture property introduced, called CAP_PROP_FRAME_COUNT
, which can be retrieved by invoking the .get()
function on the VideoCapture element.