如何从相机保存序列图像? [英] How do I save serial image from camera?

查看:79
本文介绍了如何从相机保存序列图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已从网络摄像头捕获图像并在Windows窗体中以图片框形式显示图像,但我无法自动将每个帧保存到我的磁盘中。我已经设置了OpenCV和visual studio 2010,语言是C ++。以下是我的代码的一部分。

I have captured the image from webcam and show the image in the picturebox in "Windows Form", but I can't save each frame into my disk "automatically". I have setup OpenCV and visual studio 2010 and the language is C++. The following is part of my code.

videoInput *VI;     
int width,height,ID,index;
unsigned char* resultBufer;
bool HaveNewFrame,StarToWork;

//initialization
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)    
{
         this->VI = new videoInput();
         this->ID = 1;
         this->index = 0;
	 this->VI->setupDevice(ID);
	 this->width = this->VI->getWidth(ID);
	 this->height = this->VI->getHeight(ID);
	 this->resultBufer = new unsigned char[this->width*this->height*3];
	 this->HaveNewFrame = false;
	 this->StarToWork = false;
    	 this->backgroundWorker1->RunWorkerAsync();   
			    
}

//show the image in the picturebox
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) 
{   
				
	 if (this->HaveNewFrame)
	 {
	        this->HaveNewFrame = false;
	        IntPtr pt1(this->resultBufer);
					 
		System::Drawing::Bitmap^ My_Vision = gcnew System::Drawing::Bitmap(this->width,this->height,this->width*3,Drawing::Imaging::PixelFormat::Format24bppRgb,pt1);
	         
                this->pictureBox1->Image = My_Vision;	
		//I want to save each frame into my disk 
	 }
				
}	

//get the frame from the webcam
private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) 
{
				 
	while (1)
	{
	        Sleep(1);
		if (this->VI->isFrameNew(ID))
		{
		        this->VI->getPixels(ID,this->resultBufer,false,true);
			this->HaveNewFrame = true;
			this->StarToWork = true;
			
		}
	}
				 
}

推荐答案

我修改了我的原始代码并在timer1_Tick中添加代码如下。

I modified my original code and added the code in the timer1_Tick as following.
i++;  
My_Vision->Save("D:\\"+i+".bmp");



最后,它工作成功。


Finally, it works successfully.


这篇关于如何从相机保存序列图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