0

这是我第一次使用 Visual Studio Professional 2010 进行 GUI 尝试,是的,它涉及 OpenCV。请看下面的代码

GUI 代码非常简单,仅包含 1 个按钮。

表格1.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;
}

图像打开.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();
};

图像打开.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 ==========
4

1 回答 1

0

如链接中所建议:OpenCV and VS2010: Fatal error LNK1104: atal error LNK1104: cannot open file 'tbb_debug.lib

您可以在配置属性->常规->公共语言运行时中将公共语言运行时支持 (/clr) 更改为无公共语言运行时支持。

您还没有包含相关的 windows 窗体头文件Form1.h

于 2013-04-24T06:29:47.067 回答