示例#1
0
void AlphaBlend::unset(){
	Drawer *drawer = Drawer::getInstance();
	
	drawer->disable(InGE_BLEND);

	m_component->unset();
}
示例#2
0
	void draw(){
		const float *eyePos = camera.getEyePos();
		const float *target = camera.getTarget();
		const float *upVector = camera.getUpVector();
		int index = current / total;
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(eyePos[0], eyePos[1], eyePos[2], target[0], target[1], target[2], 
			upVector[0], upVector[1], upVector[2]);
		SurfaceGeometryF tmp;
		Drawer drawer;
		tmp.rows = tmp.cols = 100;
		tmp.startX = tmp.startY = -1.0;
		tmp.endX = tmp.endY = 1.0;
		tmp.calculateNorm = true;
		tmp.evalFunc = calc;
		for(size_t i = 0;i < surfs.size();++ i){
			surf = surfs[i].surf;
			mat(&surfs[i].color);
			//cout << surfs[i].color.x() << ' ' << surfs[i].color.y() << ' ' << surfs[i].color.z() << endl;
			drawer.draw(tmp);
		}
		if(index + 1 < surfs.size()){
			surf = interpolated.surf;			
			mat(&interpolated.color);
			drawer.draw(tmp);
		}
	}
void ConsoleModeController::run(QString pathToConfigFile, QString pathToOutputFile)
{
	saveAndLoadConfig::ConfigParser parser;
	try
	{
        Configuration* config = parser.parse(pathToConfigFile);
		Drawer drawer;
        Lemniscate* lemniscate = config->getLemniscate();
        int width = config->getPanel()->getWidth();
        int height = config->getPanel()->getHeight();
        QImage* image = new QImage(width, height, QImage::Format_RGB888);

		const int whiteColorValue = 255;
		memset(image->bits(), whiteColorValue, image->byteCount());
        drawer.drawLemniscate(image, lemniscate);


        if (!image->save(pathToOutputFile))
		{
			std::cerr << "image wasn't saved" << std::endl;
		}
	}
	catch (JsonParserException& exception)
	{
		std::cerr << exception.what() << std::endl;
	}
}
示例#4
0
文件: Level.cpp 项目: toemm/Pong
void Level::render(Drawer& drawer)
{
	b2Transform trans = mTop->GetTransform();
	drawer.DrawShape(trans, mTop->GetFixtureList(), b2Color(1, 1, 1));

	trans = mBot->GetTransform();
	drawer.DrawShape(trans, mTop->GetFixtureList(), b2Color(1, 1, 1));
}
示例#5
0
// Draw the game according the the time elapsed since the last draw
// The elapsed time is in seconds
void MainMenu::draw(const Drawer& drawer, float elapsedTime)
{
	drawer.clear(_backgroundColor);

	drawer.draw(_mainMenu);

	drawer.present();
}
示例#6
0
void AlphaBlend::set(bool setup){
	Drawer *drawer = Drawer::getInstance();
	
	drawer->enable(InGE_BLEND);
	drawer->blendFunc( InGE_SRC_ALPHA, InGE_ONE_MINUS_SRC_ALPHA );
	
	m_component->set(setup);
}
示例#7
0
void DrawerManager::SetAuiManager( wxAuiManager* auiManager )
{
    for ( M_DrawerButtonIDs::const_iterator drawerItr = m_Drawers.begin(), drawerEnd = m_Drawers.end(); drawerItr != drawerEnd; ++drawerItr )
    {
        Drawer* drawer = drawerItr->second;
        drawer->SetAuiManager( auiManager );
    }
}
示例#8
0
文件: main.cpp 项目: TraumLou/qt
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Drawer drawer;
    drawer.show();

    return a.exec();
}
示例#9
0
	spn::SizeF Node::draw(const Vec2& offset, const Vec2& unit, Drawer& d) const {
		const auto sz = _text->getSize();
		d.drawRectBoth({
			offset.x,
			offset.x+sz.width,
			offset.y,
			offset.y-sz.height
		}, {Color::Node});
		// ノード名
		d.drawText(offset, _text, {Color::Node});
		// ノードを開いた印
		d.drawText(offset + Vec2(sz.width + 8, 0), _mark[_expanded], {Color::Node});
		return {sz.width+16, unit.y};
	}
