Пример #1
0
ImageSequenceMovieSaver::~ImageSequenceMovieSaver(void)
	{
	/* Signal the frame capturing and saving threads to shut down: */
	done=true;
	{
	Threads::MutexCond::Lock captureLock(captureCond);
	captureCond.signal(captureLock);
	}
	
	/* Wait until the frame saving thread has saved all frames and terminates: */
	frameSavingThread.join();
	}
Пример #2
0
void* ImageSequenceMovieSaver::frameSavingThreadMethod(void)
	{
	unsigned int frameIndex=0;
	while(true)
		{
		/* Wait for the next frame: */
		FrameBuffer frame;
		{
		Threads::MutexCond::Lock captureLock(captureCond);
		while(!done&&capturedFrames.empty())
			captureCond.wait(captureLock);
		if(capturedFrames.empty()) // Bail out if there will be no more frames
			break;
		frame=capturedFrames.front();
		capturedFrames.pop_front();
		}
		
		/* Open the next frame image file: */
		char frameName[1024];
		snprintf(frameName,sizeof(frameName),frameNameTemplate.c_str(),frameIndex);
		++frameIndex;
		Misc::File frameFile(frameName,"wb");
		
		/* Get the image from the frame buffer: */
		int width=frame.getFrameSize()[0];
		int height=frame.getFrameSize()[1];
		const unsigned char* buffer=frame.getBuffer();
		
		/* Write the PPM header: */
		fprintf(frameFile.getFilePtr(),"P6\n");
		fprintf(frameFile.getFilePtr(),"%d %d\n",width,height);
		fprintf(frameFile.getFilePtr(),"255\n");
		
		/* Write each row of the frame buffer: */
		for(int y=height-1;y>=0;--y)
			frameFile.write(buffer+y*width*3,width*3);
		}
	
	return 0;
	}
Пример #3
0
void ImageSequenceMovieSaver::frameWritingThreadMethod(void)
	{
	/* Save frames until shut down: */
	unsigned int frameIndex=0;
	while(!done)
		{
		/* Add the most recent frame to the captured frame queue: */
		{
		Threads::MutexCond::Lock captureLock(captureCond);
		frames.lockNewValue();
		capturedFrames.push_back(frames.getLockedValue());
		captureCond.signal(captureLock);
		}
		
		/* Wait for the next frame: */
		int numSkippedFrames=waitForNextFrame();
		if(numSkippedFrames>0)
			{
			std::cerr<<"MovieSaver: Skipped frames "<<frameIndex<<" to "<<frameIndex+numSkippedFrames-1<<std::endl;
			frameIndex+=numSkippedFrames;
			}
		}
	}
Пример #4
0
void _StartCapture(CvCapture **capture, IplImage **image)
{
	IplImage *tempImage;
	try {
		while(1) {
			boost::unique_lock<boost::mutex> captureLock(captureMutex);
			if(*capture) tempImage = cvQueryFrame(*capture);
			else {
				cvReleaseImage(&tempImage);
				return;
			}
			captureLock.unlock();

			cvCvtColor(tempImage, tempImage, CV_BGR2RGB);
			boost::unique_lock<boost::mutex> imageLock(imageMutex);
			cvReleaseImage(image);
			*image = cvCloneImage(tempImage);
			ready = 1;
			imageLock.unlock();
		}
	} catch (const std::exception &e) {
		std::cout << e.what() << std::endl;
	}
}