首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建OpenCV非自由生成v4.3、collapsable.cpp -errors C2039、2605错误

创建OpenCV非自由生成v4.3、collapsable.cpp -errors C2039、2605错误
EN

Stack Overflow用户
提问于 2020-05-24 12:25:21
回答 1查看 302关注 0票数 2

这可能是一个简单的问题,但这是我第一次使用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时,我在编译提供的模块时遇到了以下两个错误,还有多个警告。

59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,15):

第1527行: C2039:‘logic’:不是'std‘的成员(编译源文件C:\path\cvv\src\qtutil\collapsable.cpp)

第1532行: 59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,1):error C2065:‘logic’:未声明的标识符(编译源文件C:\path\cvv\src\qtutil\collapsable.cpp)

开发步骤

使用VisualStudio2019和cmake构建,这两个版本都安装在5月22日。下载了OpenCV 4.3.0,并在5月22日按照教程的说明编写了OpenCV_contrib代码,只有一个例外,我选择了OPENCV_ENABLE_NONFREE。

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

OpenCV collapsable.cpp

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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
EN

回答 1

Stack Overflow用户

发布于 2020-05-25 09:37:23

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

然而,我也找到了一种不同的安装方法,我刚刚成功地通过了测试。

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

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

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

主页提供了OpenCV的预构建版本,而没有免费代码,使用的是它们的工具链的副本。https://pypi.org/project/opencv-python/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61985936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档