Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C++
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;
			
		}
	}
				 
}
Posted
Updated 7-Jul-14 3:27am
v2
Comments
Maciej Los 7-Jul-14 9:32am    
And the problem is...

1 solution

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

Finally, it works successfully.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900