Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Small changes

  • Loading branch information...
commit 3c6c562bda7bbaf55d2fbc2f62bb2e6b550275dd 1 parent d3e5b80
Diego Macrini macrini authored
13 MachineLearning/BehaviorAnalyzer.cpp
@@ -252,13 +252,17 @@ void BehaviorAnalyzer::Run()
252 252 }
253 253
254 254 // Set a 7-day X 2-scale matrix of indices
255   - IrregularScale dayScale(7, 2, 0); // important: init all to zero
  255 + // Map each day to its corresponding day index at each scale
  256 + //IrregularScale dayScale(7, 2, 0); // important: init all to zero
  257 + IrregularScale dayScale(7, 1, 0); // important: init all to zero
256 258
257 259 for (unsigned i = 0; i < 7; i++)
258 260 dayScale(i, 0) = i;
259 261
260   - dayScale(0, 1) = 1;
  262 + /*dayScale(0, 1) = 1;
261 263 dayScale(6, 1) = 1;
  264 + // other indices are set to zero above
  265 + */
262 266
263 267 RegularScale timeScale;
264 268
@@ -269,7 +273,10 @@ void BehaviorAnalyzer::Run()
269 273 */
270 274
271 275 m_tempPyr.init(m_eventCalendar, dayScale, timeScale,
272   - m_sessionInfo.frame_width, m_sessionInfo.frame_height, 6);
  276 + m_sessionInfo.frame_width, m_sessionInfo.frame_height, 6, 1);
  277 +
  278 + /*m_tempPyr.init(m_eventCalendar, dayScale, timeScale,
  279 + m_sessionInfo.frame_width, m_sessionInfo.frame_height, 1, 8);*/
273 280
274 281 m_tempPyr.processData(m_params.minProbLikelyEvents, m_params.maxProbUnlikelyEvents);
275 282
177 Tools/SpatioTemporalScale.h
@@ -112,9 +112,16 @@ class SpatialPyramid : public std::vector<SimpleMatrix<SpatialStats>>
112 112 m_imageHeight = rhs.m_imageHeight;
113 113 }
114 114
115   - SpatialPyramid(unsigned ni, unsigned nj, unsigned levels)
  115 + /*!
  116 + Constructs a pyramid with "levels" levels for representing
  117 + the data of an image of size ni * nj. The top level will
  118 + have "numCellAtTop" cell along the rows and along the columns.
  119 + Lower level will have a factor of two number of rows and columns
  120 + from their previous level.
  121 + */
  122 + SpatialPyramid(unsigned ni, unsigned nj, unsigned levels, unsigned topDelta)
116 123 {
117   - init(ni, nj, levels);
  124 + init(ni, nj, levels, topDelta);
118 125 }
119 126
120 127 void operator=(const SpatialPyramid& rhs)
@@ -127,11 +134,19 @@ class SpatialPyramid : public std::vector<SimpleMatrix<SpatialStats>>
127 134 m_imageHeight = rhs.m_imageHeight;
128 135 }
129 136
130   - void init(unsigned ni, unsigned nj, unsigned levels)
  137 + /*!
  138 + Constructs a pyramid with "levels" levels for representing
  139 + the data of an image of size ni * nj. The top level will
  140 + have "topDelta" cell along the rows and along the columns.
  141 + Lower level will have a factor of two number of rows and columns
  142 + from their previous level.
  143 + */
  144 + void init(unsigned ni, unsigned nj, unsigned levels, unsigned topDelta)
