71 virtual void FrameNotify(IplImage *img,
int frameNr) =0;
82 virtual const char*
GetName()
const =0;
87 std::map<std::string, GCPointer<FrameObs> >
observers;
88 typedef std::map<std::string, GCPointer<FrameObs> >::const_iterator
obs_iter;
92 i->second->FrameNotify(img,frameNr);
97 i->second->RegionInfoNotify(regions);
113 std::map<std::string, GCPointer<FrameObs> >::iterator
148 std::cout <<
fps.
get() <<
" fps" << std::endl;
153 return "frames per seconds";
169 cvReleaseVideoWriter(&
pWriter);
175 pWriter = cvCreateVideoWriter(
videoFName, CV_FOURCC(
'm',
'p',
'4',
'v'), 25, cvGetSize(img));
193 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
194 cvNamedWindow(
name.c_str());
196 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
199 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
200 cvDestroyWindow(
name.c_str());
204 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
205 MHDBGMSG_P(__FILE__,__LINE__,
"cvShowImage", img);
206 cvShowImage(
name.c_str(), img);
207 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
227 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
228 if (img==
nullptr)
return;
230 std::vector<ObjectPosition> result;
232 for (
unsigned int i=0;i<
matchers.size();i++) {
233 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
235 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
237 for (
unsigned int j=0;j<
matchers[i]->GetPoints().size();j++) {
248 CvPoint target =
matchers[i]->GetRandomTarget();
250 std::cout <<
matchers[i]->GetVisiconName()
251 <<
" found at position " << target << std::endl;
254 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
260 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
287 cvReleaseImage(&
copy);
292 IplImage*
GetCopy(IplImage*img,
int frameNr) {
296 copy = cvCloneImage(img);
298 copy = cvCreateImage(cvSize(img->width/
divisor,img->height/
divisor),img->depth,img->nChannels);
299 cvResize(img,
copy, CV_INTER_LINEAR);
306 cvResize(img,
copy, CV_INTER_LINEAR);
332 std::vector<float>
sd;
338 IplImage* pCopy =
GetCopy(img,frameNr);
342 cv::MatConstIterator_<cv::Vec3b> it = mat.begin<cv::Vec3b>(), it_end = mat.end<cv::Vec3b>();
343 for(; it != it_end; ++it) {
345 for(
int c=0;c<pCopy->nChannels;++c) {
346 float curVal = (*it)[c];
347 float curDiff = std::abs(curVal-
means[c])/
sd[c];
349 maxDiff = max(maxDiff, curDiff);
351 maxDiff = std::max(maxDiff, curDiff);
357 const unsigned char overlay = (maxDiff < 1.5f) ? 255 : 0;
358 for(
int c=0;c<pCopy->nChannels;++c) {
359 (*it)[c] += overlay/2;
363 unsigned char* p =
reinterpret_cast<unsigned char*
>(pCopy->imageData);
364 for(
int y=0; y<pCopy->height; ++y) {
365 unsigned char* row = p + y*pCopy->widthStep;
366 for(
int x=0; x<pCopy->width; ++x, row += pCopy->nChannels) {
368 for(
int c=0;c<pCopy->nChannels;++c) {
369 float curVal = row[c];
370 float curDiff = std::abs(curVal-
means[c])/
sd[c];
372 maxDiff = max(maxDiff, curDiff);
374 maxDiff = std::max(maxDiff, curDiff);
378 const unsigned char overlay = (maxDiff < 1.5f) ? 255 : 0;
379 for(
int c=0;c<pCopy->nChannels;++c) {
380 row[c] = row[c] / 2 + overlay/2;
428 IplImage* pCopy =
GetCopy(img,frameNr);
438 unsigned char* p =
reinterpret_cast<unsigned char*
>(pCopy->imageData);
439 const unsigned char* pPrev =
reinterpret_cast<unsigned char*
>(
pWorkImg->imageData);
440 for(
int y=0; y<pCopy->height; ++y) {
441 unsigned char* row = p + y*pCopy->widthStep;
442 const unsigned char* rowPrev = pPrev + y*
pWorkImg->widthStep;
445 ++x, row += pCopy->nChannels, rowPrev +=
pWorkImg->nChannels) {
447 for(
int c=0;c<pCopy->nChannels;++c) {
451 row[c] = min(abs(cur),255);
453 row[c] = std::min(abs(cur),255);
487 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
490 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
498 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
500 std::vector<ObjectPosition> result;
504 (region.bottom+region.top) / 2,
505 region.right-region.left,
506 region.bottom-region.top,
507 region.info.c_str()));
511 << region.left <<
";"
514 << region.info << std::endl;
521 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
549 cvReleaseImage(&
gray);
552 if (img==
nullptr)
return;
554 if (img->nChannels==3) {
557 gray = cvCreateImage(cvSize(img->width,img->height), IPL_DEPTH_8U, 1);
559 cvCvtColor(img,
gray, CV_BGR2GRAY);
586 #define ATTLOC_CROSS_LWIDTH 2
621 :
focus(cvPoint(-10,-10)),
622 mouse(cvPoint(-10,-10)) {
630 if (img==
nullptr)
return;
631 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
633 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
635 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
637 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
639 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
646 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
651 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
654 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
659 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
662 return "attended location";
680 if (img==
nullptr)
return;
686 static_cast<int>(img->height - img->height*.5)));
689 static_cast<int>(img->height - img->height*.75)));
703 std::ostringstream ostr;
718 return "optical flow";
734 if (img==
nullptr)
return;
738 return "match-contour";
756 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
758 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
761 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
766 cvReleaseImage(&
canny);
770 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
772 cvReleaseImage(&
canny);
777 MHDBGMSG(__FILE__,__LINE__,__PRETTY_FUNCTION__);
778 if (img==
nullptr)
return;
780 if (
canny==0)
canny = cvCreateImage(cvGetSize(gray), 8, 1);
783 cvCanny(gray,
canny, 50, 200, 3);
785 CV_HOUGH_PROBABILISTIC, 1, CV_PI/180,
790 for(
int i = 0; i < lines->total; i++) {
791 CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
792 cvLine(
GetCopy(img,frameNr), line[0], line[1], CV_RGB(255,0,0), 2, 8 );