Ejemplo n.º 1
0
Archivo: cfimage.cpp Proyecto: 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;
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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);
			}
		}
	}

}
Ejemplo n.º 5
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;
}