-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitkVideoFileReaderExample.cxx
More file actions
96 lines (82 loc) · 2.62 KB
/
itkVideoFileReaderExample.cxx
File metadata and controls
96 lines (82 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "iostream"
#include "itkVideoFileReader.h"
#include "itkImageFileWriter.h"
// This is an example that illustate how the Light video file reader works
// It basically saves a image from a video every minute. (every 1500 frame
// if the frame period is 1/25 s)
int test_reader ( char* Input, char* OutputWithoutExtension, bool readerUseOpenCV )
{
typedef itk::Image<unsigned char, 2> OutputImageType;
itk::VideoFileReader< OutputImageType >::Pointer reader = itk::VideoFileReader< OutputImageType >::New();
reader->SetFileName(Input);
reader->UseOpenCV(readerUseOpenCV);
reader->LoadVideo();
unsigned int FrameTotal = reader->GetFrameTotal();
unsigned int i;
char* buf = new char;
itk::ImageFileWriter<OutputImageType>::Pointer writer = itk::ImageFileWriter<OutputImageType>::New();
writer->SetInput(reader->GetOutput());
for (i = 0; i < FrameTotal ; i++)
{
if ( i % 500 == 0 )
{
//To set a different filename each time
std::string filename = OutputWithoutExtension;
sprintf( buf, "%d", i );
filename += std::string(buf);
filename += ".png";
writer->SetFileName(filename.c_str());
try
{
writer->Update();
}
catch (itk::ExceptionObject &e)
{
reader->Print(std::cout);
writer->Print(std::cout);
std::cerr<<e.GetFile()<<std::endl;
std::cerr<<e.GetLine()<<std::endl;
std::cerr<<e.GetLocation()<<std::endl;
std::cerr<<e.GetNameOfClass()<<std::endl;
std::cerr<<e.GetDescription()<<std::endl;
return EXIT_FAILURE;
}
}
else
{
reader->Update();
}
reader->KeepReading();
}
std::string filename = OutputWithoutExtension ;
filename += "Half.png";
reader->SetNextFrameIsFrameRequested(true);
reader->SetFrameRequested(static_cast<unsigned long>(FrameTotal/2));
writer->SetFileName(filename.c_str());
try
{
writer->Update();
}
catch (itk::ExceptionObject &e)
{
reader->Print(std::cout);
writer->Print(std::cout);
std::cerr<<e.GetFile()<<std::endl;
std::cerr<<e.GetLine()<<std::endl;
std::cerr<<e.GetLocation()<<std::endl;
std::cerr<<e.GetNameOfClass()<<std::endl;
std::cerr<<e.GetDescription()<<std::endl;
return EXIT_FAILURE;
}
std::cout<<"Done !"<<std::endl;
return EXIT_SUCCESS;
}
int main ( int argc, char *argv[] )
{
/*int k = test_reader("C:/projects/ITK-Vid-A2D2/Data/inde-circulation.avi",
"C:/projects/ITK-Vid-A2D2_build/Testing/OpenCVFrame_Number_",
atoi("1"));
std::cin>>k;
return k;*/
return test_reader(argv[1],argv[2],atoi(argv[3]));
}