CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
common.h
1 /****************************************************************************
2  * Copyright (c) 2014, Joel Kivelä, Erkki Koskenkorva, Oskari Leppäaho,
3  * Mika Lehtinen and Petri Partanen.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ****************************************************************************/
30 #ifndef COMMON_H
31 #define COMMON_H
32 
33 #include <string>
34 
35 #include <QDebug>
36 
37 #include <opencv2/opencv.hpp>
38 #include <opencv2/highgui/highgui.hpp>
39 
40 #include "cavapa/cavapa.h"
41 
42 // Timers for retrieval/calculation etc. information.
43 //#define _DEBUG_TIMERS 1 // Comment out if you don't want them.
44 
45 namespace cavapa
46 {
47 // Name re-definitions for cavapa, as these might still change quite a lot.
48 using CalibrationPoint = calibration_point;
49 using CameraSettings = camera;
50 using CavapaDetector = detector;
51 using Sighting = sighting;
52 using Sightings = sightings;
53 } // namespace
54 
58 namespace cavapa_gui
59 {
68 enum class SourceType { CAMERA, NOTHING, STREAM, VIDEO, VIDEOSET };
69 
77 enum class ErrorLevel : int { INFO = 1, WARNING = 2, CRITICAL = 3 };
78 
83 enum class EXPORT_FLAGS : int {
84  NOTHING = 0x00, // No flags
85  APPEND = 0x01, // Append information to the file
86  USE_COMMA = 0x02, // Use comma as decimal separator
87 };
88 
95 static inline constexpr bool operator& (EXPORT_FLAGS a, EXPORT_FLAGS b)
96 {
97  return static_cast<int>(a) & static_cast<int>(b);
98 }
99 
106 static inline constexpr EXPORT_FLAGS operator| (EXPORT_FLAGS a, EXPORT_FLAGS b)
107 {
108  return static_cast<EXPORT_FLAGS>(static_cast<int>(a) | static_cast<int>(b));
109 }
110 
117 static inline constexpr EXPORT_FLAGS operator|= (EXPORT_FLAGS a, EXPORT_FLAGS b)
118 {
119  return EXPORT_FLAGS(a | b);
120 }
121 
130 static inline bool isNaN(double value)
131 {
132  return value != value;
133 }
134 
138 using FrameTime = std::uint64_t;
139 
145 struct Marker
146 {
150  bool active;
151 
156 
160  std::string text;
161 
168  bool operator < (const Marker& str) const{
169  return pos < str.pos;
170  }
171 };
172 
177 
184 {
188  std::string filename;
189 
194 
199 
203  std::vector<Marker> markers;
204 
209 
214 
219 };
220 
224 const int UNKNOWN_DEVICE = -2;
225 
229 using SourceID = unsigned int;
230 
235 
242 {
247 
252 
256  cv::Mat image;
257 };
258 
266 enum class FrameFlags : std::uint32_t {
267  FRAME_DEFAULT = 0, // Nothing special.
268  FRAME_STOP = 1, // This frame is an end frame.
269  FRAME_START = 2, // This frame is a start frame.
270  FRAME_DUPLICATE = 4,// This frame contains no new information from previous.
271  FRAME_WARNING = 8,// This frame had warnings during calculation.
272 };
273 
286 {
292 
298  float activity;
299 
303  float count;
304 
308  //FrameFlags flags;
309 
310  // This check is performed in order to check the correct member size of the
311  // structure to maintain 32bit & 64bit file format integrity.
312  static_assert(sizeof(FrameStats::activity) == 4
313  && sizeof(FrameStats::time) == 8
314  && sizeof(FrameStats::count) == 4,
315  "The size of the structure members is not correct.");
316 };
317 
328 {
332  unsigned int missed;
333 
337  unsigned int recorded;
338 
342  unsigned int retrieved;
343 
347  unsigned int total_recorded;
348 };
349 
350 // Empty statistics that can be used for zeroing
351 static const FrameCapture EMPTY_FRAME_CAPTURE = {0,0,cv::Mat()};
352 static const FrameStats EMPTY_FRAME_STATS = {0,0,0};
353 static const SourceStats EMPTY_SOURCE_STATS = {0,0,0,0};
354 
362 #define DISALLOW_COPY_AND_ASSIGN(f) \
363  f(const f&) = delete; \
364  f(f&&) = delete; \
365  f& operator =(const f&) = delete; \
366  f& operator =(f&&) = delete
367 } // namespace
368 
369 #endif // COMMON_H
FrameTime start
The period's start point.
Definition: common.h:208
FrameFlags
Parameter type to hold frame specific flags.
Definition: common.h:266
The structure holds the properties of a single marker on the graph.
Definition: common.h:145
Structure for holding frame statistics on activity.
Definition: common.h:285
unsigned int total_recorded
The total number of the frames recorded in all video files.
Definition: common.h:347
unsigned int SourceID
Used to indicate unique source ID-numbers.
Definition: common.h:229
const SourceID UNDEFINED_SOURCE
Used to indicate unknown sources.
Definition: common.h:234
cv::Mat image
The actual frame image.
Definition: common.h:256
std::vector< Marker > markers
The markers for the export.
Definition: common.h:203
FrameTime time
The calculation time of the frame.
Definition: common.h:291
unsigned int recorded
The frames recorded to the current video file.
Definition: common.h:337
EXPORT_FLAGS
The flags that are used for exporting the results.
Definition: common.h:83
FrameTime pos
The position of the marker.
Definition: common.h:155
FrameTime stop
The period's stop point.
Definition: common.h:213
float activity
The total activity on the frame.
Definition: common.h:298
The structure to hold statistics about the source performance.
Definition: common.h:327
FrameTime interval
The interval to be averaged in milliseconds.
Definition: common.h:198
std::string text
The text of the marker.
Definition: common.h:160
bool active
Defines if the marker is active or not.
Definition: common.h:150
int time_offset
The offset change for each marker time in seconds.
Definition: common.h:218
SourceType
Available source types are the following ones: CAMERA = hardware or network camera, NOTHING = not a working source, STREAM = network stream, VIDEO = video file and VIDEOSET = set of multiple files.
Definition: common.h:68
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
The structure is used for storing a single source frame.
Definition: common.h:241
unsigned int missed
The total number of the missed frames.
Definition: common.h:332
bool operator<(const Marker &str) const
Operator for sorting by time with std::sort.
Definition: common.h:168
EXPORT_FLAGS flags
The flags for export.
Definition: common.h:193
The structure holds CSV export options.
Definition: common.h:183
FrameTime time
The time of the frame.
Definition: common.h:251
float count
The number of detected sightings on the frame.
Definition: common.h:303
std::string filename
The export filename with full path.
Definition: common.h:188
unsigned int retrieved
The total number of the frames retrieved from the source.
Definition: common.h:342
const int UNKNOWN_DEVICE
Used to indicate unknown hardware device.
Definition: common.h:224
SourceID id
The source ID number.
Definition: common.h:246
ErrorLevel
Error level indicator.
Definition: common.h:77