131 145 {
132 146 ASSERT(empty());
133 147 ASSERT(m_labelCounters.empty());
134 148 ASSERT(ni > 0 && nj > 0 && levels > 0);
  149 + ASSERT(topDelta >= 1);
135 150
136 151 m_imageWidth = ni;
137 152 m_imageHeight = nj;
@@ -141,14 +156,81 @@ class SpatialPyramid : public std::vector<SimpleMatrix<SpatialStats>>
141 156 m_labelCounters.resize(levels); // nested arrays are init to empty
142 157
143 158 // Set the number of elements in each level of the pyramid
144   - unsigned delta = 1;
  159 + unsigned delta = topDelta;
145 160
146 161 for (auto it = begin(); it != end(); ++it)
147 162 {
148 163 it->resize(delta, delta);
149 164 delta *= 2;
150 165 }
151   - };
  166 + }
  167 +
  168 + /*!
  169 + Initializes the pyramid as the merge of the given pair of
  170 + pyramids.
  171 + */
  172 + void initFromMerge(const SpatialPyramid& sp0, const SpatialPyramid& sp1)
  173 + {
  174 + ASSERT(!sp0.empty() && !sp1.empty());
  175 +
  176 + ASSERT(sp0.imageWidth() == sp1.imageWidth() &&
  177 + sp0.imageHeight() == sp1.imageHeight() &&
  178 + sp0.size() == sp1.size() &&
  179 + sp0.topDelta() == sp1.topDelta());
  180 +
  181 + init(sp0.imageWidth(), sp0.imageHeight(), sp0.size(), sp0.topDelta());
  182 +
  183 + int l0, l1;
  184 +
  185 + for (unsigned k = 0; k < size(); k++)
  186 + {
  187 + const SpatialPyramid::SpatialLevel& img0 = sp0.get(k);
  188 + const SpatialPyramid::SpatialLevel& img1 = sp1.get(k);
  189 + SpatialPyramid::SpatialLevel& img2 = get(k);
  190 +
  191 + SpatialStats::LABEL lbl;
  192 +
  193 + for (unsigned i = 0; i < img2.ni(); i++)
  194 + {
  195 + for (unsigned j = 0; j < img2.nj(); j++)
  196 + {
  197 + l0 = img0(i, j).label;
  198 + l1 = img1(i, j).label;
  199 +
  200 + if ((l0 <= SpatialStats::SOMETIMES && l1 >= SpatialStats::SOMETIMES) ||
  201 + (l0 >= SpatialStats::SOMETIMES && l1 <= SpatialStats::SOMETIMES))
  202 + {
  203 + lbl = SpatialStats::SOMETIMES;
  204 + }
  205 + else if (l0 == SpatialStats::ALWAYS && l1 == SpatialStats::ALWAYS)
  206 + {
  207 + lbl = SpatialStats::ALWAYS;
  208 + }
  209 + else if (l0 == SpatialStats::NEVER && l1 == SpatialStats::NEVER)
  210 + {
  211 + lbl = SpatialStats::NEVER;
  212 + }
  213 + else if (l0 < SpatialStats::SOMETIMES && l1 < SpatialStats::SOMETIMES)
  214 + {
  215 + lbl = SpatialStats::VERY_LIKELY;
  216 + }
  217 + else if (l0 > SpatialStats::SOMETIMES && l1 > SpatialStats::SOMETIMES)
  218 + {
  219 + lbl = SpatialStats::VERY_UNLIKELY;
  220 + }
  221 + else
  222 + {
  223 + ASSERT(false);
  224 + lbl = SpatialStats::SOMETIMES;
  225 + }
  226 +
  227 + img2(i, j).label = lbl;
  228 +
  229 + incrementLabelCounter(k, lbl);
  230 + }
  231 + }
  232 + }
  233 + }
152 234
153 235 unsigned imageWidth() const
154 236 {
@@ -160,6 +242,13 @@ class SpatialPyramid : public std::vector<SimpleMatrix<SpatialStats>>
160 242 return m_imageHeight;
161 243 }
162 244
  245 + unsigned topDelta() const
  246 + {
  247 + ASSERT(front().ni() == front().nj());
  248 +
  249 + return front().ni();
  250 + }
  251 +
