Ask Your Question
0

Unable to link opencv to windows form application

asked 2013-10-15 02:29:38 -0600

zulfiqar gravatar image

updated 2013-10-16 05:00:53 -0600

berak gravatar image

i have linked opencv to console application but when i tried to link it to windows form application VS 2010 it gives me following errors

Error   1   error C2065: 'IplImage' : undeclared identifier c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h   130 1   abc
Error   2   error C3861: 'cvLoadImage': identifier not found    c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h   130 1   abc

#pragma once
#include "highgui.h"
#include <opencv2/imgproc/imgproc.hpp>  // Gaussian Blur
#include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>

namespace abc {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;


    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

        protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
        private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::TextBox^  path;
    private: System::Windows::Forms::Button^  summary;
    protected: 


        private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

        #pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->path = (gcnew System::Windows::Forms::TextBox());
            this->summary = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(392, 68);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"browse";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // path
            // 
            this->path->Location = System::Drawing::Point(23, 68);
            this->path->Name = L"path";
            this->path->Size = System::Drawing::Size(304, 20);
            this->path->TabIndex = 1;
            // 
            // summary
            // 
            this->summary->Location = System::Drawing::Point(153, 156);
            this->summary->Name = L"summary";
            this->summary->Size = System::Drawing::Size(159, 27);
            this->summary->TabIndex = 2;
            this->summary->Text = L"summaize video";
            this->summary->UseVisualStyleBackColor = true;
            this->summary->Click += gcnew System::EventHandler(this, &Form1::summary_Click);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(568, 262);
            this->Controls->Add(this->summary);
            this->Controls->Add(this->path);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        Stream^ myStream;
        OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

        openFileDialog1->InitialDirectory = "c:\\";
        openFileDialog1->Filter = "txt files (*.avi)|*.avi|All files (*.*)|*.*";
        openFileDialog1->FilterIndex = 2;
        openFileDialog1->RestoreDirectory = true;

        if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
        {
            if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
            {
                path->Text = Convert::ToString(openFileDialog1->FileName);

                // Insert code to read the stream here.
                String ^ temp = "you have successfully browsed a video";
                System::Windows::Forms::MessageBox::Show(temp);

                myStream->Close();
            }
        }
    }
private: System::Void summary_Click(System::Object^  sender, System::EventArgs^  e) {
            // Set ...
(more)
edit retag flag offensive close merge delete

Comments

add: #include "opencv/cv.h" ?

also, it probably should be : "opencv/highgui.h", not just "highgui.h". did you omit an error here ?

berak gravatar imageberak ( 2013-10-16 05:12:29 -0600 )edit

13 errors like the below appears after adding these headers

Error 8 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::write(class cv::FileStorage &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?write@HOGDescriptor@cv@@UBEXAAVFileStorage@2@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) C:\Users\Ayesha\Documents\Visual Studio 2010\Projects\abc\abc\abc.obj abc

zulfiqar gravatar imagezulfiqar ( 2013-10-16 05:23:18 -0600 )edit

believe it or not, that's progress ;)

your first errors were compiler errors, those now are linker errors.

you forgot to link some libraries, opencv_core246.lib, opencv_objdetect246.lib, opencv_highgui246.lib, opencv_imgproc246.lib. (all of them with a 'd' at the end for DEBUG build)

berak gravatar imageberak ( 2013-10-16 06:20:38 -0600 )edit

after editing .hpp ti .h gives this error

Error 1 error C1083: Cannot open include file: 'opencv2/imgproc/imgproc.h': No such file or directory c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 3 1 abc

zulfiqar gravatar imagezulfiqar ( 2013-10-16 07:29:39 -0600 )edit

where i have to place 'd' ?

zulfiqar gravatar imagezulfiqar ( 2013-10-16 07:34:41 -0600 )edit

. Adding opencv_objdetect230.lib removed my errors . Thanks a lot. Thanks once again

zulfiqar gravatar imagezulfiqar ( 2013-10-16 07:38:59 -0600 )edit
1

oh, nice. you obviously solved the 'opencv2/imgproc/imgproc.hpp' problem on your own ;)

and it will be opencv_objdetect230d.lib for DEBUG.

berak gravatar imageberak ( 2013-10-16 07:54:21 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-10-15 08:13:39 -0600

Winforms is a bit different from the console applications. They do not allow you to use the include of the opencv namespace at the top of the header file, wich generates some rules you need to keep, before you can use opencv functionality inside the header.

Have you put cv:: in front of all of you openCV code? Without, the compiler will not know where to look for the cvLoadImage functionality.

Also if it is possible, switch to the C++ interface, since the C-interface is deprecated and will get removed.

edit flag offensive delete link more

Comments

Thanks it helps to solve my problem to some extent but not completely. I am using cv:: before opencv functions but it is giving error in both cases.

zulfiqar gravatar imagezulfiqar ( 2013-10-16 04:54:04 -0600 )edit

the old c-api does not live in the cv namespace

berak gravatar imageberak ( 2013-10-16 05:14:44 -0600 )edit

what is the solution? what should i do now?

zulfiqar gravatar imagezulfiqar ( 2013-10-16 05:16:21 -0600 )edit

You should remove old C - api and replace it by the C++ variant. For example, instead of using iplimages, use Mat elements. Same for cvLoadImage, replace that one by imread().

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-17 03:59:25 -0600 )edit
0

answered 2013-10-15 07:54:55 -0600

Can you show us the code ?

edit flag offensive delete link more

Comments

1

I have posted my code. error appears in the last function

zulfiqar gravatar imagezulfiqar ( 2013-10-16 04:59:53 -0600 )edit

Question Tools

Stats

Asked: 2013-10-15 02:29:38 -0600

Seen: 3,828 times

Last updated: Oct 16 '13