void Player::run()
{
    int delay = (1000/framerate);
    while(!stop) {
        if (!capture.read(frame0))
        {
            stop = true;
        }
        else
        {
            if (frame0.channels() == 3)
            {
                frame = frame0(Range(119,500),Range(285,800));
                //frame = frame0;

                //cv::cvtColor(frame,frame,CV_BGR2RGB);
                cv::cvtColor(frame,RGBframe,CV_BGR2GRAY);
                img = QImage( (const unsigned char*)(RGBframe.data), RGBframe.cols, RGBframe.rows, RGBframe.step, QImage::Format_Indexed8);
                /*cv::cvtColor(frame,RGBframe,COLOR_BGR2RGB);*/
                /*img = QImage( (const unsigned char*)(RGBframe.data), RGBframe.cols, RGBframe.rows, RGBframe.step, QImage::Format_RGB888);*/
            }
            else
            {
                /*emit extractFeatureSignal(frame);*/
                /*frame = frame(Range(119,500),Range(285,800));*/
                img = QImage( (const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_Indexed8);
            }
            /*emit extractFeatureSignal(img);*/
            emit processedImageSignal(img);
            this->msleep(delay);
        }
    }

}
	static int load()
	{
		FreeTypeDecoder::initialize();

		ShowWindow(GetConsoleWindow(), SW_HIDE);

		Graphics3D * graphics = D3DGraphics::initialize();
		FinalAction finally(D3DGraphics::free);

		graphics->setClearColor({0.0f, 0.0f, 0.0f});

		Handle<Window> window(graphics, 0, 0, 1024, 758);
		Handle<WindowBackground> back(window);
		back->name = "Background";

		Handle<Panel> frame(back);
		frame->setPlacement({0.5f, 0.5f, 0.5f, 0.5f}, {-300, -300, 300, 300});
		frame << [](const DrawParams & p)
		{
			p.graphics->setColor({0.25f, 0.25f, 0.25f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame0(frame);
		frame0->setPlacement(ModelMask::FullSize, {4, 4, -4, -4});
		frame0 << [](const DrawParams & p)
		{
			p.graphics->setColor({0.5f, 0.5f, 0.5f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame1(frame0);
		frame1->setPlacement(ModelMask::FullSize, {3, 3, -3, -3});
		frame1 << [](const DrawParams & p)
		{
			p.graphics->setColor({0.75f, 0.75f, 0.75f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> frame2(frame1);
		frame2->setPlacement(ModelMask::FullSize, {2, 2, -2, -2});
		frame2 << [](const DrawParams & p)
		{
			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			p.graphics->rectangle(p.clipped);
		};

		Handle<Panel> panel(frame2);
		panel->setPlacement(ModelMask::FullSize, {1, 1, -1, -1});
		panel << [](const DrawParams & p)
		{
			p.graphics->setColor({0.0f, 0.0f, 0.0f});
			p.graphics->rectangle(p.clipped);
		};

		auto arial = Font::load("arial.ttf");

		graphics->bind(arial);
		graphics->setFontSize(16);

		Handle<String> project_name("Independence");
		Handle<Panel> project_name_panel(back);
		project_name_panel->setPlacement(10, 10, 0, 0);
		project_name_panel->setSize(graphics->getTextSize(*project_name));

		project_name_panel << [arial, project_name](const DrawParams & p)
		{
			auto & graphics = p.graphics;
			auto & region = p.region;
			graphics->bind(arial);
			graphics->setFontSize(16);

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(region.left, region.top, *project_name);
		};

		Handle<String> text("Press Esc to quit");
		Handle<Panel> text_panel(back);
		text_panel->setPlacement(ModelMask::RightTop, {0, 10, -10, 0});
		text_panel->setSize(graphics->getTextSize(*text));

		text_panel << [arial, text](const DrawParams & p)
		{
			auto & graphics = p.graphics;
			auto & region = p.region;
			graphics->bind(arial);
			graphics->setFontSize(16);

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(region.left, region.top, *text);
		};

		Handle<FpsCounter> counter(emptiness);

		Handle<Panel> fps_panel(back);
		fps_panel->setPlacement({0.5f, 1.0f, 0.5f, 1.0f}, {-40, -30, 40, -10});
		fps_panel << [counter, arial](const DrawParams & p)
		{
			auto graphics = p.graphics;
			graphics->bind(arial);
			graphics->setFontSize(16);

			auto text = String(counter->get()) + " fps";
			auto textSize = graphics->getTextSize(text);
			int left = p.region.left + (p.region.width() - textSize.x) / 2;
			int top = p.region.top + (p.region.height() - textSize.y) / 2;

			p.graphics->setColor({1.0f, 1.0f, 1.0f});
			graphics->draw(left, top, text);
		};
		
		Handle<Scene> scene(panel);
		scene->append<Snake>(color(1.0f, 0.0f, 0.0f));
		scene->append<Snake>(color(1.0f, 0.5f, 0.0f));
		scene->append<Snake>(color(1.0f, 1.0f, 0.0f));
		scene->append<Snake>(color(0.0f, 1.0f, 0.0f));
		scene->append<Snake>(color(0.0f, 1.0f, 1.0f));
		scene->append<Snake>(color(0.0f, 0.0f, 1.0f));
		scene->append<Snake>(color(0.5f, 0.0f, 1.0f));

		connect(*window, onWindowKeyDown);

		window->setBorderStyle(BorderStyle::Static);
		window->setCaption("Independence");
		window->centralize();
		window->show();

		ThreadLoop::add(processWindowMessage);
		ThreadLoop::add([scene, window, counter, fps_panel] () mutable
		{
			//std::this_thread::sleep_for(1ms);
			
			counter->next();
			window->invalidate(fps_panel);
			
			scene->invalidate();
			window->validate();

			return 0;
		});

		ThreadLoop::run();

		return 0;
	}
示例#3
0
int main(int argc,char* argv[])
	{
	/* Open the uncompressed depth stream file: */
	IO::FilePtr depthFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/DepthFrames.dat"));
	depthFrameFile->setEndianness(Misc::LittleEndian);
	
	/* Read the file header: */
	unsigned int size[2];
	depthFrameFile->read(size,2);
	
	/* Create a background frame: */
	unsigned short* backgroundFrame=new unsigned short[size[1]*size[0]];
	unsigned short* bfPtr=backgroundFrame;
	for(unsigned int y=0;y<size[1];++y)
		for(unsigned int x=0;x<size[0];++x,++bfPtr)
			*bfPtr=0x07ffU;
	unsigned int numCaptureFrames=150;
	
	/* Create the depth frame writer and reader: */
	IO::FilePtr compressedDepthFrameFile(IO::openFile("/work/okreylos/3DVideo/Kinect/CompressedDepthFrames.dat",IO::File::ReadWrite));
	Kinect::DepthFrameWriter depthFrameWriter(*compressedDepthFrameFile,size);
	compressedDepthFrameFile->flush();
	Kinect::DepthFrameReader depthFrameReader(*compressedDepthFrameFile);
	
	/* Process all frames from the two depth frame files: */
	double totalTime=0.0;
	double maxTime=0.0;
	unsigned int numFrames=0;
	while(!depthFrameFile->eof())
		{
		/* Read the next uncompressed depth frame: */
		Kinect::FrameBuffer frame0(size[0],size[1],size[1]*size[0]*sizeof(unsigned short));
		frame0.timeStamp=depthFrameFile->read<double>();
		unsigned short* frameBuffer0=frame0.getData<unsigned short>();
		depthFrameFile->read(frameBuffer0,size[1]*size[0]);
		
		if(numCaptureFrames>0)
			{
			/* Add the depth frame to the background frame: */
			unsigned short* bfPtr=backgroundFrame;
			const unsigned short* dfPtr=frameBuffer0;
			for(unsigned int y=0;y<size[1];++y)
				for(unsigned int x=0;x<size[0];++x,++bfPtr,++dfPtr)
					if(*bfPtr>*dfPtr-2)
						*bfPtr=*dfPtr-2;
			--numCaptureFrames;
			}
		else
			{
			/* Remove background from the depth frame: */
			const unsigned short* bfPtr=backgroundFrame;
			unsigned short* dfPtr=frameBuffer0;
			for(unsigned int y=0;y<size[1];++y)
				for(unsigned int x=0;x<size[0];++x,++bfPtr,++dfPtr)
					if(*dfPtr>=*bfPtr)
						*dfPtr=0x07ffU;
			}
		
		/* Write the compressed depth frame: */
		depthFrameWriter.writeFrame(frame0);
		compressedDepthFrameFile->flush();
		
		/* Read the next compressed depth frame: */
		Misc::Timer uncompressTime;
		Kinect::FrameBuffer frame1=depthFrameReader.readNextFrame();
		uncompressTime.elapse();
		double time=uncompressTime.getTime();
		totalTime+=time;
		if(maxTime<time)
			maxTime=time;
		++numFrames;
		
		/* Compare the two frames: */
		unsigned int numPixels=size[0]*size[1];
		const unsigned short* f0Ptr=frameBuffer0;
		const unsigned short* f1Ptr=frame1.getData<unsigned short>();
		while(numPixels>0)
			{
			if(*f0Ptr!=*f1Ptr)
				std::cerr<<"Difference in frame "<<numFrames-1<<", "<<numPixels<<" pixels left"<<std::endl;
			++f0Ptr;
			++f1Ptr;
			--numPixels;
			}
		}
	std::cout<<"Total decompression time: "<<totalTime*1000.0<<" ms, "<<numFrames<<" frames"<<std::endl;
	std::cout<<"Maximum decompression time: "<<maxTime*1000.0<<" ms"<<std::endl;
	std::cout<<"Decompression frame rate: "<<double(numFrames)/totalTime<<" Hz"<<std::endl;
	
	return 0;
	}