Word Gems

A personal interest blog about computergraphics, rendering and usefull C++ and Python stuff.

OpenCV with Visual Studio 2010

If you try to get OpenCV to work with Visual Studio 2010 and get an “Unhandled Exception” while trying out a simple example make sure your program links against the correct .dll!

Make sure you added the path to the folder containing the dll’s build with VS 2010 to your path-enviroment variable, not any other version of Visual Studio, it wont work!

Filed under: C++, Computergraphics, OpenCV

Quick & Dirty *.pfm Reader & Writer

This is a simple, quick and dirty portable float map reader and writer I made. Fell free to use it for whatever purpose, but beware: Its not production code, just a quick research implementation.


typedef struct {
 float r;
 float g;
 float b;
} COLOR;

COLOR * data;

void HDRImage::setSize(int x, int y)
{
 if(mSizeX==x && mSizeY==y)
 return;
 mSizeX = x;
 mSizeY = y;
 if (data)
 delete[] data;
 data = new COLOR[mSizeX* mSizeY];
}

void HDRImage::loadPfm(const char * filename)
{

	char strPF[3];
	unsigned int SizeX;
	unsigned int SizeY;
	float dummy;
	int dummyC;

	FILE * file = fopen(filename, "rb");

	if (file == NULL) {
		printf("PFM-File not found!\n");
		return;
	}

	fscanf(file, "%s\n%u %u\n", strPF, &SizeX, &SizeY);
	dummyC = fgetc(file);
	fscanf(file, "\n%f\n", &dummy);

	//DEBUG Ausgabe
	printf("Keyword: %s\n",strPF);
	printf("Size X: %d\n", SizeX);
	printf("Size Y: %d\n", SizeY);
	printf("dummy: %f\n", dummy);
	// ENDE Debug Ausgabe

	this->setSize(SizeX, SizeY);

	int result;
	int lSize;
	lSize = mSizeX*3;
	for(int y=mSizeY-1; y>=0; y--)
	{
		result = fread(data+1+mSizeX*y, sizeof(float), lSize, file);
		if (result != lSize) {
			printf("Error reading PFM-File. %d Bytes read.\n", result);
		}
	}

	fclose(file);
}

void HDRImage::writePfm(const char * filename)
{

 char sizes[256];
 FILE * file = fopen(filename, "wb");

 fwrite("PF\n",sizeof(char), 3, file);
 sprintf(sizes, "%d %d\n", mSizeX, mSizeY);

 fwrite(sizes,sizeof(char), strlen(sizes)+1, file);
 fwrite("\n",sizeof(char),1, file);
 fwrite("-1.000000\n",sizeof(char),10, file);

 for(int y=mSizeY-1; y>=0; y--)
 fwrite(data+1+mSizeX*y, sizeof(float), mSizeX*3, file);

 fclose(file);
}

Filed under: Computergraphics,

Stochastic Progressive Photon Mapping

An picture I rendered with my Stochastic Progressive Photon Mapper. There is diffuse, specular and half diffuse/specular material in the Scene. The bust is “Otto von Guericke”, the inventor of the vacuum pump. The clock was kindly provided by Toshiya Hachisuka. I saved extensive statistics while the rendering was running.

You can get the logfile.txt from <link down, sorry>

The original HDR-File is available as portable float map <link down, sorry>

The scene description file is available in a text format similar to pbrt <link down, sorry>

The Otto bust is available as zipped obj-file <link down, sorry>

Filed under: Computergraphics,