📄 faceobj.cpp
字号:
// FaceObj.cpp - by Robin Hewitt, 2005
// http://www.robinhewitt.com/mavis
// This is free software. See license at the bottom
// of this file for terms of use.
//
//////////////////////////////////////////////////////////////
// Implementation of FaceObj class
//
#include "FaceObj.h"
#include "Mavis.h"
#include "../Logger.h"
#include "../Params.h"
#include "../camera/Camera.h"
#include "FaceSearch.h"
#include "MVObjModel.h"
using namespace std;
using namespace MVDataUtils;
using namespace MVObjSearch;
//////////////////////////////////////////////////////////////
// FaceObj class
//
const int FaceObj::MAX_NEG_EXAMPLES = 100;
const int FaceObj::MAX_POS_EXAMPLES = 100;
//////////////////
// constructor
//
FaceObj::FaceObj(Mavis * pM, int id, string & dataDir) :
MVObjBase(pM), objId(id), pSearcher(0)
{
Logger * pLogger = pMavis->getLogger();
// get model number for this object ID
string record;
int modelNum;
DBAccessResult_t result =
getRecord(dataDir, MVDataUtils::OBJDB, id, record);
if(DB_SUCCESS == result)
if( DB_SUCCESS == getFieldValue(record, 2, &modelNum) )
{
FaceSearchParams searcherParams;
searcherParams.dataDir = dataDir;
searcherParams.modelNum = modelNum;
// Instantiate the searcher
try {
pSearcher = new FaceSearch(searcherParams);
} catch(MVErr& err) {
//// temp code
//string msg = "Error: ";
//msg += err.getMsg();
//cout << msg << endl;
//// end temp code
pLogger->writelnToLog("Error: %s", err.getMsg());
throw MavisErr(err);
}
}
else
throw MavisErr( "Object %d doesn\'t have a model", id );
else
{
throw MavisErr( "No record for object %d", id );
}
// Capture first example
countdownNeg = countdownPos = 0;
}
//////////////////
// destructor
//
FaceObj::~FaceObj()
{
if(pSearcher) delete pSearcher;
}
//////////////////
// lookOnce()
//
int FaceObj::lookOnce(ObjLoc_t * pObjLoc)
{
memset(pObjLoc, 0, sizeof(ObjLoc_t));
VideoFrame * pFrame = 0;
pFrame = pMavis->getNextFrame();
Result_t * pResult = pSearcher->search(*pFrame);
Logger * pLogger = pMavis->getLogger();
pLogger->writelnToLog("Looking for Learned Object number %d", objId);
ImgDB * pImgDB = pMavis->getImgDB();
// display the result
if(pResult->pHit)
{
Hit_t * pHit = pResult->pHit;
// Time to capture a positive example?
if(!countdownPos && pImgDB->getNPos() < MAX_POS_EXAMPLES)
{
pImgDB->addPosLook(objId, *pFrame, pHit->roi);
// reset countdownPos
countdownPos = 5;
}
else
--countdownPos;
// Outline the ROI
MVImgUtils::Vis::outlineROI(*pFrame, (pHit->roi), 0xffff00);
// write log entries
pLogger->writelnToLog("\tFound Learned Object. Strength = %.2g", pResult->pHit->strength);
//pLogger->writeFrame(pFrame->getData(), "face", "out.bmp");
}
else
{
// Time to capture a negative example?
int nPos = pImgDB->getNPos();
int nNeg = pImgDB->getNNeg();
if( (!countdownNeg) && (!nNeg || nNeg < nPos) && (nNeg < MAX_NEG_EXAMPLES) )
{
pImgDB->addNegLook(objId, *pFrame);
// reset countdownNeg
countdownNeg = 8;
}
else
--countdownNeg;
pLogger->writelnToLog("\tDidn\'t find Learned Object");
}
delete pResult;
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this
// license. If you do not agree to this license, do not download, install, copy or
// use the software.
//
//
// Mavis License Agreement
//
// Copyright (c) 2004-2006, Robin Hewitt (http://www.robin-hewitt.com).
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// This software is provided "as is" and any express or implied warranties, including,
// but not limited to, the implied warranties of merchantability and fitness for a
// particular purpose are disclaimed. In no event shall the authors or contributors be
// liable for any direct, indirect, incidental, special, exemplary, or consequential
// damages (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused and on any
// theory of liability, whether in contract, strict liability, or tort (including
// negligence or otherwise) arising in any way out of the use of this software, even
// if advised of the possibility of such damage.
///////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -