OpenCV 在窗口关闭时中止(核心转储)

OpenCV Aborted (core dumped) When the Window Is Closed

本文关键字:核心 转储 窗口 OpenCV      更新时间:2023-10-16

我尝试读取相机帧并使用cv::cuda::GpuMat通过cv::namedWindow显示它。

这是我C++代码:

cv::namedWindow("frame", cv::WINDOW_OPENGL);
cv::resizeWindow("frame", FRAME_WIDTH, FRAME_HEIGHT);
while (true) {
cv::Mat frame;
cv::cuda::GpuMat frame_gpu;
camera.read(frame);
frame_gpu.upload(frame);
cv::imshow("frame", frame_gpu);
//frame_gpu.download(frame);
if (cv::waitKey(1) == 27) {
break;
}
}
cv::destroyAllWindows();

如果我关闭窗口,我会收到此错误:

OpenCV Error: The function/feature is not implemented (You should explicitly call download method for cuda::GpuMat object) in getMat_, file /home/nvidia/opencv-3.2.0/modules/core/src/matrix.cpp, line 1276
terminate called after throwing an instance of 'cv::Exception'
what():  /home/nvidia/opencv-3.2.0/modules/core/src/matrix.cpp:1276: error: (-213) You should explicitly call download method for cuda::GpuMat object in function getMat_
Aborted (core dumped)

如果我键入Esc键来结束逻辑,它不会引发任何异常。

为什么我会收到此错误,如何解决此问题?

我想错误是关于您尝试使用 imshow 显示GpuMat图像。您需要先将其下载到其他Mat,然后才能使用 imshow 显示它。 试试这个

cv::Mat host;
frame_gpu.upload(frame);
frame_gpu.download(host)
cv::imshow("frame", host);