Search code examples
c++opencvgtk

OpenCV's namedWindow is not implemented


When I run my C++ code, I get this error:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.1.0) /home/me/opencv/modules/highgui/src/window.cpp:610: 
error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, 
GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, 
then re-run cmake or configure script in function 'cvNamedWindow'

So then I went ahead and ran this command:

sudo apt-get install libgtk2.0-dev pkg-config -y

After re-running cmake, the same error persists.

I have all of the necessary imports:

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>

This is the line of code that is throwing the error:

cv::namedWindow("input video", cv::WINDOW_NORMAL);

Solution

  • Install a window development library:

        sudo apt-get install libgtk2.0-dev pkg-config
    

    Rebuild opencv:

        cd build
        cmake ../opencv-4.x
        cmake --build .
        sudo make install