创建 OpenCV 非自由版本 v4.3 时出错,可折叠.cpp错误 C2039、2605

Error creating OpenCV Non Free build v4.3, collapsable.cpp -errors C2039, 2605

本文关键字:cpp 可折叠 错误 C2039 2605 出错 OpenCV 自由 版本 v4 创建      更新时间:2023-10-16

这可能是一个简单的问题,但这是我第一次使用cmake和第一个复杂的构建,所以我不知道下一步该尝试什么。我目前的经验是Python和Java。我搜索了Stackoverflow和OpenCV,但没有找到一个我理解得足够多的答案来解决这个问题。

我正在尝试在Windows上构建一个版本的OpenCV,其中包含以下非自由代码,遵循这个优秀的教程 https://cv-tricks.com/how-to/installation-of-opencv-4-1-0-in-windows-10-from-source/

我在创建opencv_cvv时编译提供的模块时遇到以下 2 个错误,还有多个警告。

第 1527 行:59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,15(: 错误 C2039:"logic_error":不是"std"(编译源代码(的成员 file C:\path\cvv\src\qtutil\collapsable.cpp(

第 1532 行:59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,1(: 错误 C2065:"logic_error":未声明的标识符(编译源 file C:\path\cvv\src\qtutil\collapsable.cpp(

开发步骤
使用 Visual Studio 2019 和 cmake 进行构建,均于 20 年 5 月 22 日安装。 20 年 5 月 22 日下载了 OpenCV 4.3.0 和OpenCV_contrib代码,完全按照教程所说的说明进行操作,但有一个例外,我选择了 OPENCV_ENABLE_NONFREE

为了消除OpenCV_contrib代码并构建问题,我使用本教程成功构建,而无需选择 NONFREE 或提供额外模块的路径。所以安装和构建似乎还可以。

OpenCV可折叠.cpp

#include "collapsable.hpp"
namespace cvv
{
namespace qtutil
{
Collapsable::Collapsable(const QString &title, std::unique_ptr<QWidget> widget,
bool isCollapsed, QWidget *parent)
: QFrame{ parent }, widget_{ widget.get() }, layout_{ nullptr }
{
auto lay = util::make_unique<QVBoxLayout>();
layout_ = *lay;
// set alignment+border
setLineWidth(1);
setFrameStyle(QFrame::Box);
layout_->setAlignment(Qt::AlignTop);
layout_->setContentsMargins(0, 0, 0, 0);
// build header
auto tmpButton = util::make_unique<QPushButton>();
button_ = tmpButton.get();
button_->setEnabled(true);
button_->setText(title);
button_->setCheckable(true);
// build widget
setLayout(lay.release());
layout_->addWidget(tmpButton.release());
layout_->addWidget(widget.release());
// connect signals and slots
QObject::connect(button_, SIGNAL(clicked()), this,
SLOT(toggleVisibility()));
// collapse/ expand according to isCollapsed
collapse(isCollapsed);
}
// Collapsable::Collapsable(const QString& title,QWidget& widget, bool
// isCollapsed, QWidget *parent):
//  Collapsable{title, std::unique_ptr<QWidget>{&widget}, isCollapsed,
//parent} {}
void Collapsable::collapse(bool b)
{
button_->setChecked(!b);
if (b)
{
widget_->hide();
}
else
{
widget_->show();
}
}
QWidget *Collapsable::detachWidget()
{
if (!widget_)
{
return nullptr;
}
layout_->removeWidget(widget_);
QWidget *tmp = widget_;
widget_ = nullptr;
return tmp;
}
}
} // end namespaces qtutil, cvv

OpenCV collapsable.hpp

#ifndef CVVISUAL_COLLAPSABLE_H
#define CVVISUAL_COLLAPSABLE_H
// std
#include <cstddef>
// QT
#include <QString>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QLabel>
#include <QFrame>
#include "../util/util.hpp"
#include "../util/observer_ptr.hpp"
namespace cvv
{
namespace qtutil
{
/**
* @brief Contains a widget and a title.
*
* The widget can be collapsed and expanded with a button.
* If the widget is collapsed only button and title are shown.
*/
class Collapsable : public QFrame
{
Q_OBJECT
public:
/**
* @brief Constructs a collapsable
* @param title The title above the widget.
* @param widget The widget to store.
* @param isCollapsed If true the contained widget will be collapsed.
* (It will be shown
* otherwise.)
*/
// explicit Collapsable(const QString& title, QWidget& widget, bool
// isCollapsed = true,
//      QWidget *parent = 0);
explicit Collapsable(const QString &title,
std::unique_ptr<QWidget> widget,
bool isCollapsed = true, QWidget *parent = 0);
~Collapsable()
{
}
/**
* @brief Collapses the contained widget.
* @param b
* @parblock
*      true: collapses the widget
*      false: expands the widget
* @endparblock
*/
void collapse(bool b = true);
/**
* @brief Expands the contained widget.
* @param b
* @parblock
*      true: expands the widget
*      false: collapses the widget
* @endparblock
*/
void expand(bool b = true)
{
collapse(!b);
}
/**
* @brief Sets the title above the widget.
*/
void setTitle(const QString &title)
{
button_->setText(title);
}
/**
* @brief Returns the current title above the widget.
* @return The current title above the widget
*/
QString title() const
{
return button_->text();
}
/**
* @brief Returns a reference to the contained widget.
* @return A reference to the contained widget.
*/
QWidget &widget()
{
return *widget_;
}
const QWidget &widget() const
{
return *widget_;
}
/**
* @brief Detaches the contained widget. (ownership remains)
* @return The contained widget
*/
QWidget *detachWidget();
private
slots:
/**
* @brief Toggles the visibility.
*/
void toggleVisibility()
{
collapse(widget_->isVisible());
}
private:
/**
* @brief The contained widget
*/
QWidget *widget_;
/**
* @brief The button to toggle the widget
*/
QPushButton *button_;
/**
* @brief The layout containing the header and widget
*/
util::ObserverPtr<QVBoxLayout> layout_;
}; // Collapsable
}
} // end namespaces qtutil, cvv
#endif // CVVISUAL_COLLAPSABLE_H

我将跟进@Cris Luengo的 #include 评论,因为我想了解我的构建出了什么问题。

但是,我也找到了一种不同的安装方法,我刚刚在测试中成功。

链接在这里 https://github.com/skvark/opencv-python/issues/126

提供了一个工具链以及有关如何启用该选项的说明。在找到该网站之前,我已经安装了Visual Studio 2015和2019,我不知道这是否有区别,但其中一条评论说使用2015。

我按照说明手动编辑 setup.py 文件。我以管理员身份从 Windows 命令行运行了所有步骤。

主站点提供没有非自由代码的OpenCV的预构建版本,它是使用的工具链的副本。 https://pypi.org/project/opencv-python/