#include "windows.h"
#include "loadbmp.h" // from http://gpwiki.org/index.php/LoadBMPCpp
#include "fdlib.h"

void main(int argc, char *argv[]) 
{
	int i, n, x[256], y[256], size[256], w, h, threshold;	
	BMPImg *bi;
	unsigned char *bgrdata, *graydata;
	
	if (argc==1)
	{
	    printf("usage: fdtest bmpfilename [threshold]n");
	    exit(0);
	}
		
	bi = new BMPImg();
	printf("nloading %sn", argv[1]);
	bi->Load(argv[1]);
	w = bi->GetWidth();
	h = bi->GetHeight();
	printf("image is %dx%d pixelsn", w, h);
	bgrdata = bi->GetImg();
	graydata = new unsigned char[w*h];
	
	for (i=0; i<w*h; i++)
	{
	    graydata[i] = (unsigned char) ((.11*bgrdata[3*i] + .59*bgrdata[3*i+1] + .3*bgrdata[3*i+2]));
	    //if (i<10) printf("%d ", graydata[i]);	    
	}	
	
	threshold = argc>2 ? atoi(argv[2]) : 0;
	printf("detecting with threshold = %dn", threshold);
	fdlib_detectfaces(graydata, w, h, threshold);	
		
	n = fdlib_getndetections();
	if (n==1)
	    printf("%d face foundn", n);
	else
 	    printf("%d faces foundn", n);		
	
	for (i=0; i<n; i++)
	{
	    fdlib_getdetection(i, x+i, y+i, size+i);
	    printf("x:%d y:%d size:%dn", x[i], y[i], size[i]);
	}
	
	delete[] graydata;
	delete bi;
}

I need to know what graydata would look like. I am trying to port this to python and need to know the correct way to pass a python datatype to fdlib_detectfaces()

I have no experience with C++.

Hey,

What your asking is quite hard to accomplish. Is there no possibility to do all of your
program in Python? It seems that would make life a lot easier for you..

Can I advise the Python Imaging Library ((link here) if you dont want to duplicate work.

Hope this seems a good suggestion! -Harry

I got it working. I used pythons ctypes. I used PIL also to convert RGB to grayscale. I think i have a snippet floating around the python forums.

#include "windows.h"
#include "loadbmp.h" // from http://gpwiki.org/index.php/LoadBMPCpp
#include "fdlib.h"

void main(int argc, char *argv[]) 
{
	int i, n, x[256], y[256], size[256], w, h, threshold;	
	BMPImg *bi;
	unsigned char *bgrdata, *graydata;
	
	if (argc==1)
	{
	    printf("usage: fdtest bmpfilename [threshold]n");
	    exit(0);
	}
		
	bi = new BMPImg();
	printf("nloading %sn", argv[1]);
	bi->Load(argv[1]);
	w = bi->GetWidth();
	h = bi->GetHeight();
	printf("image is %dx%d pixelsn", w, h);
	bgrdata = bi->GetImg();
	graydata = new unsigned char[w*h];
	
	for (i=0; i<w*h; i++)
	{
	    graydata[i] = (unsigned char) ((.11*bgrdata[3*i] + .59*bgrdata[3*i+1] + .3*bgrdata[3*i+2]));
	    //if (i<10) printf("%d ", graydata[i]);	    
	}	
	
	threshold = argc>2 ? atoi(argv[2]) : 0;
	printf("detecting with threshold = %dn", threshold);
	fdlib_detectfaces(graydata, w, h, threshold);	
		
	n = fdlib_getndetections();
	if (n==1)
	    printf("%d face foundn", n);
	else
 	    printf("%d faces foundn", n);		
	
	for (i=0; i<n; i++)
	{
	    fdlib_getdetection(i, x+i, y+i, size+i);
	    printf("x:%d y:%d size:%dn", x[i], y[i], size[i]);
	}
	
	delete[] graydata;
	delete bi;
}

I need to know what graydata would look like. I am trying to port this to python and need to know the correct way to pass a python datatype to fdlib_detectfaces()

I have no experience with C++.

i am trying to run this code.at the first if loop...argc is equal to one and it prints the line and exits...can you tell me why argc=1 and why it shouldnt be?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.