这可能是一个简单的问题,但这是我第一次使用cmake,也是第一次复杂的构建,所以我不知道下一步该怎么做。我目前的经验是Python和Java。我搜索了Stackoverflow和OpenCV,但没有找到一个我足够理解的答案来解决这个问题。
我正在尝试按照这个优秀的教程,用包含的非免费代码在Windows上构建一个OpenCV的版本。https:/cv-tricks.comhow-to-installation-of-opencv-4-1-0-in-windows-10-from-source。
当我创建opencv_cvv时,在编译所提供的模块时,我得到了以下两个错误,还有多个警告。
第1527行:59>C:\path\cvv\src\qtutil.utilobserver_ptr.hpp(177,15): 错误C2039: 'logic_error': 不是'std'的成员 (编译源文件C:\path\cvv\src\qtutil\collapsable.cpp)
第1532行:59>C:\path\cvv\src\qtutil.util.utilobserver_ptr.hpp(177,1):错误C2065:'logic_error':未声明的标识符(编译源文件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 collapsable.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.comskvarkopencv-pythonissues126。
已经提供了一个工具链以及如何启用该选项的说明。在我找到这个网站之前,我同时安装了Visual Studio 2015和2019,我不知道这是否有区别,但其中一个评论说使用2015。
我按照说明手动编辑setup.py文件。我以管理员身份从Windows命令行运行所有步骤。
主站提供了OpenCV的预构建版本,没有非自由代码,使用的是他们的工具链的副本。https:/pypi.orgprojectopencv-python
昨天我也遇到了完全相同的问题。有趣的是,我用非自由算法包括opencv_cvv用同样的开发步骤构建了OpenCV。两个系统之间的区别是MSVC和Qt版本。
前一个是MSVC 19.25.28614.0,现在的是MSVC 19.26.28805.0构建的。而以前的Qt版本是5.14.2,新的是5.15.0。
两者我都使用了OpenCV 4.3.0版本和Github fork的OpenCV Contrib。
如果你得到了解决方案,也请告诉我们。