Prepared some videos for future tests. Added first version of common positioning...
authorAlexander Reshetnikov <no@email>
Tue, 31 Jan 2012 21:02:05 +0000 (21:02 +0000)
committerAlexander Reshetnikov <no@email>
Tue, 31 Jan 2012 21:02:05 +0000 (21:02 +0000)
modules/highgui/src/cap_ffmpeg_impl.hpp
modules/highgui/test/test_pos.cpp [new file with mode: 0644]
modules/highgui/test/test_video_io.cpp

index 9c833be..491bc91 100644 (file)
@@ -507,6 +507,9 @@ bool CvCapture_FFMPEG::reopen()
 #ifndef AVSEEK_FLAG_FRAME
        #define AVSEEK_FLAG_FRAME 0
 #endif
+ifndef AVSEEK_FLAG_ANY
+       #define AVSEEK_FLAG_ANY 1
+#endif
 
 bool CvCapture_FFMPEG::open( const char* _filename )
 {
@@ -832,7 +835,7 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
             }
             else
             {
-                int flags = AVSEEK_FLAG_FRAME;
+                int flags = AVSEEK_FLAG_ANY;
                 if (timestamp < ic->streams[video_stream]->cur_dts)
                   flags |= AVSEEK_FLAG_BACKWARD;
                 int ret = av_seek_frame(ic, video_stream, timestamp, flags);
diff --git a/modules/highgui/test/test_pos.cpp b/modules/highgui/test/test_pos.cpp
new file mode 100644 (file)
index 0000000..50030ba
--- /dev/null
@@ -0,0 +1,120 @@
+#include "test_precomp.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include <stdio.h>
+
+/* #include <cv.h>
+#include <cxcore.h>
+
+    #include <iostream>
+    #include <sstream>
+    #include <string> */
+
+using namespace cv;
+using namespace std;
+
+//ticket #1497
+
+#define HIGHGUI_POSITIONING_ERROR_OPEN 0
+
+#define MESSAGE_ERROR_CONTENT "Cannot read source video file."
+
+class CV_VideoPositioningTest: public cvtest::BaseTest
+{
+public:
+    void run(int);
+
+};
+
+void CV_VideoPositioningTest::run(int)
+{
+    const string& src_dir = ts->get_data_path();
+
+    std::cout << src_dir.c_str() << endl;
+
+    string file_path = "/home/reshetnikov/SVN_Projects/OpenCV/opencv_extra/testdata/perf/video/sample_sorenson.mov";
+
+    std::cout << file_path.c_str() << endl;
+
+    cv::VideoCapture cap(file_path);
+
+    // CvCapture* cap = cvCreateFileCapture(file_path.c_str());
+     if (!cap.isOpened())
+    {
+        printf("Error!");
+        return;
+    }
+
+    std::cout << "Frame pos: " << cap.get(CV_CAP_PROP_POS_FRAMES) << std::endl;
+
+    // IplImage* frame = cvQueryFrame(cap);
+
+    Mat frame; cap >> frame;
+
+    /* if (!frame)
+    {
+
+            return;
+    } */
+
+    std::cout << "Frames number: " << cap.get(CV_CAP_PROP_FRAME_COUNT) << std::endl;
+    
+    int step = 20;
+    int frameCount = 1;
+    while (frameCount < 100)
+    {
+            std::cout << "Frame count: " << frameCount << "\tActual frame pos: " << cap.get(CV_CAP_PROP_POS_FRAMES) << std::endl;
+
+            // Save the frame
+            std::stringstream ss;
+            ss << frameCount;
+            std::string filename = ss.str() + ".png";
+            imwrite(file_path, frame, vector<int>(1));
+            // Advance by step frames
+            frameCount += step;
+            std::cout << "cvSetCaptureProperty result: " << cap.set(CV_CAP_PROP_POS_FRAMES, frameCount) << std::endl;;
+            // frame = cvQueryFrame(cap);
+    }
+
+    // cvReleaseCapture(&cap);
+    cap.release();
+}
+
+
+
+
+
+    /*
+47     NOTES
+48
+49     Output:
+50     Frame pos: 0
+51     Frame count: 1  Actual frame pos: -1.84467e+017
+52     cvSetCaptureProperty result: 1
+53     Frame count: 21 Actual frame pos: -1.84467e+017
+54     cvSetCaptureProperty result: 1
+55     Frame count: 41 Actual frame pos: -1.84467e+017
+56     cvSetCaptureProperty result: 1
+57     Frame count: 61 Actual frame pos: -1.84467e+017
+58     cvSetCaptureProperty result: 1
+59     Frame count: 81 Actual frame pos: -1.84467e+017
+60     cvSetCaptureProperty result: 1
+61
+62     Expected:
+63     Frame pos: 0
+64     Frame count: 1  Actual frame pos: 1
+65     cvSetCaptureProperty result: 1
+66     Frame count: 21 Actual frame pos: 21
+67     cvSetCaptureProperty result: 1
+68     Frame count: 41 Actual frame pos: 41
+69     cvSetCaptureProperty result: 1
+70     Frame count: 61 Actual frame pos: 61
+71     cvSetCaptureProperty result: 1
+72     Frame count: 81 Actual frame pos: 81
+73     cvSetCaptureProperty result: 1
+74
+75     In addition, the frame retrieved from cvQueryFrame was not the correct frame
+76     */
+
+TEST (HighguiPositioning, regression) { CV_VideoPositioningTest test; test.safe_run(); }
+
+
index 7466a59..fd7caa1 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "test_precomp.hpp"
 #include "opencv2/highgui/highgui.hpp"
+  #include "stdio.h"
 
 using namespace cv;
 using namespace std;
@@ -56,6 +57,12 @@ public:
     void run(int);
 };
 
+class CV_PositioningTest : public cvtest::BaseTest
+{
+public:
+void run(int);
+};
+
 double PSNR(const Mat& m1, const Mat& m2)
 {              
     Mat tmp;
@@ -232,6 +239,11 @@ void CV_HighGuiTest::VideoTest(const string& dir, int fourcc)
     ts->printf(ts->LOG, "end test function : ImagesVideo \n");
 }
 
+void CV_PositioningTest::run(int)
+{
+
+}
+
 
 void CV_HighGuiTest::run( int /*start_from */)
 {
@@ -240,13 +252,21 @@ void CV_HighGuiTest::run( int /*start_from */)
 #if defined WIN32 || (defined __linux__ && !defined ANDROID)
 #if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP  
 
-    VideoTest(ts->get_data_path(), CV_FOURCC_DEFAULT);
+    const char codecs[][4] = { {'I', 'Y', 'U', 'V'},
+                               {'X', 'V', 'I', 'D'},
+                               {'M', 'P', 'G', '2'},
+                               {'M', 'J', 'P', 'G'} };
+
+                               printf("%s", ts->get_data_path().c_str());
 
-    VideoTest(ts->get_data_path(), CV_FOURCC('X', 'V', 'I', 'D'));
+    int count = sizeof(codecs)/(4*sizeof(char));
+
+    for (int i = 0; i < count; ++i)
+    {
+     VideoTest(ts->get_data_path(), CV_FOURCC(codecs[i][0], codecs[i][1], codecs[i][2], codecs[i][3]));
+    }
 
-    VideoTest(ts->get_data_path(), CV_FOURCC('M', 'P', 'G', '2'));
 
-    VideoTest(ts->get_data_path(), CV_FOURCC('M', 'J', 'P', 'G'));
 
 #endif
 #endif