Commit d807738201e3e9211b58e9e857cfa3aa5113b248

Authored by Josh Klontz
1 parent 43fab3dc

removed seq gallery

Showing 1 changed file with 0 additions and 249 deletions
openbr/plugins/gallery/seq.cpp deleted
1 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
2 - * Copyright 2012 The MITRE Corporation *  
3 - * *  
4 - * Licensed under the Apache License, Version 2.0 (the "License"); *  
5 - * you may not use this file except in compliance with the License. *  
6 - * You may obtain a copy of the License at *  
7 - * *  
8 - * http://www.apache.org/licenses/LICENSE-2.0 *  
9 - * *  
10 - * Unless required by applicable law or agreed to in writing, software *  
11 - * distributed under the License is distributed on an "AS IS" BASIS, *  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  
13 - * See the License for the specific language governing permissions and *  
14 - * limitations under the License. *  
15 - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */  
16 -  
17 -#include <fstream>  
18 -#include <QQueue>  
19 -#include <opencv2/highgui/highgui.hpp>  
20 -  
21 -#include <openbr/plugins/openbr_internal.h>  
22 -#include <openbr/core/qtutils.h>  
23 -  
24 -namespace br  
25 -{  
26 -  
27 -/*!  
28 - * \brief DOCUMENT ME  
29 - * \author Unknown \cite unknown  
30 - */  
31 -class seqGallery : public Gallery  
32 -{  
33 -public:  
34 - Q_OBJECT  
35 -  
36 - bool open()  
37 - {  
38 - seqFile.open(QtUtils::getAbsolutePath(file.name).toStdString().c_str(), std::ios::in | std::ios::binary | std::ios::ate);  
39 - if (!isOpen()) {  
40 - qDebug("Failed to open file %s for reading", qPrintable(file.name));  
41 - return false;  
42 - }  
43 -  
44 - int headSize = 1024;  
45 - // start at end of file to get full size  
46 - int fileSize = seqFile.tellg();  
47 - if (fileSize < headSize) {  
48 - qDebug("No header in seq file");  
49 - return false;  
50 - }  
51 -  
52 - // first 4 bytes store 0xEDFE, next 24 store 'Norpix seq '  
53 - char firstFour[4];  
54 - seqFile.seekg(0, std::ios::beg);  
55 - seqFile.read(firstFour, 4);  
56 - char nextTwentyFour[24];  
57 - readText(24, nextTwentyFour);  
58 - if (firstFour[0] != (char)0xED || firstFour[1] != (char)0xFE || strncmp(nextTwentyFour, "Norpix seq", 10) != 0) {  
59 - qDebug("Invalid header in seq file");  
60 - return false;  
61 - }  
62 -  
63 - // next 8 bytes for version (skipped below) and header size (1024), then 512 for descr  
64 - seqFile.seekg(4, std::ios::cur);  
65 - int hSize = readInt();  
66 - if (hSize != headSize) {  
67 - qDebug("Invalid header size");  
68 - return false;  
69 - }  
70 - char desc[512];  
71 - readText(512, desc);  
72 - file.set("Description", QString(desc));  
73 -  
74 - width = readInt();  
75 - height = readInt();  
76 - // get # channels from bit depth  
77 - numChan = readInt()/8;  
78 - int imageBitDepthReal = readInt();  
79 - if (imageBitDepthReal != 8) {  
80 - qDebug("Invalid bit depth");  
81 - return false;  
82 - }  
83 - // the size of just the image part of a raw img  
84 - imgSizeBytes = readInt();  
85 -  
86 - int imgFormatInt = readInt();  
87 - if (imgFormatInt == 100 || imgFormatInt == 200 || imgFormatInt == 101) {  
88 - imgFormat = "raw";  
89 - } else if (imgFormatInt == 102 || imgFormatInt == 201 || imgFormatInt == 103 ||  
90 - imgFormatInt == 1 || imgFormatInt == 2) {  
91 - imgFormat = "compressed";  
92 - } else {  
93 - qFatal("unsupported image format");  
94 - }  
95 -  
96 - numFrames = readInt();  
97 - // skip empty int  
98 - seqFile.seekg(4, std::ios::cur);  
99 - // the size of a full raw file, with extra crap after img data  
100 - trueImgSizeBytes = readInt();  
101 -  
102 - // gather all the frame positions in an array  
103 - seekPos.reserve(numFrames);  
104 - // start at end of header  
105 - seekPos.append(headSize);  
106 - // extra 8 bytes at end of img  
107 - int extra = 8;  
108 - for (int i=1; i<numFrames; i++) {  
109 - int s;  
110 - // compressed images have different sizes  
111 - // the first byte at the beginning of the file  
112 - // says how big the current img is  
113 - if (imgFormat == "compressed") {  
114 - int lastPos = seekPos[i-1];  
115 - seqFile.seekg(lastPos, std::ios::beg);  
116 - int currSize = readInt();  
117 - s = lastPos + currSize + extra;  
118 -  
119 - // but there might be 16 extra bytes instead of 8...  
120 - if (i == 1) {  
121 - seqFile.seekg(s, std::ios::beg);  
122 - char zero;  
123 - seqFile.read(&zero, 1);  
124 - if (zero == 0) {  
125 - s += 8;  
126 - extra += 8;  
127 - }  
128 - }  
129 - }  
130 - // raw images are all the same size  
131 - else {  
132 - s = headSize + (i*trueImgSizeBytes);  
133 - }  
134 -  
135 - seekPos.enqueue(s);  
136 - }  
137 -  
138 -#ifdef CVMATIO  
139 - if (basis.file.contains("vbb")) {  
140 - QString vbb = basis.file.get<QString>("vbb");  
141 - annotations = TemplateList::fromGallery(File(vbb));  
142 - }  
143 -#else  
144 - qWarning("cvmatio not installed, bounding boxes will not be available. Add -DBR_WITH_CVMATIO cmake flag to install.");  
145 -#endif  
146 -  
147 - return true;  
148 - }  
149 -  
150 - bool isOpen()  
151 - {  
152 - return seqFile.is_open();  
153 - }  
154 -  
155 - void close()  
156 - {  
157 - seqFile.close();  
158 - }  
159 -  
160 - TemplateList readBlock(bool *done)  
161 - {  
162 - if (!isOpen()) {  
163 - if (!open())  
164 - qFatal("Failed to open file %s for reading", qPrintable(file.name));  
165 - else  
166 - idx = 0;  
167 - }  
168 -  
169 - // if we've reached the last frame, we're done  
170 - if (seekPos.size() == 0) {  
171 - *done = true;  
172 - return TemplateList();  
173 - }  
174 -  
175 - seqFile.seekg(seekPos.dequeue(), std::ios::beg);  
176 -  
177 - cv::Mat temp;  
178 - // let imdecode do all the work to decode the compressed img  
179 - if (imgFormat == "compressed") {  
180 - int imgSize = readInt() - 4;  
181 - std::vector<char> imgBuf(imgSize);  
182 - seqFile.read(&imgBuf[0], imgSize);  
183 - // flags < 0 means load image as-is (keep color info if available)  
184 - cv::imdecode(imgBuf, -1, &temp);  
185 - }  
186 - // raw images can be loaded straight into a Mat  
187 - else {  
188 - char *imgBuf = new char[imgSizeBytes];  
189 - seqFile.read(imgBuf, imgSizeBytes);  
190 - int type = (numChan == 1 ? CV_8UC1 : CV_8UC3);  
191 - temp = cv::Mat(height, width, type, imgBuf);  
192 - }  
193 - Template output;  
194 - output.file = file;  
195 - if (!annotations.empty()) {  
196 - output.file.setRects(annotations.first().file.rects());  
197 - annotations.removeFirst();  
198 - }  
199 - output.m() = temp;  
200 - output.file.set("position",idx);  
201 - idx++;  
202 -  
203 - *done = false;  
204 - TemplateList rVal;  
205 - rVal.append(output);  
206 -  
207 - return rVal;  
208 - }  
209 -  
210 - void write(const Template &t)  
211 - {  
212 - (void) t;  
213 - qFatal("Not implemented.");  
214 - }  
215 -  
216 -private:  
217 - qint64 idx;  
218 - int readInt()  
219 - {  
220 - int num;  
221 - seqFile.read((char*)&num, 4);  
222 - return num;  
223 - }  
224 -  
225 - // apparently the text in seq files is 16 bit characters (UTF-16?)  
226 - // since we don't really need the last byte, snad since it gets interpreted as  
227 - // a terminating char, let's just grab the first byte for storage  
228 - void readText(int bytes, char *buffer)  
229 - {  
230 - seqFile.read(buffer, bytes);  
231 - for (int i=0; i<bytes; i+=2) {  
232 - buffer[i/2] = buffer[i];  
233 - }  
234 - buffer[bytes/2] = '\0';  
235 - }  
236 -  
237 -protected:  
238 - std::ifstream seqFile;  
239 - QQueue<int> seekPos;  
240 - int width, height, numChan, imgSizeBytes, trueImgSizeBytes, numFrames;  
241 - QString imgFormat;  
242 - TemplateList annotations;  
243 -};  
244 -  
245 -BR_REGISTER(Gallery, seqGallery)  
246 -  
247 -} // namespace br  
248 -  
249 -#include "gallery/seq.moc"