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?