41 #include <visp3/core/vpConfig.h> 43 #if defined(VISP_HAVE_CATCH2) 44 #define CATCH_CONFIG_RUNNER 47 #include <visp3/core/vpIoTools.h> 48 #include <visp3/io/vpVideoReader.h> 49 #include <visp3/io/vpVideoWriter.h> 51 static long first_frame = 100;
52 static int frame_step = 2;
53 static unsigned int nframes = 3;
54 static long last_frame = first_frame +
static_cast<long>(frame_step) * (nframes - 1);
55 static std::string tmp;
56 static std::string videoname_grey;
57 static std::string videoname_color;
60 bool test_createSequence(
vpImage<Type> &I,
const std::string &videoname,
unsigned int first_frame,
int frame_step,
unsigned int nframes)
69 for (
unsigned int i = 0; i < nframes; i ++) {
71 std::cout <<
"Frame saved in: " << writer.
getFrameName() << std::endl;
80 bool test_readSequence(
vpImage<Type> &I,
const std::string &videoname,
long first_frame,
int frame_step,
int step,
long last_frame)
88 std::cout <<
"First frame: " << frame << std::endl;
89 if (frame != first_frame) {
90 std::cout <<
"Wrong first frame" << std::endl;
94 std::cout <<
"Last frame: " << frame << std::endl;
95 if (frame != last_frame) {
96 std::cout <<
"Wrong last frame" << std::endl;
101 while (! reader.
end()) {
104 std::cout <<
"Read frame with index " << index <<
" from: " << reader.
getFrameName() << std::endl;
105 if (index != first_frame + cpt * frame_step) {
106 std::cout <<
"Read wrong frame index" << std::endl;
114 TEST_CASE(
"Test saving sequence of uchar images with step 2",
"[grey]")
116 std::cout <<
"** Create sequence of uchar images with step " << frame_step << std::endl;
118 CHECK(test_createSequence(I, videoname_grey, first_frame, frame_step, nframes));
121 TEST_CASE(
"Test reading a sequence of grey images",
"[grey]") {
122 SECTION(
"Read sequence of uchar images with step 1")
126 CHECK(test_readSequence(I, videoname_grey, first_frame, frame_step, step, last_frame));
129 SECTION(
"Read sequence of uchar images with step 2")
131 int step = frame_step;
133 CHECK(test_readSequence(I, videoname_grey, first_frame, frame_step, step, last_frame));
137 TEST_CASE(
"Test saving sequence of color images with step 2",
"[color]")
139 std::cout <<
"** Create sequence of color images with step " << frame_step << std::endl;
141 CHECK(test_createSequence(I, videoname_color, first_frame, frame_step, nframes));
144 TEST_CASE(
"Test reading a sequence of color images",
"[color]") {
145 SECTION(
"Read sequence of color images with step 1")
149 CHECK(test_readSequence(I, videoname_color, first_frame, frame_step, step, last_frame));
152 SECTION(
"Read sequence of color images with step 2")
154 int step = frame_step;
156 CHECK(test_readSequence(I, videoname_color, first_frame, frame_step, step, last_frame));
160 int main(
int argc,
char *argv[])
162 Catch::Session session;
165 session.applyCommandLine(argc, argv);
167 #if 0 // Prepare next version using temp folder 174 std::string tmp =
"C:/temp/" + username +
"/video";
176 std::string tmp =
"/tmp/" + username +
"/video";
184 std::cerr << std::endl <<
"ERROR:" << std::endl;
185 std::cerr <<
" Cannot create " << tmp << std::endl;
189 std::cout <<
"** Create temp directory: " << tmp << std::endl;
191 videoname_grey = tmp + std::string(
"/I%d.pgm");
192 videoname_color = tmp + std::string(
"/I%d.ppm");
194 int numFailed = session.run();
void setFrameStep(const int frame_step)
void setFirstFrameIndex(int first_frame)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
long getFirstFrameIndex()
void open(vpImage< vpRGBa > &I)
Class that enables to write easily a video file or a sequence of images.
void acquire(vpImage< vpRGBa > &I)
void saveFrame(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
long getFrameIndex() const
std::string getFrameName() const
void setFileName(const std::string &filename)
void setFrameStep(const long frame_step)
std::string getFrameName() const
void setFileName(const std::string &filename)
Definition of the vpImage class member functions.