📄 learnedobj.cpp
字号:
// LearnedObj.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 LearnedObj class
//
#include "LearnedObj.h"
#include "Mavis.h"
#include "../Logger.h"
#include "../Params.h"
#include "../camera/Camera.h"
#include "MVObjModel.h"
using namespace std;
using namespace MVDataUtils;
using namespace MVObjSearch;
//////////////////////////////////////////////////////////////
// LearnedObj class
//
const int LearnedObj::MAX_NEG_EXAMPLES = 100;
const int LearnedObj::MAX_POS_EXAMPLES = 100;
//////////////////
// constructor
//
LearnedObj::LearnedObj(Mavis * pM, int id, string & dataDir) :
MVObjBase(pM), objId(id), pSearchCtl(0)
{
// 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) )
{
//cout << " modelNum = " << modelNum << "\n";
// instantiate the SearchCtl object
SearchCtlParams params;
params.dataDir = dataDir;
params.modelNum = modelNum;
try
{
pSearchCtl = new SearchCtl(params);
}
catch(MVObjErr & err)
{
throw MavisErr(err);
}
}
else
throw MavisErr( "Object %d doesn\'t have a model", id );
else
{
//todo: base error message on returned DBAccessResult_t value
throw MavisErr( "No record for object %d", id );
}
// Capture first example
countdownNeg = countdownPos = 0;
}
//////////////////
// destructor
//
LearnedObj::~LearnedObj()
{
if(pSearchCtl) delete pSearchCtl;
}
//////////////////
// lookOnce()
//
int LearnedObj::lookOnce(ObjLoc_t * pObjLoc)
{
memset(pObjLoc, 0, sizeof(ObjLoc_t));
VideoFrame * pFrame = 0;
pFrame = pMavis->getNextFrame();
Result_t * pResult = pSearchCtl->search(*pFrame);
Logger * pLogger = pMavis->getLogger();
pLogger->writelnToLog("Looking for Learned Object number %d", objId);
ImgDB * pImgDB = pMavis->getImgDB();
// display the result
if(pResult)
{
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);
pLogger->writelnToLog("\tFound Learned Object. Strength = %.2g", pResult->pHit->strength);
delete pResult;
}
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");
}
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-2005, 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 + -