示例#10
0
//--------------------------------------------------------------
void ofApp::setup() {
	ofSetFrameRate(60);
	ofSetVerticalSync(true);
	
	rotate = 0;
	
	// setup bvh
	bvh[0].load("bvhfiles/kashiyuka.bvh");
	bvh[1].load("bvhfiles/nocchi.bvh");
	bvh[2].load("bvhfiles/aachan.bvh");
	
	for (int i = 0; i < 3; i++)	{
		bvh[i].play();
	}
	
	track.loadSound("Perfume_globalsite_sound.wav");
	track.play();
	track.setLoop(true);
	
	// setup tracker and drawer
	for (int i = 0; i < 3; i++)
		{
		ofxBvh &b = bvh[i];
		Drawer *d = new Drawer;
		
		for (int n = 0; n < b.getNumJoints(); n++) {
			const ofxBvhJoint *o = b.getJoint(n);
			Tracker *t = new Tracker;
			t->setup(o);
			t->setTrackerLength(trackerLength);
			trackers.push_back(t);
			d->add(o);
		}
		
		drawers.push_back(d);
		}
	
	ofPushMatrix();
	ofTranslate(0, -100);
	ofScale(1, 1, 1);
	ofRotateX(90);
	camera.setFov(90);
	camera.lookAt(ofVec3f(0,0,0));
	camera.setPosition(300, 30, 300);
	//camera.disableMouseInput();
	ofPopMatrix();
	background.loadImage("background.png");
	
}
示例#11
0
void display(){
	GLfloat texParams[4] = {0, 0, 0.5, 0.5};
	const float *eyePos = camera.getEyePos();
	const float *target = camera.getTarget();
	const float *upVector = camera.getUpVector();
	GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat yellow[]= {1.0, 1.0, 0.0, 1.0};
	GLfloat mat_shininess[]={ 30.0 };
	SurfaceGeometryF tmp;
	Drawer drawer;
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	tmp.startX = tmp.startY = -4;
	tmp.endX = tmp.endY = 4;
	tmp.rows = tmp.cols = slice;
	tmp.evalFunc = tmpFunc;
	tmp.normFunc = normFunc;
	tmp.hasTexture = true;
	if(tmp.normFunc == NULL)
		tmp.calculateNorm = true;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eyePos[0], eyePos[1], eyePos[2], target[0], target[1], target[2], 
			upVector[0], upVector[1], upVector[2]);
	//glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	//glTexGenfv(GL_S, GL_OBJECT_PLANE, texParams);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, white );
        glMaterialfv(GL_BACK, GL_DIFFUSE, yellow );
        glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess );
	{
		GLuint texName;
		glGenTextures(1,&texName);                 // define texture for sixth face
		//glEnable(GL_TEXTURE_2D);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glBindTexture(GL_TEXTURE_2D,texName);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,texture.textWidth,texture.textHeight,
		             0,GL_RGB,GL_UNSIGNED_BYTE,texture.texImage);
		drawer.draw(tmp);
		glDeleteTextures(1, &texName);
	}
	glutSwapBuffers();
}
示例#12
0
void DrawerManager::RemoveAllDrawers()
{
    // Close and detach from all drawers
    for ( M_DrawerButtonIDs::const_iterator drawerItr = m_Drawers.begin(), drawerEnd = m_Drawers.end(); drawerItr != drawerEnd; ++drawerItr )
    {
        Drawer* drawer = drawerItr->second;
        
        drawer->e_Opening.RemoveMethod( this, &DrawerManager::OnDrawerOpening );
        drawer->e_Opened.RemoveMethod( this, &DrawerManager::OnDrawerOpened );
        drawer->e_Closed.RemoveMethod( this, &DrawerManager::OnDrawerClosed );

        drawer->Close();

        //delete drawer;
    }
    m_Drawers.clear();
}
示例#13
0
void DrawerManager::RemoveDrawer( Drawer* drawer )
{
    // Close and detach from all drawers
    M_DrawerButtonIDs::iterator foundDrawerItr = m_Drawers.find( drawer->GetButtonID() );
    if ( foundDrawerItr != m_Drawers.end() )
    {
        Drawer* foundDrawer = foundDrawerItr->second;
        
        foundDrawer->e_Opening.RemoveMethod( this, &DrawerManager::OnDrawerOpening );
        foundDrawer->e_Opened.RemoveMethod( this, &DrawerManager::OnDrawerOpened );
        foundDrawer->e_Closed.RemoveMethod( this, &DrawerManager::OnDrawerClosed );

        foundDrawer->Close();

        m_Drawers.erase( foundDrawerItr );
    }
}
DEF_TEST(SkRecordingAccuracyXfermode, reporter) {
#define FINEGRAIN 0
    const Drawer drawer;

    BitmapBackedCanvasStrategy golden(drawer.imageInfo());
    PictureStrategy picture(drawer.imageInfo());

#if !FINEGRAIN
    unsigned numErrors = 0;
    SkString errors;
#endif

    for (int iMode = 0; iMode < int(SkBlendMode::kLastMode); iMode++) {
        const SkRect& clip = SkRect::MakeXYWH(100, 0, 100, 100);
        SkBlendMode mode = SkBlendMode(iMode);

        const SkBitmap& goldenBM = golden.recordAndReplay(drawer, clip, mode);
        const SkBitmap& pictureBM = picture.recordAndReplay(drawer, clip, mode);

        size_t pixelsSize = goldenBM.computeByteSize();
        REPORTER_ASSERT(reporter, pixelsSize == pictureBM.computeByteSize());

        // The pixel arrays should match.
#if FINEGRAIN
        REPORTER_ASSERT(reporter,
                        0 == memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize));
#else
        if (memcmp(goldenBM.getPixels(), pictureBM.getPixels(), pixelsSize)) {
            numErrors++;
            errors.appendf("For SkXfermode %d %s:    SkPictureRecorder bitmap is wrong\n",
                           iMode, SkBlendMode_Name(mode));
        }
#endif
    }

