diff c/cvutils.cpp @ 12:ff5403319cec

optical flow demo working
author Nicolas Saunier <nico@confins.net>
date Wed, 11 Nov 2009 23:25:23 -0500
parents e77e2fd69b02
children 336926453b28
line wrap: on
line diff
--- a/c/cvutils.cpp	Wed Nov 11 12:01:43 2009 -0500
+++ b/c/cvutils.cpp	Wed Nov 11 23:25:23 2009 -0500
@@ -1,6 +1,7 @@
 #include "cvutils.hpp"
 
 #include "opencv/cv.h"
+#include "opencv/highgui.h"
 
 #include <iostream>
 
@@ -19,14 +20,18 @@
   return image;
 }
 
-void goToFrameNum(CvCapture* capture, const int& currentFrameNum, const int& targetFrameNum) {
-  if (currentFrameNum > targetFrameNum)
+int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum) {
+  int frameNum = currentFrameNum;
+  if (currentFrameNum > targetFrameNum) {
     cerr << "Current frame number " << currentFrameNum << " is after the target frame number " << targetFrameNum << "." << endl;
-
-  for (int frameNum = currentFrameNum; frameNum<targetFrameNum; ++frameNum) {
+  } else if (currentFrameNum < targetFrameNum) {
     IplImage* frame = cvQueryFrame(inputVideo);
-    if (!frame)
-      break;
     frameNum++;
+    while (frame && frameNum<targetFrameNum) {
+      frame = cvQueryFrame(inputVideo);
+      frameNum++;
+    }
   }
+  
+  return frameNum;
 }