Thread: problem combining forms in visual c++ with opencv

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    problem combining forms in visual c++ with opencv

    I've taught myself basic opencv functionality and I've taught myself how to create forms using visual c++, but I can't merge the two.

    At the moment, all I'm trying to do is write a program that creates a form with a single button "display image" which when pressed, gets opencv to open an image.

    The problem I get is when I include open cv libraries

    #include <cv.h>
    #include <cxcore.h>
    #include <highgui.h>

    in the following code (code for the forms)

    Code:
     // Opencv_helloworld.cpp : main project file.
    
    #include "stdafx.h"
    #include "Form1.h"
    
    
    using namespace Opencv_helloworld;
    
    [STAThreadAttribute]
    int main(array<System::String ^> ^args)
    {
    	// Enabling Windows XP visual effects before any controls are created
    	Application::EnableVisualStyles();
    	Application::SetCompatibleTextRenderingDefault(false); 
    
    	// Create the main window and run it
    	Application::Run(gcnew Form1());
    	return 0;
    }
    Form1.h:

    Code:
    #pragma once
    
    namespace Opencv_helloworld {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <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;
    	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->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(93, 112);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(108, 23);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"Display Image";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(284, 262);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    			 }
    	};
    }
    When I run this, the form appears with the button (although pressing it doesn't do anything, obviously). As soon as I try to add the opencv libraries I get the following errors:

    1>------ Build started: Project: Opencv_helloworld, Configuration: Debug Win32 ------
    1> Opencv_helloworld.cpp
    1>c:\programdata\opencv2.2\include\opencv2\core\op erations.hpp(81): warning C4793: '`anonymous namespace'::CV_XADD' : function compiled as native :
    1> Inline native assembly not supported in managed code
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class std::vector<float,class std::allocator<float> > const &)" (?setSVMDetector@HOGDescriptor@cv@@UAEXABV?$vector @MV?$allocator@M@std@@@std@@@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::HOGDescriptor::read(class cv::FileNode &)" (?read@HOGDescriptor@cv@@UAE_NAAVFileNode@2@@Z)
    1>Opencv_helloworld.obj : 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)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::HOGDescriptor::load(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?load@HOGDescriptor@cv@@UAE_NABV?$basic_string@DU ?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?save@HOGDescriptor@cv@@UBEXABV?$basic_string@DU? $char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::copyTo(struct cv::HOGDescriptor &)const " (?copyTo@HOGDescriptor@cv@@UBEXAAU12@@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::compute(class cv::Mat const &,class std::vector<float,class std::allocator<float> > &,class cv::Size_<int>,class cv::Size_<int>,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > const &)const " (?compute@HOGDescriptor@cv@@UBEXABVMat@2@AAV?$vect or@MV?$allocator@M@std@@@std@@V?$Size_@H@2@2ABV?$v ector@V?$Point_@H@cv@@V?$allocator@V?$Point_@H@cv@ @@std@@@5@@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::detect(class cv::Mat const &,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > &,double,class cv::Size_<int>,class cv::Size_<int>,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > const &)const " (?detect@HOGDescriptor@cv@@UBEXABVMat@2@AAV?$vecto r@V?$Point_@H@cv@@V?$allocator@V?$Point_@H@cv@@@st d@@@std@@NV?$Size_@H@2@2ABV45@@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::detectMultiScale(class cv::Mat const &,class std::vector<class cv::Rect_<int>,class std::allocator<class cv::Rect_<int> > > &,double,class cv::Size_<int>,class cv::Size_<int>,double,int)const " (?detectMultiScale@HOGDescriptor@cv@@UBEXABVMat@2@ AAV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H @cv@@@std@@@std@@NV?$Size_@H@2@2NH@Z)
    1>Opencv_helloworld.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::computeGradient(class cv::Mat const &,class cv::Mat &,class cv::Mat &,class cv::Size_<int>,class cv::Size_<int>)const " (?computeGradient@HOGDescriptor@cv@@UBEXABVMat@2@A AV32@1V?$Size_@H@2@2@Z)
    1>d:\documents\visual studio 2010\Projects\Opencv_helloworld\Debug\Opencv_hello world.exe : fatal error LNK1120: 10 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    What am I doing wrong?

  2. #2
    Registered User
    Join Date
    Feb 2011
    Posts
    1
    I have exactly the same Problem! Could you find a solution?

    Thx for help..

    Robert

  3. #3
    a newbie :p
    Join Date
    Aug 2008
    Location
    Zurich, Switzerland, Switzerland
    Posts
    91
    I think, it is linker problem:

    Add these entries on Additional Dependencies option (for debug configuration):

    * C:\Program Files\OpenCV2.2\lib\opencv_core220d.lib
    * C:\Program Files\OpenCV2.2\lib\opencv_highgui220d.lib
    * C:\Program Files\OpenCV2.2\lib\opencv_video220d.lib
    * C:\Program Files\OpenCV2.2\lib\opencv_ml220d.lib
    * C:\Program Files\OpenCV2.2\lib\opencv_legacy220d.lib
    * C:\Program Files\OpenCV2.2\lib\opencv_imgproc220d.lib

    You need to eliminate ending d for release build.
    Consult here: VisualC++ - OpenCV Wiki

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Forms are not available in C++. They are part of Managed C++ or C++/CLI.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual studio.net C++ Problem
    By Dina in forum C Programming
    Replies: 5
    Last Post: 07-19-2008, 02:34 PM
  2. Problem in visual c++ 6
    By hero_bash in forum C++ Programming
    Replies: 24
    Last Post: 09-17-2007, 10:57 AM
  3. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Microsoft Visual C++ compiler, cast problem?
    By jonnie75 in forum C Programming
    Replies: 5
    Last Post: 11-10-2001, 08:53 AM