Profactor / cv-plot

fast modular opencv plotting library
MIT License
159 stars 30 forks source link

given demo terminate: Can't destroy non-registered window #4

Closed skyblueee closed 4 years ago

skyblueee commented 4 years ago

This project is awesome, but I met some basic error with the demo code.

a.cpp:

#include <CvPlot/cvplot.h>
int main(int argc, char *argv[])
{
    auto axes = CvPlot::plot(std::vector<double> {3, 3, 4, 6, 4, 3}, "-o");
    CvPlot::show("mywindow", axes);
    return 0;
}

$ g++ --version g++ (Debian 9.3.0-15) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -DCVPLOT_HEADER_ONLY -I$HOME/cv-plot/CvPlot/inc -I/usr/include/opencv4 a.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui $ ./a.out terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.2.0) ../modules/highgui/src/window_gtk.cpp:1260: error: (-215:Assertion failed) found && "Can't destroy non-registered window" in function 'cvDestroyWindow'

Aborted

I followed the code and think the problem is from Window.h:

inline
Window::Window(std::string windowName, Axes &axes, int rows, int cols)
    :_mouseAdapter(axes)
    , _windowName(windowName) {

    cv::destroyWindow(windowName); //destroy opencv window if existing       ############## HERE. if comment out, err in deconstructor
    cv::namedWindow(windowName, cv::WINDOW_NORMAL);
    cv::resizeWindow(windowName, { cols,rows });
    axes.render(_mat, cv::Size(cols, rows));
    cv::imshow(windowName, _mat);
    cv::setMouseCallback(windowName, [](int event, int x, int y, int flags, void* userdata) {
        Window& window = *static_cast<Window*>(userdata);
        window.updateSize();
        MouseEvent mouseEvent(window._mouseAdapter.getAxes(), window._mat.size(), event, x, y, flags);
        if (window._mouseAdapter.mouseEvent(mouseEvent)) {
            window.update();
        }
        }, this);
}

inline
Window::~Window() {
    cv::destroyWindow(_windowName);       ########### ALSO NOTE HERE PLEASE
}

There is no problem if I use:

cv::Mat mat = axes.render(300, 400);
cv::imshow("mywindow", mat);
cv::waitKey();
wpalfi commented 4 years ago

Hi @skyblueee, thanx for reporting! I am using windows normally. Never tested the gui-stuff with gtk before:-). Should be fixed with https://github.com/Profactor/cv-plot/commit/6480ffe8e67c9490e75ffa8b1e55bd6e5e74fbd1. Could you please test the master branch? Gtk does not support free-ratio windows, so the plot ratio is fixed when you resize the window. Apart from that, everything seems to work now.

skyblueee commented 4 years ago

thanks, i have tried it. It works great.