1
votes

This may be a simple problem but this is my first use of cmake and first complicated build so I don't know what to try next. My current experience is Python and Java. I have searched Stackoverflow and OpenCV but did not find an answer that I understood enough to solve this problem.

I am trying to build a version of OpenCV on Windows with the non-free code included following this excellent tutorial https://cv-tricks.com/how-to/installation-of-opencv-4-1-0-in-windows-10-from-source/

I get the following 2 errors in compiling the supplied modules when creating opencv_cvv, there are also multiple warnings.

Line 1527: 59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,15): error C2039: 'logic_error': is not a member of 'std' (compiling source file C:\path\cvv\src\qtutil\collapsable.cpp)

Line 1532: 59>C:\path\cvv\src\qtutil../util/observer_ptr.hpp(177,1): error C2065: 'logic_error': undeclared identifier (compiling source file C:\path\cvv\src\qtutil\collapsable.cpp)

Development steps
Using Visual Studio 2019 and cmake to build, both installed on 22 May 20. Downloaded OpenCV 4.3.0 and the OpenCV_contrib code on 22 May 20 following the instructions exactly as the tutorial says with one exception, I selected OPENCV_ENABLE_NONFREE

To eliminate the OpenCV_contrib code, and build issues I built succesfully using the tutorial without selecting NONFREE or supplying the path to the extra modules. So the installation and build seem OK.

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
2
The error occurs in ../util/observer_ptr.hpp. It likely is missing a #include <stdexcept>, because that is where std::logic_error is declared according to the standard.Cris Luengo
Thank you for your feedback I will look for thisRoo

2 Answers

0
votes

I will follow up the #include comment from @Cris Luengo as I would like to understand what went wrong with my build.

However I have also tracked down a different method for installation which I have just suceeded in testing.

The link is here https://github.com/skvark/opencv-python/issues/126

A toolchain has been provided along with instructions on how to enable the option. I had both Visual Studio 2015 and 2019 installed before I found the site, I don't know if that made a difference but one of the comments said use 2015.

I followed the instructions to manually edit the setup.py file. I ran all the steps from the Windows command line as an administrator.

The home site provides pre-built versions of OpenCV without the non-free code and it is a copy of their toolchain that is used. https://pypi.org/project/opencv-python/

0
votes

yesterday i also ran through the totally the same problem.. Did you get any clues what caused this problem? Interestingly, i have built the OpenCV with non free algorithms including opencv_cvv using the same development steps. The difference between two systems is MSVC and Qt versions.

The former one was MSVC 19.25.28614.0 and the current one is MSVC 19.26.28805.0 built. And the former Qt version was 5.14.2 and the new one is 5.15.0.

Both i used OpenCV 4.3.0 release and OpenCV Contrib from the Github fork.

If you get the solution please also let us know