00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ENVISION_ENV_MOTION_CHANNEL_C_DEFINED
00039 #define ENVISION_ENV_MOTION_CHANNEL_C_DEFINED
00040
00041 #include "Envision/env_motion_channel.h"
00042
00043 #include "Envision/env_c_math_ops.h"
00044 #include "Envision/env_channel.h"
00045 #include "Envision/env_image_ops.h"
00046 #include "Envision/env_log.h"
00047 #include "Envision/env_params.h"
00048
00049 #ifdef ENV_WITH_DYNAMIC_CHANNELS
00050
00051
00052
00053
00054
00055
00056 void env_motion_channel_init(struct env_motion_channel* chan,
00057 const struct env_params* envp)
00058 {
00059 env_pyr_init_empty(&chan->unshifted_prev);
00060 chan->num_directions = envp->num_motion_directions;
00061 chan->shifted_prev = (struct env_pyr*)
00062 env_allocate(envp->num_motion_directions
00063 * sizeof(struct env_pyr));
00064 for (env_size_t i = 0; i < envp->num_motion_directions; ++i)
00065 env_pyr_init_empty(&chan->shifted_prev[i]);
00066 }
00067
00068
00069 void env_motion_channel_destroy(struct env_motion_channel* chan)
00070 {
00071 env_pyr_make_empty(&chan->unshifted_prev);
00072 for (env_size_t i = 0; i < chan->num_directions; ++i)
00073 env_pyr_make_empty(&chan->shifted_prev[i]);
00074 env_deallocate(chan->shifted_prev);
00075 chan->num_directions = 0;
00076 chan->shifted_prev = 0;
00077 }
00078
00079
00080 void env_motion_channel_input_and_consume_pyr(
00081 struct env_motion_channel* chan,
00082 const char* tagName,
00083 const struct env_params* envp,
00084 const struct env_math* imath,
00085 const struct env_dims inputdims,
00086 struct env_pyr* unshiftedCur,
00087 env_chan_status_func* status_func,
00088 void* status_userdata,
00089 struct env_image* result)
00090 {
00091 env_img_make_empty(result);
00092
00093 if (chan->num_directions != envp->num_motion_directions)
00094 {
00095 env_motion_channel_destroy(chan);
00096 env_motion_channel_init(chan, envp);
00097 }
00098
00099 if (chan->num_directions == 0)
00100 return;
00101
00102 const env_size_t firstlevel = envp->cs_lev_min;
00103 const env_size_t depth = env_max_pyr_depth(envp);
00104
00105 struct env_image chanOut = env_img_initializer;
00106
00107 char buf[17] =
00108 {
00109 'r', 'e', 'i', 'c', 'h', 'a', 'r', 'd', 't',
00110 '(', '_', '_',
00111 '/', '_', '_', ')', '\0'
00112 };
00113
00114 ENV_ASSERT(chan->num_directions <= 99);
00115
00116 buf[13] = '0' + (chan->num_directions / 10);
00117 buf[14] = '0' + (chan->num_directions % 10);
00118
00119
00120 for (env_size_t dir = 0; dir < chan->num_directions; ++dir)
00121 {
00122
00123 const env_size_t thetaidx =
00124 (dir * ENV_TRIG_TABSIZ) / chan->num_directions;
00125
00126 ENV_ASSERT(thetaidx < ENV_TRIG_TABSIZ);
00127
00128 buf[10] = '0' + ((dir+1) / 10);
00129 buf[11] = '0' + ((dir+1) % 10);
00130
00131
00132 struct env_pyr shiftedCur;
00133 env_pyr_init(&shiftedCur, depth);
00134
00135
00136 for (env_size_t i = firstlevel; i < depth; ++i)
00137 {
00138 env_img_resize_dims(env_pyr_imgw(&shiftedCur, i),
00139 env_pyr_img(unshiftedCur, i)->dims);
00140 env_shift_image(env_pyr_img(unshiftedCur, i),
00141 imath->costab[thetaidx],
00142 -imath->sintab[thetaidx],
00143 ENV_TRIG_NBITS,
00144 env_pyr_imgw(&shiftedCur, i));
00145 }
00146
00147 env_chan_direction(buf, envp, imath,
00148 inputdims,
00149 &chan->unshifted_prev, unshiftedCur,
00150 &chan->shifted_prev[dir], &shiftedCur,
00151 status_func, status_userdata, &chanOut);
00152
00153 env_pyr_swap(&chan->shifted_prev[dir], &shiftedCur);
00154 env_pyr_make_empty(&shiftedCur);
00155
00156 if (env_img_initialized(&chanOut))
00157 {
00158 if (!env_img_initialized(result))
00159 {
00160 env_img_resize_dims(result, chanOut.dims);
00161 env_c_image_div_scalar
00162 (env_img_pixels(&chanOut),
00163 env_img_size(&chanOut),
00164 (intg32) chan->num_directions,
00165 env_img_pixelsw(result));
00166 }
00167 else
00168 {
00169 ENV_ASSERT
00170 (env_dims_equal(chanOut.dims,
00171 result->dims));
00172 env_c_image_div_scalar_accum
00173 (env_img_pixels(&chanOut),
00174 env_img_size(&chanOut),
00175 (intg32) chan->num_directions,
00176 env_img_pixelsw(result));
00177 }
00178 }
00179 }
00180
00181 env_img_make_empty(&chanOut);
00182
00183 if (env_img_initialized(result))
00184 {
00185 env_max_normalize_inplace(result,
00186 INTMAXNORMMIN, INTMAXNORMMAX,
00187 envp->maxnorm_type,
00188 envp->range_thresh);
00189 if (status_func)
00190 (*status_func)(status_userdata, tagName, result);
00191 }
00192
00193 env_pyr_swap(unshiftedCur, &chan->unshifted_prev);
00194 env_pyr_make_empty(unshiftedCur);
00195 }
00196
00197 #endif // ENV_WITH_DYNAMIC_CHANNELS
00198
00199
00200
00201
00202
00203
00204
00205
00206 #endif // ENVISION_ENV_MOTION_CHANNEL_C_DEFINED