-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStackReader.h
131 lines (104 loc) · 4.2 KB
/
StackReader.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* File: StackReader.h
* Author: Marc
*
* Created on October 27, 2010, 4:32 PM
*
* used to read compressed stacks (generated by LinearStackCompressor or its subclasses)
* from disk
* this is the highest level reading function in the library;
*
* create the stackreader by passing a file name
* access frames using the getFrame command
* generate a meta data file using getSupplementalData
*
* in separate projects:
* see also the supplemental dll wrapper: StackReaderWrapper
* see also the example movie player: StackPlayer
*
* example usage:
* StackReader sr("\\\\labnas2\\Phototaxis\\exponentialstack.mmf"); //open stack for reading
* sr.createSupplementalDataFile("c:\\testcs5_dat.dat"); //create a metadata file
* sr.playMovie(); //play a movie on the screen
* (C) Marc Gershow; licensed under the Creative Commons Attribution Share Alike 3.0 United States License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
* Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
*/
#ifndef STACKREADER_H
#define STACKREADER_H
#include "StaticBackgroundCompressor.h"
#include "ExtraDataWriter.h"
#include <map>
#include <string>
#include <cv.h>
class StackReader {
public:
StackReader();
StackReader(const char *fname);
virtual ~StackReader();
virtual void setInputFileName (const char *fname);
virtual void openInputFile ();
virtual void closeInputFile ();
virtual void getBackground (int frameNum, IplImage **dst, int frameRange = 0);
virtual void getFrame (int frameNum, IplImage **dst);
virtual void annotatedFrame (int frameNum, IplImage **dst);
virtual void playMovie (int startFrame = 0, int endFrame = -1, int delay_ms = 50, const char *windowName = NULL, bool annotated = true);
virtual CvSize getImageSize ();
virtual void createSupplementalDataFile(const char *fname);
virtual ExtraDataWriter *getSupplementalData();
/* virtual ExtraDataWriter *addToSupplementalData(ExtraDataWriter *edw, int frameOffset);
* when combining multiple stacks into one analysis file, use addToSupplementalData to create a combined metadata file
* if edw == NULL, creates the EDW
* same as getSupplementalData, with two differences
* FrameNumber (add) = FrameNumber (get) + frameOffset
* LocalFrameNumber (add) = FrameNumber (get)
*/
virtual ExtraDataWriter *addToSupplementalData(ExtraDataWriter *edw = NULL, int frameOffset = 0);
virtual inline bool dataFileOk(){
return (infile != NULL && !infile->fail());
}
virtual inline int getTotalFrames () {
return totalFrames;
}
virtual inline bool isError() {
return iserror;
}
virtual inline std::string getError() {
return errormessage;
}
virtual std::string diagnostics();
virtual CvRect getLargestROI ();
/* virtual void decimateStack(const char *outputname, int decimationCount = 2);
* writes out a copy of the compressed movie, but only a subset of the frames
*
* outputname - name of the file to save the new movie in (cannot be the same as the old file name)
* decimationCount - factor to reduce the file size by (e.g. decimation count of 4 means to record every 4th frame)
*
* returns 0 on sucess, < 0 on error
*/
virtual int decimateStack(const char *outputname, int thresholdAboveBackground, int smallDimMinSize, int lgDimMinSize, int decimationCount = 2);
virtual const ImageMetaData* getMetaData(int frameNum);
virtual int getKeyFrameInterval();
protected:
std::string fname;
std::ifstream *infile;
std::map<int, std::ifstream::pos_type> keyframelocations; //start frame, place in file
int totalFrames;
int startFrame;
int endFrame;
StaticBackgroundCompressor *sbc;
virtual void init();
virtual void parseInputFile();
virtual void setSBC(int frameNum);
virtual inline void setError (std::string err) {
iserror = true;
errormessage = err;
}
CvRect validROI;
bool iserror;
std::string errormessage;
private:
StackReader(const StackReader& orig);
};
#endif /* STACKREADER_H */