这是我第一次使用Visual Studio Professional 2010进行GUI尝试,是的,它涉及OpenCV。请查看以下代码
GUI代码非常简单,只包含1个按钮。
Form1.h
#pragma once
#include "ImageOpen.h"
namespace GUI {
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(27, 49);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// 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->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
ImageOpen i;
i.OpenImage();
}
};
}
Form1.cpp
// GUI.cpp:主项目文件。
#include "stdafx.h"
#include "Form1.h"
using namespace GUI;
[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;
}
ImageOpen.h
#pragma once
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
class ImageOpen
{
public:
ImageOpen(void);
void OpenImage();
};
ImageOpen.cpp
#include "StdAfx.h"
#include "ImageOpen.h"
ImageOpen::ImageOpen(void)
{
}
void ImageOpen::OpenImage()
{
Mat image = imread("C:/Users/Public/Pictures/Sample Pictures/Tulips.jpg");
namedWindow("Image");
imshow("Image",image);
waitKey(0);
}
GUI简单如下,所以我认为您甚至不必查看GUI代码
不幸的是,当我运行时,我收到以下错误
1>------ Build started: Project: GUI, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> GUI.cpp
1> ImageOpen.cpp
1> Generating Code...
1>LINK : fatal error LNK1104: cannot open file 'tbb_debug.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这也发生在VS 2010 Express中。为什么我收到此错误?我在opencv中找不到tbb_debug.lib文件。我的opencv版本是2.4。请帮忙!
更新
此链接OpenCV and VS2010: Fatal error LNK1104: atal error LNK1104: cannot open file 'tbb_debug.lib表明我们需要将公共语言运行时支持更改为无公共语言运行时支持。
然后我收到此错误
1>------ Build started: Project: GUI, Configuration: Debug Win32 ------
1> stdafx.cpp
1> ImageOpen.cpp
1> GUI.cpp
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(6): error C2871: 'System' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(7): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(7): error C2871: 'ComponentModel' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(8): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(8): error C2871: 'Collections' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(9): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(9): error C2871: 'Forms' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(10): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(10): error C2871: 'Data' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(11): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(11): error C2871: 'Drawing' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(16): error C2059: syntax error : 'public'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(16): error C2059: syntax error : 'public'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(16): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(17): error C2143: syntax error : missing ';' before '{'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\form1.h(17): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(8): error C2337: 'STAThreadAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(9): error C2065: 'array' : undeclared identifier
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(9): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(9): error C2275: 'cv::String' : illegal use of this type as an expression
1> c:\opencv\build\include\opencv2\core\core.hpp(87) : see declaration of 'cv::String'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(9): error C2059: syntax error : '>'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(10): error C2143: syntax error : missing ';' before '{'
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\gui.cpp(10): error C2447: '{' : missing function header (old-style formal list?)
1> AssemblyInfo.cpp
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(3): error C2871: 'System' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(4): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(4): error C2871: 'Reflection' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(5): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(5): error C2871: 'CompilerServices' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(6): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(6): error C2871: 'InteropServices' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(7): error C2653: 'System' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(7): error C2871: 'Permissions' : a namespace with this name does not exist
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(14): error C2337: 'AssemblyTitleAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(15): error C2337: 'AssemblyDescriptionAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(16): error C2337: 'AssemblyConfigurationAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(17): error C2337: 'AssemblyCompanyAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(18): error C2337: 'AssemblyProductAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(19): error C2337: 'AssemblyCopyrightAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(20): error C2337: 'AssemblyTrademarkAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(21): error C2337: 'AssemblyCultureAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(34): error C2337: 'AssemblyVersionAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(36): error C2337: 'ComVisible' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(38): error C2337: 'CLSCompliantAttribute' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(40): error C2337: 'SecurityPermission' : attribute not found
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(40): error C2653: 'SecurityAction' : is not a class or namespace name
1>c:\users\yohan\documents\visual studio 2010\projects\gui\gui\assemblyinfo.cpp(40): error C2065: 'RequestMinimum' : undeclared identifier
1> missing quotes ("") around 'RequestMinimum'?
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
答案 0 :(得分:0)
正如链接中提出的那样:OpenCV and VS2010: Fatal error LNK1104: atal error LNK1104: cannot open file 'tbb_debug.lib
您可以将公共语言运行时支持(/ clr)更改为配置属性中的无公共语言运行时支持 - &gt;一般 - &gt;公共语言运行时。
您还没有在Form1.h