1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2002, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistributions of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistributions in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 // ////////////////////////////////////////////////////////////////////////////
45 // This file contains member functions of the BlobTracker class
46 // that deal with output data.
47 // FillDestinationData
51 // ////////////////////////////////////////////////////////////////////////////
53 #include "cvstreams.h"
54 #include "BlobTracker.h"
55 #include "BlobTrkObject.h"
59 template <class T> static inline T min(T a, T b) { return a < b ? a : b; }
60 template <class T> static inline T max(T a, T b) { return a > b ? a : b; }
62 // ////////////////////////////////////////////////////////////////////////////
63 // BlobTracker::FillDestinationData()
65 // Fills in the destination image based on estimated object location and state.
66 // Markers are displayed to indicate object position and search windows and
67 // other information of importance.
72 // ////////////////////////////////////////////////////////////////////////////
73 void BlobTracker::FillDestinationData(IplImage *image)
75 if (m_output_options != 0)
77 for (BlobTrackerObjectList::const_iterator object = m_objects->begin(); object != m_objects->end(); object++)
80 if (m_output_options & IBlobTracker::OUTPUT_COLOR_PIXELS)
82 CvRect rect = object->GetRect();
84 const unsigned char *pSrc = (const unsigned char *)m_image->imageData + rect.y * image->width;
85 unsigned char *pDst = (unsigned char *)image->imageData + rect.y * image->width;
86 for (int i = rect.y; i < rect.y + rect.height; i++)
88 for (int j = rect.x; j < rect.x + rect.width; j++)
91 pDst[j] = ((i ^ j) & 1) ? 255 : 0;
94 pDst += image->widthStep;
99 if (m_output_options & IBlobTracker::OUTPUT_BOUNDING_BOX)
101 CvRect rect = object->GetRect();
102 cvRectangle(image, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), 0xffffff, 1);
105 if (m_output_options & IBlobTracker::OUTPUT_CROSSHAIRS)
107 // Draw a cross at the estimated Object location
109 switch (object->GetId())
124 DrawCross(image, object->GetCenter(), color);
130 STDMETHODIMP BlobTracker::GetTrackedObjects(ITracker::TrackingInfo &tracked_objects)
132 tracked_objects.clear();
134 for (BlobTrackerObjectList::const_iterator object = m_objects->begin(); object != m_objects->end(); object++)
135 tracked_objects.push_back(cv3dTracker2dTrackedObject(object->GetId(), object->GetCenter()));
140 // ////////////////////////////////////////////////////////////////////////////
141 // BlobTracker::DrawCross(IplImage *image, CvPoint point)
143 // Draws a cross on the image at the point indicated
146 // image: image in which cross is being placed
147 // point: coordinates of center of cross
149 // ////////////////////////////////////////////////////////////////////////////
151 void BlobTracker::DrawCross(IplImage *image, CvPoint point, double color)
153 const int SIZE_OF_CROSS = 20;
155 int Left = max((int)point.x - SIZE_OF_CROSS, 0);
156 int Right = min((int)point.x + SIZE_OF_CROSS, (int)image->width - 1);
157 int Top = max((int)point.y - SIZE_OF_CROSS, 0);
158 int Bottom = min((int)point.y + SIZE_OF_CROSS, (int)image->height - 1);
160 cvLine(image, cvPoint(point.x, Top), cvPoint(point.x, Bottom), color);
161 cvLine(image, cvPoint(Left, point.y), cvPoint(Right, point.y), color);