Ask Your Question
0

opencv in windows form

asked Sep 4 '13

lenteken gravatar image

updated Sep 4 '13

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);


         }
Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Sep 4 '13

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

Preview: (hide)

Comments

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

lenteken gravatar imagelenteken (Sep 4 '13)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 (Sep 4 '13)edit

Question Tools

Stats

Asked: Sep 4 '13

Seen: 727 times

Last updated: Sep 04 '13