gpt4 book ai didi

c++ - namedWindow 函数不创建窗口

转载 作者:行者123 更新时间:2023-11-27 22:55:46 25 4
gpt4 key购买 nike

我正在使用以下代码来显示示例图像,但尽管 imread 实际上返回了一个 cv::Mat 对象,但没有显示任何窗口。调试后我意识到 namedWindow 实际上没有创建任何窗口并且在终端中没有给出错误消息。

cv::Mat dst;
dst=imread("/home/user/catkin_ws/sample.jpg");
std::cout << cv::getBuildInformation() << std::endl;
cv::namedWindow("test");
cv::imshow("test", dst);

这里是我的OpenCV的配置信息

General configuration for OpenCV 2.4.8 =====================================
Version control: unknown

Platform:
Host: Linux 3.2.0-58-generic x86_64
CMake: 2.8.12.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: Release

C/C++:
Built as dynamic libs?: YES
C++ Compiler: /usr/bin/x86_64-linux-gnu-g++ (ver 4.8.2)
C++ flags (Release): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG
C++ flags (Debug): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/x86_64-linux-gnu-gcc
C flags (Release): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG
C flags (Debug): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -ffunction-sections -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now
Linker flags (Debug): -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now
Precompiled headers: YES

OpenCV modules:
To be built: core flann imgproc highgui features2d calib3d ml objdetect video contrib legacy photo gpu java ocl python stitching superres ts videostab
Disabled: world
Disabled by dependency: -
Unavailable: androidcamera dynamicuda

GUI:
QT: NO
GTK+ 2.x: YES (ver 2.24.22)
GThread : YES (ver 2.39.90)
GtkGlExt: YES (ver 1.2.0)
OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libSM.so /usr/lib/x86_64-linux-gnu/libICE.so /usr/lib/x86_64-linux-gnu/libX11.so /usr/lib/x86_64-linux-gnu/libXext.so)

Media I/O:
ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.50)
TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.3)
JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 1.6.1)

Video I/O:
DC1394 1.x: NO
DC1394 2.x: YES (ver 2.2.1)
FFMPEG: YES
codec: YES (ver 54.35.0)
format: YES (ver 54.20.3)
util: YES (ver 52.3.0)
swscale: YES (ver 2.1.1)
gentoo-style: YES
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
PvAPI: NO
GigEVisionSDK: NO
UniCap: NO
UniCap ucil: NO
V4L/V4L2: Using libv4l (ver 1.0.1)
XIMEA: NO
Xine: NO

Other third-party libraries:
Use IPP: NO
Use Eigen: YES (ver 3.2.0)
Use TBB: YES (ver 4.2 interface 7000)
Use OpenMP: NO
Use GCD NO
Use Concurrency NO
Use C=: NO
Use Cuda: NO
Use OpenCL: YES

OpenCL:
Version: dynamic
Use AMD FFT: NO
Use AMD BLAS: NO

Python:
Interpreter: /usr/bin/python2 (ver 2.7.6)
Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.0.dev-95f7a46)
packages path: lib/python2.7/dist-packages

Java:
ant: /usr/bin/ant (ver 1.9.3)
JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include
Java tests: NO

Documentation:
Build Documentation: YES
Sphinx: /usr/bin/sphinx-build (ver 1.2.1)
PdfLaTeX compiler: /usr/bin/pdflatex

Tests and samples:
Tests: NO
Performance tests: YES
C/C++ Examples: YES

Install path: /usr

cvconfig.h is in: /build/buildd/opencv-2.4.8+dfsg1/obj-x86_64-linux-gnu
-----------------------------------------------------------------

最佳答案

您必须在 cv::imshow 之后调用 cv::waitKey() 以使 OpenCV 管理 GUI 事件并实际创建窗口并等待新事件到达.

cv::waitKey() 将在按下一个键后返回。如果它是您程序的最后一条语句,如您的示例代码中所示,程序将结束并且窗口将关闭。

关于c++ - namedWindow 函数不创建窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com