Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to acquire image with opencv and Windows Form Application

Hi

I would like to open USB camera and acquiring images under windows form application. I create an application but the streaming of images is going very slowly (The images appear and disappear in big intervals). Where is my error. Using a console application there is no such a problem. Here is my code.

timer1->Interval = 1; VideoCapture cap(0); Mat frame; private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

             timer1->Start();

 }
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {

             cap.read(frame);

             graphics = pictureBox1->CreateGraphics();
             System::IntPtr ptr(frame.ptr());

             b  = gcnew System::Drawing::Bitmap(frame.cols,frame.rows,frame.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
             System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);

             graphics->DrawImage(b,rect);

             pictureBox1->Refresh();
         }
click to hide/show revision 2
No.2 Revision

updated 2014-02-26 05:05:28 -0600

berak gravatar image

How to acquire image with opencv and Windows Form Application

Hi

I would like to open USB camera and acquiring images under windows form application. I create an application but the streaming of images is going very slowly (The images appear and disappear in big intervals). Where is my error. Using a console application there is no such a problem. Here is my code.

timer1->Interval = 1;
VideoCapture cap(0);
Mat frame;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

{
 timer1->Start();
 }
 private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
 cap.read(frame);
  graphics = pictureBox1->CreateGraphics();
 System::IntPtr ptr(frame.ptr());
  b = gcnew System::Drawing::Bitmap(frame.cols,frame.rows,frame.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
 System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);
 graphics->DrawImage(b,rect);
 pictureBox1->Refresh();
  }