Ask Your Question
0

How to acquire image with opencv and Windows Form Application

asked 2014-02-26 04:22:25 -0500

tiho_bg gravatar image

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

berak gravatar image

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();
             }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-26 05:10:56 -0500

First check the interval of the timer. If there is no problem, make a benchmark and see how long takes every line of code in function timer1_Tick. Then we will think about a solution.

edit flag offensive delete link more

Comments

Thank you for your answer my Bulgarian friend. How to make this kind of checking of the timer? This code below is working better for me but when I would like to start the application again I saw that the .exe file was not stopped. May be something is wrong with my timer. What is the problem?

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

capture = cvCaptureFromCAM(0);

timer1->Start();

         }

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

             frame = cvQueryFrame(capture);

pictureBox1->Image = gcnew //replacement of cvShowImage

System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,

System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);

pictureBox1->Refresh(); }

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

                 timer1->Stop();
             Application::Exit();
         }
tiho_bg gravatar imagetiho_bg ( 2014-02-26 07:55:31 -0500 )edit
     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        timer1->Interval=100; \\Time interval in miliseconds
        timer1->Start();
     }
     private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
            MessageBox::Show("The calculations are complete", "My Application", MessageBoxButtons::OKCancel, MessageBoxIcon::Asterisk);
     }
Spas Hristov gravatar imageSpas Hristov ( 2014-02-28 01:56:17 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-02-26 04:22:25 -0500

Seen: 590 times

Last updated: Feb 28 '14