4 * Copyright (C) Georg Martius - February 2011
5 * georg dot martius at web dot de
6 * Copyright (C) Alexey Osipov - Jule 2011
7 * simba at lerlan dot ru
8 * speed optimizations (threshold, spiral, SSE, asm)
10 * This file is part of vid.stab video stabilization library
12 * vid.stab is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License,
14 * as published by the Free Software Foundation; either version 2, or
15 * (at your option) any later version.
17 * vid.stab is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GNU Make; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 #ifndef MOTIONDETECT_H
29 #define MOTIONDETECT_H
34 #include "transformtype.h"
35 #include "vidstabdefines.h"
37 #include "frameinfo.h"
39 typedef struct _vsmotiondetectconfig
{
40 /* meta parameter for maxshift and fieldsize between 1 and 15 */
42 int accuracy
; // meta parameter for number of fields between 1 and 10
43 int stepSize
; // stepsize of field transformation detection
44 int algo
; // deprecated
46 /* if 1 and 2 then the fields and transforms are shown in the frames */
48 /* measurement fields with lower contrast are discarded */
49 double contrastThreshold
;
50 const char* modName
; // module name (used for logging)
51 } VSMotionDetectConfig
;
53 /** structure for motion detection fields */
54 typedef struct _vsmotiondetectfields
{
55 /* maximum number of pixels we expect the shift of subsequent frames */
57 int stepSize
; // stepsize for detection
58 int fieldNum
; // number of measurement fields
59 int maxFields
; // maximum number of fields used (selected by contrast)
60 double contrastThreshold
; // fields with lower contrast are discarded
61 int fieldSize
; // size = min(md->width, md->height)/10;
62 int fieldRows
; // number of rows
63 Field
* fields
; // measurement fields
64 short useOffset
; // if true then the offset us used
65 VSTransform offset
; // offset for detection (e.g. known from coarse scan)
66 } VSMotionDetectFields
;
68 /** data structure for motion detection part of deshaking*/
69 typedef struct _vsmotiondetect
{
72 VSMotionDetectConfig conf
;
74 VSMotionDetectFields fieldscoarse
;
75 VSMotionDetectFields fieldsfine
;
77 VSFrame curr
; // blurred version of current frame buffer
78 VSFrame currorig
; // current frame buffer (original) (only pointer)
79 VSFrame currtmp
; // temporary buffer for blurring
80 VSFrame prev
; // frame buffer for last frame (copied)
81 short hasSeenOneFrame
; // true if we have a valid previous frame
82 int initialized
; // 1 if initialized and 2 if configured
87 static const char vs_motiondetect_help
[] = ""
89 " Generates a file with relative transform information\n"
90 " (translation, rotation) about subsequent frames."
91 " See also transform.\n"
93 " 'result' path to the file used to write the transforms\n"
94 " (def:inputfile.stab)\n"
95 " 'shakiness' how shaky is the video and how quick is the camera?\n"
96 " 1: little (fast) 10: very strong/quick (slow) (def: 5)\n"
97 " 'accuracy' accuracy of detection process (>=shakiness)\n"
98 " 1: low (fast) 15: high (slow) (def: 9)\n"
99 " 'stepsize' stepsize of search process, region around minimum \n"
100 " is scanned with 1 pixel resolution (def: 6)\n"
101 " 'mincontrast' below this contrast a field is discarded (0-1) (def: 0.3)\n"
102 " 'tripod' virtual tripod mode (if >0): motion is compared to a \n"
103 " reference frame (frame # is the value) (def: 0)\n"
104 " 'show' 0: draw nothing (def); 1,2: show fields and transforms\n"
105 " in the resulting frames. Consider the 'preview' filter\n"
106 " 'help' print this help message\n";
109 /** returns the default config
111 VSMotionDetectConfig
vsMotionDetectGetDefaultConfig(const char* modName
);
113 /** initialized the VSMotionDetect structure and allocates memory
114 * for the frames and stuff
115 * @return VS_OK on success otherwise VS_ERROR
117 int vsMotionDetectInit(VSMotionDetect
* md
, const VSMotionDetectConfig
* conf
,
118 const VSFrameInfo
* fi
);
121 * Performs a motion detection step
122 * Only the new current frame is given. The last frame
123 * is stored internally
124 * @param motions: calculated local motions. (must be deleted manually)
126 int vsMotionDetection(VSMotionDetect
* md
, LocalMotions
* motions
, VSFrame
*frame
);
128 /** Deletes internal data structures.
129 * In order to use the VSMotionDetect again, you have to call vsMotionDetectInit
131 void vsMotionDetectionCleanup(VSMotionDetect
* md
);
133 /// returns the current config
134 void vsMotionDetectGetConfig(VSMotionDetectConfig
* conf
, const VSMotionDetect
* md
);
136 /// returns the frame info
137 const VSFrameInfo
* vsMotionDetectGetFrameInfo(const VSMotionDetect
* md
);
139 #endif /* MOTIONDETECT_H */
143 * c-file-style: "stroustrup"
144 * c-file-offsets: ((case-label . *) (statement-case-intro . *))
145 * indent-tabs-mode: nil
146 * c-basic-offset: 2 t
149 * vim: expandtab shiftwidth=2: