c++ - 创建 OpenCV 非免费版本 v4.3 时出错,collapsable.cpp -errors C2039、2605
问题描述
这可能是一个简单的问题,但这是我第一次使用 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': is not a member of 'std' (编译源文件 C: \path\cvv\src\qtutil\collapsable.cpp)
第 1532 行:59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,1): error C2065: 'logic_error': undeclared identifier (编译源文件 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 可折叠.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/
推荐阅读
- c# - 父面板的 MouseWheel - 从子传递事件
- python - Pandas 使用 item() 从日期时间索引中给出整数
- c# - 无法在与枚举绑定的组合框中设置“SelectedValue”
- instagram - 我使用 Instagram API 中的哪个端点从关注的帐户中检索数据,例如他们拥有的关注者数量?
- geometry - 将一系列深度图和 x、y、z、theta 值转换为 3D 模型
- amazon-web-services - 是否应该在一批插入 dynamoddb 之前对项目进行洗牌?
- python - 烧瓶运行错误python,虚拟环境中没有名为flask的模块
- python - 列表索引超出范围 - 卡方检验
- ubuntu - 如何通过 anisble playbook 注释多行
- uwp - 如何以编程方式截取 uwp 应用程序 samsung odyssey 的屏幕截图?