Exemplo n.º 1
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
/*
     Функция:
        CFSaveToDIB
     Цель:
         Сохраняет изображение в формате DIB
     Параметры:
       [ in ] hImage  - дескриптор изображения
       [ out ] info   - указатель на заголовок DIB
       [ out ] DIBPixels - указатель на пиксели изображения
     Возвращаемые заначения:
     CF_SUCCESS - данные изображения успешно записаны в память.
     в противном случае возвращает код ошибки.
     Замечания:
     Функция всегда записывает любое изображение hImage в формате
     DIB, который имеет глубину цвета 3 байта
*/
CF_ERROR __EXPORT_TYPE CFSaveToDIB( CF_IMAGE hImage, CF_BMP* info, BYTE* DIBPixels )
{
    CF_ERROR status = CF_SUCCESS;
     if(info == NULL)
    {
        status = CFF_INVALID_DIB;
        return status;
    }

	TLFImage* image = (TLFImage*)hImage;
    if(image == NULL)
    {
        status = CFF_INVALID_HANDLE;
		return status;
    }
    BITMAPINFO lInfo;
    memcpy( &lInfo, info, sizeof( BITMAPINFO ) );
    bool flag = DIBPixels == NULL? false : true;
    if(awpImageToDIB( image->GetImage(), &lInfo, (void**)(&DIBPixels), flag )!=AWP_OK)
	{
        status = CFF_INVALID_DIB;
        return status;
    }
    memcpy( info, &lInfo, sizeof( BITMAPINFO ) );  
    return status;
}
Exemplo n.º 2
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
CF_ERROR __EXPORT_TYPE CFGetImageParams(CF_IMAGE hImage, CF_IMAGE_PARAMS* pParams)
{
	CF_ERROR status = CF_SUCCESS;
	// проверим входные параметры
	if (pParams == NULL)
	{
		return CFF_INVALID_PARAM;
	}
	TLFImage* image = (TLFImage*)hImage;
	if(image == NULL)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	awpImage* pImage = NULL;
	pImage = image->GetImage();
	if (awpCheckImage(pImage) != AWP_OK)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	pParams->width = pImage->sSizeX;
	pParams->height = pImage->sSizeY;
	switch(pImage->bChannels)
	{
		case 1:
			pParams->bpp = 8;
		break;
		case 3:
			pParams->bpp = 24;
		break;
	}
	return status;
}
Exemplo n.º 3
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
// запись растрового изображения в неструктурированную память
CF_ERROR __EXPORT_TYPE CFSaveToDump(CF_IMAGE hImage, CF_WORD* pWidth, CF_WORD* pHeight, CF_WORD* pBpp, CF_BYTE* buffer)
{
	CF_ERROR status = CF_SUCCESS;
	// проверим входные параметры дескриптора изображения
	TLFImage* image = (TLFImage*)hImage;
	if(image == NULL)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	awpImage* pImage = NULL;
	pImage = image->GetImage();
	if (awpCheckImage(pImage) != AWP_OK)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	// проверим возможность конвертации изображения 

    //проверим остальные параметры
	if (pWidth == NULL || pHeight == NULL || pBpp == NULL || buffer == NULL)
	{
		return CFF_INVALID_PARAM;
	}
	// выполним копирование
	*pWidth = pImage->sSizeX;
	*pHeight= pImage->sSizeY;
	*pBpp   = 8*pImage->bChannels;
	int bufsize = pImage->sSizeX*pImage->sSizeY*pImage->bChannels;
	CF_BYTE* b = (CF_BYTE*)pImage->pPixels;
	memcpy(buffer, b, bufsize);
	return status;
}
Exemplo n.º 4
0
//-------------------------------TLFEmptyAverageNNPredictor----------------------
TLFDblVector* TLFEmptyAverageNNPredictor::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	ILFObjectDetector* d = engine->GetDetector(0);
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	if (img == NULL)
		return NULL;
	TLFDblVector* data = new TLFDblVector(id);
	double w = (double)rect->Width() / 8;
	double h = (double)rect->Height() /8;
	double s = w*h;
	for (int y = 0; y < 8; y++)
	{
		int yy = (int)floor(rect->Top() + y*w + 0.5);
		for (int x = 0; x < 8 ; x++)
		{
			int xx = (int)floor(rect->Left() + x*w + 0.5);
			double value = img->CalcLnSum(xx, yy, (int)w, (int)h)/s;
			data->AddValue(value);
		}
	}
	return data;
}
Exemplo n.º 5
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
/*
    CFLoadFromDIB
	loads image from Windows DIB 
*/
CF_ERROR __EXPORT_TYPE CFLoadFromDIB( CF_IMAGE hImage, CF_BMP info, BYTE* DIBPixels )
{
    CF_ERROR status = CF_SUCCESS;
    TLFImage* image = (TLFImage*)hImage;
    if(image == NULL)
    {
        status = CFF_INVALID_HANDLE;
        return status;
    }
	awpImage* img = NULL;
    BITMAPINFO lInfo;
    memcpy( &lInfo, &info, sizeof(CF_BMP) );
    if( awpDIBToImage(&lInfo, DIBPixels, &img)!= AWP_OK )
    {
        status = CFF_INVALID_DIB;
        return status;
    }
    try
    {
        image->SetImage( img );
    }
    catch (...)
    {
        status = CFCR_NOT_ENOUGH_MEMORY;
        awpReleaseImage(&img);
        return status;
    }
    awpReleaseImage(&img);
    return status;
}
Exemplo n.º 6
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
/*
     Функция:
        CFDIBSize
     Цель:
         Возвращает размер буфера, необходимый для сохранения
         изображения в формате DIB
     Параметры:
       [ in ] hImage  - дескриптор изображения
       [ out ] pSize  - указатель на переменную, в которой будет сохранено
                        значение размера буфера.
     Возвращаемые заначения:
     CF_SUCCESS - Переменная pSize cодержит значение размера буфера
     в противном случае возвращает код ошибки.
*/
CF_ERROR __EXPORT_TYPE CFDIBSize(CF_IMAGE hImage, int* pSize)
{
    CF_ERROR status = CF_SUCCESS;
    // проверим входные параметры
    if (pSize == NULL)
    {
        return CFF_INVALID_PARAM;
    }
    TLFImage* image = (TLFImage*)hImage;
    if(image == NULL)
    {
        status = CFF_INVALID_HANDLE;
        *pSize = 0;
		return status;
	}
	*pSize = 0;
	awpImage* pImage = NULL;
	pImage = image->GetImage();
	if (awpCheckImage(pImage) != AWP_OK)
	{
		status = CFF_INVALID_HANDLE;
		*pSize = 0;
		return status;
	}
	int dib_width = ((pImage->sSizeX*24 + 31)/32) * 4; /* aligned to 4 bytes */
	*pSize = dib_width*pImage->sSizeY;
	return status;
}
Exemplo n.º 7
0
TLFRect* TLFMomentsPredictor::Predict(ILFDetectEngine* engine)
{
 	TLFFGEngine* e = dynamic_cast<TLFFGEngine*>(engine);
	if (e == NULL)
		return NULL;
	if (m_pPredicted != NULL)
	{
		delete m_pPredicted;
		m_pPredicted = NULL;
	}
	TLFImage* fg = e->GetForegroundImage();
	if (fg != NULL)
	{
	   SLFBinaryMoments m;
	   TLFThresholdProc* proc = e->GetThresholdProc();
	   if (e != NULL)
	   {
			TLFRect r;
			r.SetRect(m_rect.GetRect());
			r.Inflate(2,2);
			proc->ProcessMoments(r, m);
			if (m.area > 0)
			{
				awpRect o_rect;
				o_rect.left = (AWPSHORT)GetMinMomnetsX(m); if (o_rect.left < 0)  o_rect.left = 0; 
				o_rect.top = (AWPSHORT)GetMinMomnetsY(m);  if (o_rect.top < 0) o_rect.top = 0;
				o_rect.right = (AWPSHORT)GetMaxMomnetsX(m); if (o_rect.right >= fg->GetImage()->sSizeX) o_rect.right = fg->GetImage()->sSizeX - 1;
				o_rect.bottom = (AWPSHORT)GetMaxMomnetsY(m); if (o_rect.bottom >= fg->GetImage()->sSizeY) o_rect.bottom = fg->GetImage()->sSizeY - 1;
				double w  = o_rect.right - o_rect.left;
				double h  = o_rect.bottom - o_rect.top;
				double s = (o_rect.right - o_rect.left)*(o_rect.bottom - o_rect.top);
				double s1 = fg->GetImage()->sSizeX*fg->GetImage()->sSizeY;
   				if (m.area/s > 0)
				{

					TLFRect* r_result = new TLFRect();
					r_result->SetRect(o_rect);
					r_result->Inflate(2,2);
					m_pPredicted = r_result;
					m_rect.SetRect(r_result->GetRect());
					return r_result;

				}
				else
		  			return NULL;
			}
			else
				return NULL;
	   }
	   else
		return NULL;
	}
	else
		return NULL;
}
Exemplo n.º 8
0
TLFRect* TLFIntegralImagePredictor::Predict(ILFDetectEngine* engine)
{
	TLFFGEngine* e = dynamic_cast<TLFFGEngine*>(engine);
	if (e == NULL)
		return NULL;
	if (m_pPredicted != NULL)
	{
		delete m_pPredicted;
		m_pPredicted = NULL;
	}
	TLFImage* fg = e->GetForegroundImage();
	double max_s = 0;
	double value;
	double overlap;
	double s;
	int idx = -1;
	for (int i = 0; i < m_scanner->GetFragmentsCount(); i++)
	{
		awpRect rect = m_scanner->GetFragmentRect(i);
		s  = (rect.right - rect.left)*(rect.bottom - rect.top);

		overlap = m_rect.RectOverlap(rect);
		if (overlap > 0.5)
		{
			value = pow(1.1,overlap)*fg->CalcLnSum(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top) /s;
			if (value > max_s)
			{
				max_s = value;
				idx = i;
			}
		}
	}
	if (idx < 0)
	{
		m_pPredicted = NULL;
		return NULL;
	}
	else
	{
		TLFRect* r_result = new TLFRect();
		r_result->SetRect(m_scanner->GetFragmentRect(idx));
		awpRect rr = r_result->GetRect();
		//awpFillRect(e->GetForeground(), &rr, 0, 0);
		m_pPredicted = r_result;
		m_rect.SetRect(r_result->GetRect());
		return r_result;
	}
}
Exemplo n.º 9
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
/*
    Функция:
        CFSaveImage
    Цель:
        Сохраняет изображение в формате jpeg на диске
    Параметры:
        [in] hImage - дескриптор изображения
        [in] path   - полное имя файла для записи.
    Возвращаемые заначения:
		CF_SUCCESS - в случае упешной записи файла.
        в противном случае возвращает код ошибки.
*/
CF_ERROR __EXPORT_TYPE CFSaveImage( CF_IMAGE hImage, char* path )
{
    CF_ERROR status = CF_SUCCESS;
    TLFImage* image = (TLFImage*)hImage;
    if(image == NULL)
    {
        status = CFF_INVALID_HANDLE;
        return status;
    }
	if(!image->SaveImage( path ))
    {
        status = CFF_CANNOT_SAVE_IMAGE;
        return status;
    }  
    return status;
}
Exemplo n.º 10
0
TLFDescriptor* TLFAverageNNTracker::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	TSCObjectDetector* d = dynamic_cast<TSCObjectDetector*>(engine->GetDetector(0));
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	if (img == NULL || img->GetImage() == NULL)
		return NULL;

	//
	int idx = d->GetStagesCount() - 1;
	TLFObjectList* stages = d->GetStrongs();

	TCSStrong* s = dynamic_cast<TCSStrong*>(stages->Get(idx));
	if (s == NULL)
		return NULL;
	double* data = (double*)malloc(s->GetCount()*sizeof(double));
	int width = rect->Width();
	double scale_coef = (double)width / (double)d->GetBaseWidth();
	TLFRect fragment;

	for (int i = 0; i < s->GetCount(); i++)
	{
		ILFWeak  * weak = s->GetWeak(i);
		if (weak != NULL)
		{
			TCSSensor* sensor = dynamic_cast<TCSSensor*>(weak->Fetaure());
			awpRect Fragment = sensor->GetRect();

			fragment.SetRect(Fragment);
			fragment.Scale(scale_coef);
			fragment.Shift(rect->Left(), rect->Top());

			Fragment = fragment.GetRect();
			double s = fragment.Width()*fragment.Height();
			double value = img->CalcLnSum(Fragment.left, Fragment.top, fragment.Width(), fragment.Height());
			value /= s;
			data[i] = value;

		}
	}
	TLFDescriptor* dscr = new TLFDescriptor(s->GetCount(), id, data);
	free(data);
	return dscr;
}
Exemplo n.º 11
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
/*
	CFLoadImage
	Load image from path 
*/
CF_ERROR __EXPORT_TYPE CFLoadImage( CF_IMAGE hImage, char* path )
{
    CF_ERROR status = CF_SUCCESS;
    // преобразование типов.
    TLFImage* image = (TLFImage*)hImage;
    if(image == NULL)
    {
        status = CFF_INVALID_HANDLE;
        return status;
    }

    if(!image->LoadImage( path ))
    {
        status = CFF_CANNOT_LOAD_IMAGE;
        return status;
    }    
	return status;
}
Exemplo n.º 12
0
TLFDblVector* TLFAverageNNPredictor::Features(ILFDetectEngine* engine, TLFRect* rect, int id)
{
	if (engine == NULL || rect == NULL)
		return NULL;
	ILFObjectDetector* d = engine->GetDetector(0);
	if (d == NULL)
		return NULL;
	TLFImage* img = d->GetImage();
	img->GetIntegralImage();
	if (img == NULL || img->GetImage() == NULL)
		return NULL;

	//
	int idx = d->GetStagesCount() - 1;
	TLFObjectList* stages = d->GetStrongs();

	ILFStrong* s = dynamic_cast<TCSStrong*>(stages->Get(idx));
	if (s == NULL)
		return NULL;
	int width = rect->Width();
	double scale_coef = (double)width / (double)d->GetBaseWidth();
	TLFRect fragment;
	TLFDblVector* data = new TLFDblVector(id);
	for (int i = 0; i < s->GetCount(); i++)
	{
		ILFWeak  * weak = s->GetWeak(i);
		if (weak != NULL)
		{
			TCSSensor* sensor = dynamic_cast<TCSSensor*>(weak->Fetaure());
			awpRect Fragment = sensor->GetRect();

			fragment.SetRect(Fragment);
			fragment.Scale(scale_coef);
			fragment.Shift(rect->Left(), rect->Top());

			Fragment = fragment.GetRect();
			double s = fragment.Width()*fragment.Height();
			double value = img->CalcLnSum(Fragment.left, Fragment.top, fragment.Width(), fragment.Height());
			value /= s;
			data->AddValue(value);
		}
	}
	return data;
}
Exemplo n.º 13
0
bool TLFSabotage::PorocessImage(awpImage* img, bool* result)
{
	*result = false;
	if (img == NULL)
		return false;
	// преобразования. 
	awpImage* tmp = NULL;
	// копируем входное изображение во временное. 
	if (awpCopyImage(img, &tmp) != AWP_OK)
		return false;
	if (tmp->sSizeX != this->m_srcWidth || tmp->sSizeY != this->m_srcHeight || tmp->bChannels != this->m_srcBPP)
	{
		// переинициализация
		TLFImage initImage;
		initImage.SetImage(img);
		this->Init(&initImage);
		_AWP_SAFE_RELEASE_(tmp)
		return true;
	}
Exemplo n.º 14
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
// загрузака растрового изображения из неструктуированной памяти. 
CF_ERROR __EXPORT_TYPE CFLoadFromDump(CF_IMAGE hImage, CF_WORD width, CF_WORD height, CF_WORD bpp, CF_BYTE* pixels,  CF_WORD line_width)
{
	CF_ERROR status = CF_SUCCESS;
    // получение указателя на изображение
	TLFImage* image = (TLFImage*)hImage;
	if(image == NULL)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	// проверка указателя на пиксели
	if (pixels == NULL)
	{
		status = CFF_INVALID_PARAM;
		return status;
	}
	// проверка числа битов на пиксель
	if (bpp != 8 && bpp != 24)
	{
		status = CFF_INVALID_PARAM;
		return status;
	}
	awpImage* tmp = NULL;
	if (awpCreateImage(&tmp, width, height, bpp == 8?1:3, AWP_BYTE) != AWP_OK)
	{
	   status = CFCR_NOT_ENOUGH_MEMORY;
	   return status;
	}
	// копирование пикселей в изображение tmp
	int bufsize = width*(bpp == 8 ? 1:3);// число байт в строке, с возможным выравниваием
	BYTE* b = (BYTE*)tmp->pPixels;
	for (int i = 0; i < height; i++)
	{
		memcpy(b, pixels, bufsize);
		b+= bufsize; 
		pixels += line_width;
	}
	image->SetImage(tmp);
	awpReleaseImage(&tmp);
	return status;
}
Exemplo n.º 15
0
bool CLBPTrackCompare::LoadCheckTrack(const char* lpFileName)
{
    bool res = CNCCPTrackCompare::LoadCheckTrack(lpFileName);
    this->m_checklbp.Clear();
    if (res)
    {
        for (int i = 0; i < this->m_pcheck->GetNumImages(); i++)
        {
            awpImage* img = this->m_pcheck->GetImage(i);
            awpImage* dscr = NULL;
            int descrSize = 59;
            int imgHeight = 16;
            awpCreateImage(&dscr, descrSize, imgHeight, 1, AWP_DOUBLE);
            awpLBPGridDescriptor(img, dscr, NULL, 4, 4, AWP_LBP_U2R1, true, 1);
            TLFImage* lfimg = new TLFImage();
            lfimg->SetImage(dscr);
            this->m_checklbp.Add(lfimg);
        }
    }
    return res;
}
Exemplo n.º 16
0
Arquivo: cfimage.cpp Projeto: hatc/ekc
CF_ERROR __EXPORT_TYPE CFGetDumpSize(CF_IMAGE hImage, CF_DWORD* pDumpSize)
{
	CF_ERROR status = CF_SUCCESS;
	TLFImage* image = (TLFImage*)hImage;
	if(image == NULL)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	awpImage* pImage = NULL;
	pImage = image->GetImage();
	if (awpCheckImage(pImage) != AWP_OK)
	{
		status = CFF_INVALID_HANDLE;
		return status;
	}
	if (pDumpSize == NULL)
		return CFF_INVALID_PARAM;
	//todo: здесь мы предполагаем, что изображения могут быть либо 
	//полутоновыми, либо цветными, пиксели содержат только 1 байт на цвет
	*pDumpSize = pImage->sSizeX*pImage->sSizeY*(pImage->bChannels == 1?1:3);
	return status;
}
Exemplo n.º 17
0
void TLFDBLabeledImages::GetFarFrr(TLFDetectEngine& engine, double& Far, double& Frr, double overlap)
{
	Far = 0;
	Frr = 0;
	if (GetItemsCount() == 0)
		return;

	for (int i = 0; i < m_dataFiles.GetCount(); i++)
	{ 
		TLFDBSementicDescriptor* d = (TLFDBSementicDescriptor*)m_dataFiles.Get(i);
		string strImageName = d->GetImageFile();
		TLFImage img;
		img.LoadImage(strImageName.c_str());
		engine.SetSourceImage(&img, true);
		TLFSemanticImageDescriptor* d1 = engine.GetSemantic();
		Far += d1->Compare(d, overlap);
		Frr += d->Compare(d1, overlap);
		if (i % 100 == 0)
			printf(">");
	}
	printf("\n");
	Far /= GetItemsCount();
	Frr /= GetItemsCount();
}
Exemplo n.º 18
0
void TLFTriangleList::Process(TLFImage& img)
{
    Process(img.GetImage());
}
Exemplo n.º 19
0
 int _tmain(int argc, _TCHAR* argv[])
{
 	if (argc < 2)
	{
		Usage();
		return 1;
	}

	// main program
	TiXmlDocument doc;
	if (!doc.LoadFile(argv[1]))
	{
		printf("error: cannot load configuration.\n");
		return 1;
	}

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem = NULL;
	pElem = hDoc.FirstChildElement().Element();
	if (!pElem)
	{
		printf("error: invalid configuration file.\n");
		return 1;
	}
   const char* name = pElem->Value();
   if (strcmp(name, "fvcccheck") != 0)
	{
		printf("error: invalid configuration file.\n");
		return 1;
	}

	string path 	     =  pElem->Attribute("in_database");
	string outName       =  pElem->Attribute("out_name");
	string tmplName      =  pElem->Attribute("tmpl_name");


	printf("params:\n");

	printf("input database: %s\n", path.c_str());
	printf("out name: %s\n", outName.c_str());
	printf("tmpl name: %s\n", tmplName.c_str());

	FvcTemplate* tmpl = NULL;
	if (fvcLoadTemplate(tmplName.c_str(), &tmpl) != FVC_OK)
	{
        printf("error: cannot load template.\n");
		return 1;
	}

	printf("template width %i:\n", tmpl->nVectorWidth);
	printf("template height %i:\n", tmpl->nVectorHeight);
	printf("template num vectors %i:\n", tmpl->nNumVectors);

	_finddata_t filesInfo;
	int num_images = 0;
	long handle = 0;
	FILE* f = fopen(outName.c_str(), "w+t");
	if ( (handle = _findfirst( (char*)((path+"*.awp").c_str()), &filesInfo)) != -1 )
	{
		do
		{
			string name = path + filesInfo.name;
			TLFImage image;
			if (!image.LoadImage((char*)name.c_str()))
			{
				printf("cannot load image %s \n", name.c_str());
				continue;
			}
			num_images++;
			double ro = 0;

			awpImage* img = image.GetImage();
			awpConvert(img, AWP_CONVERT_TO_FLOAT);
			fvcCompare(img, tmpl, &ro, FVC_COMPARE_EUCLID);
			float ro1 = ro;
			fprintf(f, "%s\t%f\n", filesInfo.name, ro1);
/*			awpImage* rec = NULL;
			if (fvcGetReconstruction(tmpl, img, &rec) != FVC_OK)
				printf("reconstruction error.\n");
			if (rec != NULL)
			{
				awpImage* norm = NULL;
				awpNormalize(rec, &norm, AWP_NORM_L2);
				awpConvert(norm, AWP_CONVERT_TO_FLOAT);
				//
				double ro = 0;
				if (awpDistance(img, rec, AWP_DIST_L2 ,&ro) != AWP_OK)
					printf("distance error.\n");
				float ro1 = ro;
				fprintf(f, "%s\t%f\n", filesInfo.name, ro1);
				awpReleaseImage(&rec);
				awpReleaseImage(&norm);
			}*/

			if (num_images % 100 == 0)
				printf(">");

		}while(!_findnext( handle, &filesInfo ));
	}
	_findclose( handle );
	fclose(f);


	printf("\ndone.\n");
	return 0;
}
Exemplo n.º 20
0
int _tmain(int argc, _TCHAR* argv[])
{
	if (argc < 2)
	{
		Usage();
		return 1;
	}

	// main program
	TiXmlDocument doc;
	if (!doc.LoadFile(argv[1]))
	{
		printf("error: cannot load configuration.\n");
		return 1;
	}

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem = NULL;
	pElem = hDoc.FirstChildElement().Element();
	if (!pElem)
	{
		printf("error: invalid configuration file.\n");
		return 1;
	}
   const char* name = pElem->Value();
   if (strcmp(name, "resize") != 0)
	{
		printf("error: invalid configuration file.\n");
		return 1;
	}
	string path =  pElem->Attribute("in_database");
	string ext  =  pElem->Attribute("format");
	g_path      =  pElem->Attribute("out");
	pElem->QueryIntAttribute("width",  &g_width);
	pElem->QueryIntAttribute("height", &g_height);

	printf("params:\n");

	printf("input database: %s\n", path.c_str());
	printf("output database: %s\n", g_path.c_str());
	printf("output images format: %s\n", ext.c_str());
	printf("out width %i\n", g_width);
	printf("out height %i:\n",g_height);

	if (!LFDirExist(g_path.c_str()))
		LFCreateDir(g_path.c_str());

	_finddata_t filesInfo;
	int num_images = 0;
	long handle = 0;

	if ( (handle = _findfirst( (char*)((path+"*.awp").c_str()), &filesInfo)) != -1 )
	{
		do
		{
			string name = path + filesInfo.name;
			TLFImage image;
			if (!image.LoadImage((char*)name.c_str()))
			{
				printf("cannot load image %s \n", name.c_str());
				continue;
			}
			num_images++;
			awpImage* img = image.GetImage();
			awpResize(img, g_width, g_height);

			std::string FileName = g_path;
			FileName += LFIntToStr(num_images);
            FileName += ext;
			image.SaveImage(FileName.c_str());

			if (num_images % 100 == 0)
				printf(">");

		}while(!_findnext( handle, &filesInfo ));
	}
	_findclose( handle );

	printf("\nprocessed %i images\n", num_images);
	printf("done.\n");
	return 0;
}
Exemplo n.º 21
0
void TLFDBLabeledImages::GetFarFrrHST(TLFDetectEngine& engine, TLFHistogramm& far_hst, TLFHistogramm& frr_hst, int stage, bool all, double overlap)
{
	ILFObjectDetector* detector = engine.GetDetector();
	if (detector == NULL)
		return;
	if (stage < 0 || stage >= detector->GetStagesCount())
		return;

	ILFScanner* scanner = detector->GetScanner();
	if (scanner == NULL)
		return;
	TLFObjectList* strongs = detector->GetStrongs();
	if (strongs == NULL)
		return;
	ILFStrong*     classifier = (ILFStrong*)strongs->Get(stage);
	if (classifier == NULL)
		return;

	far_hst.Setup(32, 0, classifier->GetThreshold() * 2);
	frr_hst.Setup(32, 0, classifier->GetThreshold() * 2);
	for (int i = 0; i < m_dataFiles.GetCount(); i++)
	{
		TLFDBSementicDescriptor* d = (TLFDBSementicDescriptor*)m_dataFiles.Get(i);
		string strImageName = d->GetImageFile();
		TLFImage img;
		if (!img.LoadImage(strImageName.c_str()))
			continue;
		engine.SetSourceImage(&img, false);
		TLFImage* img1 = detector->GetImage();
		if (i % 100 == 0)
			printf(">");
		for (int j = 0; j < scanner->GetFragmentsCount(); j++)
		{
			double err = 0;
			double scale = 1;
			awpRect rect = scanner->GetFragmentRect(j);
			TLFRect lf_rect(rect);
			double overlap_det = d->Overlap(lf_rect);
			scale = (double)(rect.right - rect.left) / (double)scanner->GetBaseWidth();
			if (!all)
			{
				classifier->Setup(scale, scale, rect.left, rect.top);
				int result = classifier->Classify(img1, err);
			}
			else
			{
				for (int k = 0; k <= stage; k++)
				{
					ILFStrong* s = (ILFStrong*)strongs->Get(k);
					s->Setup(scale, scale, rect.left, rect.top);
					err = 0;
					if (s->Classify(img1, err) == 0)
					{
						if (k != stage)
							err = 0;
						break;
					}
				}
			}


			if (overlap_det > overlap)
			{
				frr_hst.AddElememt(err);
			}
			else if (overlap_det < overlap- 0.5)
			{
				far_hst.AddElememt(err);
			}
		}
	}

}
Exemplo n.º 22
0
/*
	Image segmentation main function
*/
bool DoSegmentation(awpImage* input, TSegmentationOptions& options, TLFObjectList* list)
{
    bool result = false;
    if (input == NULL || list == NULL)
        return result;
    // cluster sgments
    if (options.segmentationType == 0)
        return result;
    TLFImage source;
    awpImage* tmp = NULL;
    double alfa = 1;
    if (options.needResize)
    {
        int w = options.imageWidth;
        int h = w*input->sSizeY / input->sSizeX;
        awpResizeNip(input, &tmp, w,h);
    }
    else
        awpCopyImage(input, &tmp);
    awpConvert(tmp, AWP_CONVERT_3TO1_BYTE);
    source.SetImage(tmp);

    TLFTileScanner scanner;
    scanner.SetBaseHeight(options.baseHeight);
    scanner.SetBaseWidth(options.baseWidth);
    scanner.GetParameter(0)->SetValue(options.tileOverlap);
    scanner.Scan(source.GetImage()->sSizeX, source.GetImage()->sSizeY);

    //
    list->Clear();
    if (scanner.GetFragmentsCount() > 0)
    {
        for (int i = 0; i < scanner.GetFragmentsCount(); i++)
        {
            awpRect rect = scanner.GetFragmentRect(i);
            TLFSegmentationResult* sr = CreateFeature(options.baseFeature, &rect);
            if (sr != NULL)
            {
                sr->Process(&source);
                if (options.needResize)
                {
                    alfa = (double)input->sSizeX / (double)options.imageWidth;
                    sr->GetRect()->Scale(alfa);
                }
                list->Add(sr);
            }
        }
    }
    // filtering
    if (options.selectionCriteria == 0)
    {
        for (int i = list->GetCount() - 1; i >= 0; i--)
        {
            TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i);
            if (sr->Value() < options.moreThen)
                list->Delete(i);
        }
    }
    else if (options.selectionCriteria == 1)
    {
        for (int i = list->GetCount() - 1; i >= 0; i--)
        {
            TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i);
            if (sr->Value() > options.lessThen)
                list->Delete(i);
        }
    }
    else
    {
        for (int i = list->GetCount() - 1; i >= 0; i--)
        {
            TLFSegmentationResult* sr = (TLFSegmentationResult*)list->Get(i);
            if (sr->Value() < options.minValue || sr->Value() > options.maxValue)
                list->Delete(i);
        }
    }



    _AWP_SAFE_RELEASE_(tmp)


    result = true;
    return result;
}