Ask Your Question
0

opencv in windows form

asked 2013-09-04 01:50:14 -0600

lenteken gravatar image

updated 2013-09-04 01:55:55 -0600

berak gravatar image

I am using now windows form in visual c++. I got an error:

error C2065: 'Filename' : undeclared identifier

error C2065: 'openFileDialog1' : undeclared identifier

error C2227: left of '->FileName' must point to class/struct/union/generic type

I don't know what is wrong in my code. Anyone who can solve this problem?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
            cv::Mat img;

            img = cv::imread(openFileDialog1->FileName, CV_LOAD_IMAGE_COLOR);

            System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
            System::IntPtr ptr(img.ptr());
            System::Drawing::Bitmap^ b  = gcnew System::Drawing::Bitmap(img.cols,img.rows,img.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
            System::Drawing::RectangleF rect(0,0,pictureBox1->Width,pictureBox1->Height);
            graphics->DrawImage(b,rect);


         }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-04 02:23:25 -0600

berak gravatar image

2 problems there:

  • you don't initialize openFileDialog1 properly. so it has no filename yet

  • you're reading an img into a local var ( cv::Mat img; )

    it will go out of scope, and your program will crash.

    you'll probably will have to make cv::Mat img a member of your Form class

edit flag offensive delete link more

Comments

How can I initialize openFileDialog1? can you show me some code ?

lenteken gravatar imagelenteken ( 2013-09-04 02:58:45 -0600 )edit
2

there's a couple of ways to do so, ranging from getting a (global) one from the toolbox to constructing one with gcnew. i have no idea, what's best for you.

berak gravatar imageberak ( 2013-09-04 03:15:31 -0600 )edit

Question Tools

Stats

Asked: 2013-09-04 01:50:14 -0600

Seen: 684 times

Last updated: Sep 04 '13