Prepared some videos for future tests. Added first version of common positioning video test.
This commit is contained in:
parent
fef90e2270
commit
a41b0902f4
@ -507,6 +507,9 @@ bool CvCapture_FFMPEG::reopen()
|
|||||||
#ifndef AVSEEK_FLAG_FRAME
|
#ifndef AVSEEK_FLAG_FRAME
|
||||||
#define AVSEEK_FLAG_FRAME 0
|
#define AVSEEK_FLAG_FRAME 0
|
||||||
#endif
|
#endif
|
||||||
|
ifndef AVSEEK_FLAG_ANY
|
||||||
|
#define AVSEEK_FLAG_ANY 1
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CvCapture_FFMPEG::open( const char* _filename )
|
bool CvCapture_FFMPEG::open( const char* _filename )
|
||||||
{
|
{
|
||||||
@ -832,7 +835,7 @@ bool CvCapture_FFMPEG::setProperty( int property_id, double value )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int flags = AVSEEK_FLAG_FRAME;
|
int flags = AVSEEK_FLAG_ANY;
|
||||||
if (timestamp < ic->streams[video_stream]->cur_dts)
|
if (timestamp < ic->streams[video_stream]->cur_dts)
|
||||||
flags |= AVSEEK_FLAG_BACKWARD;
|
flags |= AVSEEK_FLAG_BACKWARD;
|
||||||
int ret = av_seek_frame(ic, video_stream, timestamp, flags);
|
int ret = av_seek_frame(ic, video_stream, timestamp, flags);
|
||||||
|
120
modules/highgui/test/test_pos.cpp
Normal file
120
modules/highgui/test/test_pos.cpp
Normal file
@ -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(); }
|
||||||
|
|
||||||
|
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -56,6 +57,12 @@ public:
|
|||||||
void run(int);
|
void run(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CV_PositioningTest : public cvtest::BaseTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void run(int);
|
||||||
|
};
|
||||||
|
|
||||||
double PSNR(const Mat& m1, const Mat& m2)
|
double PSNR(const Mat& m1, const Mat& m2)
|
||||||
{
|
{
|
||||||
Mat tmp;
|
Mat tmp;
|
||||||
@ -232,6 +239,11 @@ void CV_HighGuiTest::VideoTest(const string& dir, int fourcc)
|
|||||||
ts->printf(ts->LOG, "end test function : ImagesVideo \n");
|
ts->printf(ts->LOG, "end test function : ImagesVideo \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CV_PositioningTest::run(int)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CV_HighGuiTest::run( int /*start_from */)
|
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 WIN32 || (defined __linux__ && !defined ANDROID)
|
||||||
#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP
|
#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'} };
|
||||||
|
|
||||||
VideoTest(ts->get_data_path(), CV_FOURCC('X', 'V', 'I', 'D'));
|
printf("%s", ts->get_data_path().c_str());
|
||||||
|
|
||||||
|
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
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user