#include namespace icl{ namespace regiondetector{ RegionDetector::RegionDetector(int iW, int iH, int iMinSize,int iMaxSize, int iMinValue, int iMaxValue): m_iW(iW),m_iH(iH),m_iDim(iW*iH),m_iMinSize(iMinSize), m_iMaxSize(iMaxSize),m_iMinValue(iMinValue),m_iMaxValue(iMaxValue){ m_ppoLim = new RegionDetectorBlobPart*[m_iDim]; memset(m_ppoLim,0,m_iDim*sizeof(RegionDetectorBlobPart*)); m_poBlobPartMM = new BlobPartMemoryManager(1000); m_poScanLineMM = new ScanLineMemoryManager(10000); m_poBlobList = new BlobList(0); RegionDetectorBlob::ensurePixelBufferSize(iW*iH*2); } RegionDetector::~RegionDetector(){ delete [] m_ppoLim; delete m_poBlobPartMM; delete m_poScanLineMM; for(int i=0;isize();i++){ delete (*m_poBlobList)[i]; } delete m_poBlobList; } void RegionDetector::setSize(const Size &size){ if(m_iW != size.width || m_iH != size.height){ m_iW = size.width; m_iH = size.height; m_iDim = m_iW*m_iH; RegionDetectorBlob::ensurePixelBufferSize(size.width*size.height*2); delete [] m_ppoLim; m_ppoLim = new RegionDetectorBlobPart*[m_iDim]; memset(m_ppoLim,0,m_iDim*sizeof(RegionDetectorBlobPart*)); } } void RegionDetector::setMinSize(int iMinSize){ this->m_iMinSize = iMinSize; } void RegionDetector::setMaxSize(int iMaxSize){ this->m_iMaxSize = iMaxSize; } void RegionDetector::setMinValue(int iMinValue){ this->m_iMinValue = iMinValue; } void RegionDetector::setMaxValue(int iMaxValue){ this->m_iMaxValue = iMaxValue; } BlobList *RegionDetector::find_blobs(icl8u *pucData){ //TODO remove icl8u *data = pucData; int i; int start_of_curr_pix_line = 0; // for the Compability of the *old* code RegionDetectorBlobPart **lim = m_ppoLim; int w = m_iW; int h = m_iH; // first pixel lim[0] = m_poBlobPartMM->next(); lim[0]->clear(); start_of_curr_pix_line = 0; // first row for(i=1;inext(); pl->update(0,start_of_curr_pix_line,i-1,w,data); lim[i-1]->add(pl); start_of_curr_pix_line = i; lim[i] = m_poBlobPartMM->next(); lim[i]->clear(); } } RegionDetectorScanLine *pl = m_poScanLineMM->next(); pl->update(0,start_of_curr_pix_line,w-1,w,data); lim[w-1]->add(pl); //rest of the image [1..w-1]x[1..h-1] RegionDetectorBlobPart **r_curr_line; RegionDetectorBlobPart **r_last_line; RegionDetectorBlobPart *r_to_delete; RegionDetectorBlobPart *r_to_keep; icl8u *im_curr_line; icl8u *im_last_line; int x,y,j; for(y=1;ynext(); r_curr_line[0]->clear(); } //rest of pixels start_of_curr_pix_line = 0; for(x=1;xadd(r_to_delete); for(j=0;jnext(); r_curr_line[x]->clear(); } RegionDetectorScanLine *pl = m_poScanLineMM->next(); pl->update(y,start_of_curr_pix_line,x-1,w,data); r_curr_line[x-1]->add(pl); start_of_curr_pix_line = x; } } RegionDetectorScanLine *pl = m_poScanLineMM->next(); pl->update(y,start_of_curr_pix_line,w-1,w,data); r_curr_line[w-1]->add(pl); } //Creating RegionDetectorBlobs recursivly //delete old blobs !! for(BlobList::iterator it = m_poBlobList->begin();it!= m_poBlobList->end();it++){ delete *it; } m_poBlobList->clear(); int iSize; icl8u ucVal; for(BlobPartMemoryManager::iterator it = m_poBlobPartMM->begin();it != m_poBlobPartMM->end();it++){ if(!((*it)->is_inside_other_region())){ RegionDetectorBlob *b = new RegionDetectorBlob(*it); iSize = b->size(); ucVal = b->val(); if((iSize >= m_iMinSize) && (iSize <= m_iMaxSize) && (ucVal >= m_iMinValue) && (ucVal <= m_iMaxValue)){ m_poBlobList->push_back(b); }else{ delete b; } } } m_poBlobPartMM->clear(); m_poScanLineMM->clear(); return m_poBlobList; } } }