#if !FINEGRAIN
    REPORTER_ASSERT(reporter, 0 == numErrors, errors.c_str());
#endif
}
示例#15
0
void display(){
	const float *eyePos = camera.getEyePos();
	const float *target = camera.getTarget();
	const float *upVector = camera.getUpVector();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(eyePos[0], eyePos[1], eyePos[2], target[0], target[1], target[2], 
			upVector[0], upVector[1], upVector[2]);
	glLightfv(GL_LIGHT0, GL_POSITION, light_pos0 ); // light 0
	glLightfv(GL_LIGHT1, GL_POSITION, light_pos1 ); // light 1
	Drawer drawer;
	ParametricSurfaceGeometryF g;
	g.startU = g.startV = -len;
	g.endU = g.endV = len;
	g.rows = 500;
	g.cols = 500;
	g.evalFunc = paramFunc;
	g.normFunc = NULL;
	//g.calculateNorm = false;
	//glColor3f(1.0, 1.0, 1.0);
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	drawer.draw(g);
	glLineWidth(2);
	glBegin(GL_LINES);
		glColor3f(1.0, 0.0, 0.0);
		glVertex3f(-2, 0, 0);
		glVertex3f(2, 0, 0);
		glColor3f(0.0, 1.0, 0.0);
		glVertex3f(0, -2, 0);
		glVertex3f(0, 2, 0);
		glColor3f(0.0, 0.0, 1.0);
		glVertex3f(0, 0, -2);
		glVertex3f(0, 0, 2);
	glEnd();
	glutSwapBuffers();
}
示例#16
0
int main() {
	std::vector<tutor::PPoint2d>u1;
	std::vector<tutor::PPoint2d>u2 ;

	char* file_names[] = {"imgs/img12.txt", "imgs/img22.txt"};
	char* img_names[] = {"imgs/image1.pgm", "imgs/image2.pgm"};
	///// get points
	u1 = read_positions(file_names[0]);
	u2 = read_positions(file_names[1]);
	// std::cout << "u1=" << u1 << std::endl;
	// std::cout << "u2=" << u2 << std::endl;
	///// get images
	cv::Mat img1 = cv::imread(img_names[0]);
	cv::Mat img2 = cv::imread(img_names[1]);

	Drawer drawer = Drawer();
	for (unsigned  i=0; i<N; i++) {
		drawer.mark(img1, u1[i], 255);
		drawer.mark(img2, u2[i],  255);
	}
	///// get F
	cv::Matx33d F ;
	F = get_fundamental_matrix(u1, u2);
	///// draw epipoler line
	for (unsigned i=0; i<u1.size(); i++) {
		// PPoint2d u = pt_to_ppt(u1[i]);
		std::cout << "i=" << i  << "   " ;
		draw_epiline(img1, u1[i], F) ;
	}
	for (unsigned i=0; i<u2.size(); i++) {
		// PPoint2d u = pt_to_ppt(u2[i]);
		draw_epiline(img2, u2[i], F.t()) ;
	}
	cv::imwrite("image1.jpg", img1);
	cv::imwrite("image2.jpg", img2);
	return 0;
}
示例#17
0
void ButtonWidget::drawAt ( Drawer &drawer, MenuWidget* parent, int x, int y, Align align )
{
	if ( !show )
	{
		return;
	}

	// Choose correct style
	Style * currentStyle = getCurrentStyle ();

	if ( this->textCache == nullptr )
	{
		this->prepare ( drawer );
		lastStyle = style;
	}
	else
	{
		if ( currentStyle != lastStyle )
		{
			prepare ( drawer, *currentStyle );
			lastStyle = currentStyle;
		}
	}

	// draw
	if ( currentStyle == nullptr )
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		lastPos = alignedPos;
		this->textCache->drawAt( alignedPos );
	}
	else
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		SDL_Rect size = { alignedPos.x, alignedPos.y, this->getWidth(), this->getHeight() };
		lastPos = alignedPos;

		drawer.setClipRect( size );

		// draw background
		currentStyle->drawBackground( drawer, size );

		// draw text
		DirSize padding = style->getPadding();
		SDL_Point innerPos = { alignedPos.x + padding.left, alignedPos.y + padding.top };
		if ( !hasDynamicWidth() )
		{
			int innerWidth = style->getWidth() - padding.left - padding.right;
			innerPos.x += (innerWidth - textCache->getWidth()) / 2;
		}
		if ( !hasDynamicHeight() )
		{
			int innerHeight = style->getHeight() - padding.top - padding.bottom;
			innerPos.y += (innerHeight - textCache->getHeight()) / 2;
		}
		
		this->textCache->drawAt( innerPos );

		// draw border
		SDL_Rect border = size;

		drawer.setDrawingColor( currentStyle->getBorderColor() );
		for ( int i = 0; i < currentStyle->getBorderThickness(); i++ )
		{
			drawer.drawRect( border );
			border.x++;
			border.y++;
			border.w -= 2;
			border.h -= 2;
		}

		drawer.cancelClipRect();
	}
}
void CharacterMenu::loop( GameState & gameState, Drawer & drawer, double delta )
{
	Size windowSize = drawer.getWindowSize();
	rootContainer->getStyle()->setHeight( windowSize.h ).setWidth( windowSize.w );
	rootContainer->drawAt( drawer, nullptr, windowSize.w / 2, 0, Align::CENTER );
}
int main(int argc ,char* argv[]){

	if(argc != 2){
		std::cout << "Usage:" << std::endl << "%s ./FeatureViewer input.txt"<<std::endl<<std::endl;
		return 0;
	}

	std::string nvmpath;
	std::string imgpath;
	int lengh,cam,numofimg,numofLines;

	if(readPath(argv[1], &imgpath, &nvmpath, &cam, &lengh, &numofimg, &numofLines) == 0){
		return 0;
	}

	std::cout << "****************************************" << std::endl << "How to use..." << std::endl << " * [n] key : Move to Next Frame" << std::endl;
	std::cout << " * [p] key : Move to previous Frame" << std::endl;
	std::cout << " * [q] key : Quit thie application" << std::endl << "****************************************" << std::endl<< std::endl;

	std::cout << " * imgpath:" << imgpath << std::endl;
	std::cout << " * nvmpath:" << nvmpath << std::endl;
	std::cout << " * pertitition_number:" << cam << std::endl;
	std::cout << " * rought_lengh:" << lengh << std::endl;
	std::cout << " * num_of_imgs:" << numofimg << std::endl;
	std::cout << " * num_of_lines:" << numofLines << std::endl << std::endl;

	int numpic=0;

	ImageViewer imgv(cam,lengh, "FeatureViewer");
	Reader reader(cam,imgpath,nvmpath);

	Drawer drawer;

	if(reader.setFeaturePoint(1,numofLines) != 0){
		exit(0);
	}


	reader.setImg(cam, 0, numofimg-1);


	reader.sortKeyFrameID();

	imgv.setWindow();
	for(int i=lengh+1; i<reader.ik.size();i++){
		
		std::vector<std::vector<ImageKeeper>> drawnCam(cam);

		for(int j=0; j<12; j++){
			for(int k=0; k<lengh+1;k++){
				drawnCam[j].push_back(reader.getIKbyID(j,reader.keyFrameID[i-k]));
			}
		}

		std::vector< std::vector<bool> > flagCam(cam);


		for(int j=0;j<cam;j++){
			drawer.DrawPoints(drawnCam[j][0]);
			flagCam[j].resize(drawnCam[j][0].getFeaturesSize());

		}

		for(int j=0;j<cam;j++){
			for(int k=0;k<cam;k++){
               			if(j!=k){
                    			drawnCam[k][1].getFeatureFlags(drawnCam[j][0],flagCam[j]);
                		}
            		}
		}


		for(int j=0;j<cam;j++){
			drawer.DrawRoute(drawnCam[j],drawnCam[j][0].getIMG(),flagCam[j]);
		}

		std::vector<ImageKeeper> preimg;
		std::vector<ImageKeeper> viewedimg;


		for(int j=0;j<cam;j++){
			preimg.push_back(drawnCam[j][1]);
			viewedimg.push_back(drawnCam[j][0]);
		}

		showData(viewedimg);

		imgv.showImgsTheta(viewedimg, preimg);

		checkCommand(&i,cv::waitKey(0));
		
	}

	return 0;
	
}
void TextInputWidget::drawAt( Drawer & drawer, MenuWidget * parent, int x, int y, Align align )
{
	if ( !show )
	{
		return;
	}

	if ( active && !SDL_IsTextInputActive() )
	{
		SDL_StartTextInput();
	}

	// Choose correct style
	Style * currentStyle = getCurrentStyle();

	if ( this->textCache == nullptr )
	{
		this->prepare( drawer, *currentStyle );
		lastStyle = style;
	}
	else
	{
		if ( currentStyle != lastStyle || textChanged )
		{
			prepare( drawer, *currentStyle );
			lastStyle = currentStyle;
		}
	}

	// draw
	if ( currentStyle == nullptr )
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		lastPos = alignedPos;
		this->textCache->drawAt( alignedPos );
	}
	else
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		SDL_Rect size = { alignedPos.x, alignedPos.y, this->getWidth(), this->getHeight() };
		lastPos = alignedPos;

		drawer.setClipRect( size );

		// draw background
		currentStyle->drawBackground( drawer, size );

		// draw text
		DirSize padding = style->getPadding();
		SDL_Point innerPos = { alignedPos.x + padding.left, alignedPos.y + padding.top };
		int innerWidth = style->getWidth() - padding.left - padding.right;
		drawer.setClipRect( { innerPos.x, innerPos.y, innerWidth, style->getHeight() } );
		innerPos.y += ( style->getHeight() - padding.top - padding.bottom - textCache->getHeight() ) / 2;

		int width = drawer.getTextSize( this->text.substr( 0, this->cursorPosition ),
										style->getFontSize(), style->getFontStyle() ).w + 1;

		int offset = 0;

		if ( width > innerWidth )
		{
			offset = width - innerWidth;
		}

		if ( text != "" )
			this->textCache->drawAt( innerPos.x - offset, innerPos.y );

		if ( active )
		{
			drawer.setDrawingColor( style->getFontColor() );
			drawer.drawLine( { width + innerPos.x - offset - 1, innerPos.y - 2 },
			{ width + innerPos.x - offset - 1, innerPos.y + textCache->getHeight() + 2 } );
		}

		drawer.setClipRect( size );

		// draw border
		SDL_Rect border = size;

		drawer.setDrawingColor( currentStyle->getBorderColor() );
		for ( int i = 0; i < currentStyle->getBorderThickness(); i++ )
		{
			drawer.drawRect( border );
			border.x++;
			border.y++;
			border.w -= 2;
			border.h -= 2;
		}

		drawer.cancelClipRect();
	}
}
int
main(int argc, char **argv)
{
	ArgumentParser *argp = new ArgumentParser(argc, argv, "h:f:c:");

	if (argp->has_arg("h") && argp->has_arg("f"))
	// read image from file
	{
		const char *cascade_file = argp->arg("h");
		const char *image_file   = argp->arg("f");

		JpegReader *   reader = new JpegReader(image_file);
		unsigned char *buffer =
		  malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height());

		reader->set_buffer(buffer);
		reader->read();

		FacesClassifier *classifier =
		  new FacesClassifier(cascade_file, reader->pixel_width(), reader->pixel_height());

		classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());
		std::list<ROI> *rois = classifier->classify();

		FilterROIDraw *roi_draw = new FilterROIDraw();
		for (std::list<ROI>::iterator i = rois->begin(); i != rois->end(); ++i) {
			printf("ROI: start (%u, %u)  extent %u x %u\n",
			       (*i).start.x,
			       (*i).start.y,
			       (*i).width,
			       (*i).height);

			roi_draw->set_dst_buffer(buffer, &(*i));
			roi_draw->apply();
		}

		ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
		display->show(buffer);

		display->loop_until_quit();

		delete display;

		delete rois;
		free(buffer);
		delete reader;
		delete classifier;
	}

	else if (argp->has_arg("h") && argp->has_arg("c"))
	// get images from camera
	{
		const char *cascade_file = argp->arg("h");

		Camera *camera = NULL;
		try {
			camera = CameraFactory::instance(argp->arg("c"));
			camera->open();
			camera->start();
		} catch (Exception &e) {
			printf("Failed to open camera.\n");
			delete camera;
			return (-1);
		}

		printf("successfully opened camera: w=%d h=%d\n",
		       camera->pixel_width(),
		       camera->pixel_height());

		TimeTracker *tt              = new TimeTracker();
		unsigned int ttc_recognition = tt->add_class("Face recognition");
		unsigned int loop_count      = 0;

		IplImage *image =
		  cvCreateImage(cvSize(camera->pixel_width(), camera->pixel_height()), IPL_DEPTH_8U, 3);

		IplImage *scaled_image =
		  cvCreateImage(cvSize(camera->pixel_width() / 2, camera->pixel_height() / 2), IPL_DEPTH_8U, 3);

		FacesClassifier *classifier = new FacesClassifier(cascade_file,
		                                                  camera->pixel_width(),
		                                                  camera->pixel_height(),
		                                                  scaled_image,
		                                                  1.2 /* scale factor */,
		                                                  2 /* min neighbours */,
		                                                  CV_HAAR_DO_CANNY_PRUNING);

		unsigned char *display_buffer = (unsigned char *)malloc(camera->buffer_size());

		ImageDisplay *display =
		  new ImageDisplay(camera->pixel_width(), camera->pixel_height(), "QA Faces Classifier");

		Drawer *drawer = new Drawer();
		drawer->set_buffer(display_buffer, camera->pixel_width(), camera->pixel_height());

		SDL_Event redraw_event;
		redraw_event.type           = SDL_KEYUP;
		redraw_event.key.keysym.sym = SDLK_SPACE;

		SDL_PushEvent(&redraw_event);

		bool quit = false;
		while (!quit) {
			SDL_Event event;
			if (SDL_WaitEvent(&event)) {
				switch (event.type) {
				case SDL_QUIT: quit = true; break;

				case SDL_KEYUP:
					if (event.key.keysym.sym == SDLK_SPACE) {
						camera->capture();

						if (camera->buffer() != NULL) {
							IplImageAdapter::convert_image_bgr(camera->buffer(), image);
							cvResize(image, scaled_image, CV_INTER_LINEAR);
							memcpy(display_buffer, camera->buffer(), camera->buffer_size());

							tt->ping_start(ttc_recognition);
							std::list<ROI> *rois = classifier->classify();
							tt->ping_end(ttc_recognition);

							camera->dispose_buffer();

							bool first = true;
							for (std::list<ROI>::reverse_iterator i = rois->rbegin(); i != rois->rend(); ++i) {
								if (first) {
									drawer->set_color(127, 70, 200);
								}
								drawer->draw_rectangle(2 * i->start.x, 2 * i->start.y, 2 * i->width, 2 * i->height);
								if (first) {
									drawer->set_color(30, 30, 30);
									first = false;
								}
							}

							if (++loop_count % 15 == 0) {
								tt->print_to_stdout();
							}

							display->show(display_buffer);
						}

						SDL_PushEvent(&redraw_event);
					}

					else if (event.key.keysym.sym == SDLK_ESCAPE) {
						quit = true;
					}

					break;

				default: break;
				}
			}
		}

		camera->stop();
		camera->close();
		delete camera;
		delete display;
		delete drawer;
		free(display_buffer);
		cvReleaseImage(&image);
		cvReleaseImage(&scaled_image);
		delete tt;
	}

	else {
		printf("Usage: %s -h <Haar cascade file> -f <Image file as JPEG>\n", argv[0]);
		printf("    or %s -h <Haar cascade file> -c <Camera argument string>\n", argv[0]);
		exit(-1);
	}

	delete argp;
}