163 252 unsigned ni(unsigned level) const
164 253 {
165 254 return get(level).ni();
@@ -296,72 +385,6 @@ class SpatialPyramid : public std::vector<SimpleMatrix<SpatialStats>>
296 385 return (label < m_labelCounters.back().size()) ? m_labelCounters.back()[label] : 0;
297 386 }
298 387
299   - /*!
300   - Initializes the pyramid as the merge of the given pair of
301   - pyramids.
302   - */
303   - void initFromMerge(const SpatialPyramid& sp0, const SpatialPyramid& sp1)
304   - {
305   - ASSERT(!sp0.empty() && !sp1.empty());
306   -
307   - ASSERT(sp0.imageWidth() == sp1.imageWidth() &&
308   - sp0.imageHeight() == sp1.imageHeight() &&
309   - sp0.size() == sp1.size());
310   -
311   - init(sp0.imageWidth(), sp0.imageHeight(), sp0.size());
312   -
313   - int l0, l1;
314   -
315   - for (unsigned k = 0; k < size(); k++)
316   - {
317   - const SpatialPyramid::SpatialLevel& img0 = sp0.get(k);
318   - const SpatialPyramid::SpatialLevel& img1 = sp1.get(k);
319   - SpatialPyramid::SpatialLevel& img2 = get(k);
320   -
321   - SpatialStats::LABEL lbl;
322   -
323   - for (unsigned i = 0; i < img2.ni(); i++)
324   - {
325   - for (unsigned j = 0; j < img2.nj(); j++)
326   - {
327   - l0 = img0(i, j).label;
328   - l1 = img1(i, j).label;
329   -
330   - if ((l0 <= SpatialStats::SOMETIMES && l1 >= SpatialStats::SOMETIMES) ||
331   - (l0 >= SpatialStats::SOMETIMES && l1 <= SpatialStats::SOMETIMES))
332   - {
333   - lbl = SpatialStats::SOMETIMES;
334   - }
335   - else if (l0 == SpatialStats::ALWAYS && l1 == SpatialStats::ALWAYS)
336   - {
337   - lbl = SpatialStats::ALWAYS;
338   - }
339   - else if (l0 == SpatialStats::NEVER && l1 == SpatialStats::NEVER)
340   - {
341   - lbl = SpatialStats::NEVER;
342   - }
343   - else if (l0 < SpatialStats::SOMETIMES && l1 < SpatialStats::SOMETIMES)
344   - {
345   - lbl = SpatialStats::VERY_LIKELY;
346   - }
347   - else if (l0 > SpatialStats::SOMETIMES && l1 > SpatialStats::SOMETIMES)
348   - {
349   - lbl = SpatialStats::VERY_UNLIKELY;
350   - }
351   - else
352   - {
353   - ASSERT(false);
354   - lbl = SpatialStats::SOMETIMES;
355   - }
356   -
357   - img2(i, j).label = lbl;
358   -
359   - incrementLabelCounter(k, lbl);
360   - }
361   - }
362   - }
363   - }
364   -
365 388 /*void add(const MotionEvent& me)
366 389 {
367 390 double cx, cy;
@@ -638,12 +661,12 @@ class DayTimeTable : public SimpleMatrix<DayTimeStats>
638 661
639 662 public:
640 663 void init(unsigned ni_day, unsigned nj_time, unsigned ni_img, unsigned nj_img,
641   - unsigned spatialPyramidLevels)
  664 + unsigned spatialPyramidLevels, unsigned topDelta)
642 665 {
643 666 ParentClass::resize(ni_day, nj_time);
644 667
645 668 for (auto it = begin(); it != end(); ++it)
646   - it->spatialPyramid.init(ni_img, nj_img, spatialPyramidLevels);
  669 + it->spatialPyramid.init(ni_img, nj_img, spatialPyramidLevels, topDelta);
647 670 }
648 671
649 672 /*!
@@ -890,15 +913,15 @@ class DayTimeMultiscaleTable
890 913
891 914 DayTimeMultiscaleTable(const EventCalendar& eventCalendar,
892 915 const IrregularScale& dayScale, const RegularScale& timeScale,
893   - unsigned ni_img, unsigned nj_img, unsigned spatialPyramidLevels)
  916 + unsigned ni_img, unsigned nj_img, unsigned spatialPyramidLevels, unsigned topDelta)
894 917 {
895 918 init(eventCalendar, dayScale, timeScale, ni_img, nj_img,
896   - spatialPyramidLevels);
  919 + spatialPyramidLevels, topDelta);
897 920 }
898 921
899 922 void init(const EventCalendar& eventCalendar,
900 923 const IrregularScale& dayScale, const RegularScale& timeScale,
901   - unsigned ni_img, unsigned nj_img, unsigned spatialPyramidLevels)
  924 + unsigned ni_img, unsigned nj_img, unsigned spatialPyramidLevels, unsigned topDelta)
902 925 {
903 926 ASSERT(m_levels.empty());
904 927
@@ -921,7 +944,7 @@ class DayTimeMultiscaleTable
921 944 for (unsigned ts = 0; ts < m_levels.nj(); ts++)
922 945 {
923 946 m_levels(ds, ts).init(dayScale.maxj(ds) + 1, nj, ni_img, nj_img,
924   - spatialPyramidLevels);
  947 + spatialPyramidLevels, topDelta);
925 948 }
926 949 }
927 950
BIN  VideoParserVC/VideoParserVC.suo
Binary file not shown

0 comments on commit 3c6c562

Please sign in to comment.
Something went wrong with that request. Please try again.