Esempio n. 1
0
/*
The main rendering function.
*/
void renderer()
{
	// Capture the image
	IplImage *image = capture->captureImage();

	// Check if we need to change image origin and is so, flip the image.
	bool flip_image = (image->origin?true:false);
	if (flip_image) {
		cvFlip(image);
		image->origin = !image->origin;
	}

	// Detect all the markers from the frame
	markerDetector.Detect(image, &camera, false, false);
	
	// Loop throught the list of detected markers
	for (size_t i=0; i<markerDetector.markers->size(); i++) {

		// Get the ID of the marker
		int id = (*(markerDetector.markers))[i].GetId();

		// Get the marker's pose (transformation matrix)
		double temp_mat[16];
		alvar::Pose p = (*(markerDetector.markers))[i].pose;
		p.GetMatrixGL(temp_mat);

	
		if( id == 5){ //Marker 5 is visible
			//Switch the 5 on
			modelSwitch->setChildValue(mtForMarkerFive, 1);
			// Update the matrix transformation
			mtForMarkerFive->setMatrix(osg::Matrix(temp_mat));
		}
		else if(id == 10){ //Marker 10 is visible
			//Switch the 10 on
			modelSwitch->setChildValue(mtForMarkerTen, 1);
			// Update the matrix transformation
			mtForMarkerTen->setMatrix(osg::Matrix(temp_mat));
		}
	}

	// In case we flipped the image, it's time to flip it back 
	if (flip_image) {
		cvFlip(image);
		image->origin = !image->origin;
	}

	// "copy" the raw image data from IplImage to the Osg::Image
	videoImage->setImage(image->width, image->height, 1, 4, GL_BGR, GL_UNSIGNED_BYTE, (unsigned char*)image->imageData, osg::Image::NO_DELETE);
	if(videoImage.valid()){
		// Set the latest frame to the view as an background texture
		videoBG.SetBGImage(videoImage.get());
	}
	// Draw the frame
	viewer->frame();
	
	//Swiths all the models of until next frame
	modelSwitch->setAllChildrenOff();
}
Esempio n. 2
0
void display(void)
{
    // update and render the scene graph
    if (viewer.valid()) viewer->frame();

    // Swap Buffers
    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 3
0
/*
	Process each captured video frame.
*/
void Process()
{
	reset = true;
	while (true)
	{
		frame = capture->captureImage();
		if (frame == 0) 
			continue; // TODO: For some reason CvCam gives NULL sometimes?
		if(frame->origin==1) 
		{ 
			cvFlip(frame); 
			frame->origin=0;
		}
		if (frame->nChannels == 1) 
		{
			gray->imageData = frame->imageData;
			cvCvtColor(frame, rgb, CV_BayerGB2RGB); // TODO: Now this assumes Bayer
		} 
		else 
		{
			rgb->imageData = frame->imageData;
			cvCvtColor(frame, gray, CV_RGB2GRAY);
		}
		gray->origin = frame->origin;

		if (reset)
		{
			reset = false;
		}

		alvar::Pose pose;
		double error = GetMultiMarkerPose(frame, &cam, pose);
		bool track_ok = (error>=0.0 && error<5.0);

		if (track_ok)
		{
			// Draw cameras, points & features
			double gl_mat[16];
			pose.GetMatrixGL(gl_mat);
			model_transform->setMatrix(osg::Matrix(gl_mat));
			model_switch->setAllChildrenOn();
		}
		else
		{
			model_switch->setAllChildrenOff();
//			std::cout << "\rTrack Failed     ";
		}

		viewBG->DrawImage(rgb);
		if (viewer->done())
			break;
		viewer->frame();
		if (stop_running) 
			break;
	}
}