cvWaitKey:函数未实现。使用 Windows、GTK+ 2.x 或 Carbon 支持重建库

cvWaitKey: The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support

使用 OpenCV,我试图从摄像头获取视频流,但出现此错误:

openOpenCV(3.4.3) Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvWaitKey, file /home/Ulugbe/Downloads/Telegram Desktop/opencv-3.4.3/modules/highgui/src/window.cpp, line 698

terminate called after throwing an instance of 'cv::Exception'

what(): OpenCV(3.4.3) /home/Ulugbe/Downloads/Telegram Desktop/opencv-3.4.3/modules/highgui/src/window.cpp:698: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'

这是我的代码:

#include <opencv2/opencv.hpp>
#include <dlib/any.h>
#include <iostream>

int main (int argc, char **argv)
{
    
    std::cout << cv::getBuildInformation() << std::endl;
    cv::VideoCapture video(0);
    // video.open("/home/Ulugbe/oson/ulugbek_face.mp4");
    if(video.isOpened())
        std::cout<<"open";
    
    cv::Mat frame;
    video.read(frame);

    cv::imshow("image", frame);
    cv::waitKey(0);

    video.release();

    return 0;
}

我不明白这个错误,因为消息中的opencv版本不适合我当前的版本,错误中显示的路径也不存在(但我记得它最初安装在那里但它是然后以 root 身份卸载和安装)。

如果注释掉 imshowwaitKey 行,程序将不会显示任何错误,所以我认为问题与此有关。

我的 NetBeans 配置的屏幕截图: compiler properties linker properties

路径仍然“存在”,因为它存储在您构建的库中。保留是因为它是有用的调试信息。

您在没有任何 GUI 支持的情况下构建了 OpenCV。这就是错误的意思。它还说:

Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'

所以你应该重建 OpenCV。 运行 cmake-gui 并查看输出以了解可能的 GUI 后端,以及导致它们不可用的原因。浏览 settings/variables 并在启用 none 的情况下启用 GUI 后端。