C++显示图像并将其保持到下一张图像的最佳方法

C++ Best way to display image and hold it until the next image

本文关键字:图像 方法 最佳 一张 显示图 显示 C++      更新时间:2023-10-16

我尝试在opencv中使用imshow来显示一个,但图像窗口关闭并在每个循环中再次显示。有没有办法保持显示器直到新的显示到来,这样图像显示就不会闪烁?

for(int iframe = 0; iframe < 10; iframe++)
{
..some processing code..
cv::imshow("image", a[iframes]);
cv::waitKey(1);
}

检查你的...一些处理代码...:

如果你在每个循环的开头使用 namedWindow(( 和/或在循环结束时使用 destroyWindow((,那么你在每次迭代中都有效地关闭了你的窗口。

删除这些函数调用,除非您绝对确定需要它们。

这两个线程不共享除显示窗口之外的任何参数。 这是我的代码。我没有包括处理部分,因为它很长。

int main(int argc, char *argv[])
{
// Some processings//
// Create the thread
cv::namedWindow("image2D");
std::thread t1(task1, "Start");
t1.join();
}
void task1(std::string msg)
{
std::cout  << "Task 1: " << msg << std::endl;    
// Some processings to compute img1
// Display img1
float min = -50;
float max = 100;
cv::Mat adjMap = cv::Mat::zeros(height, width, CV_8UC1);
cv::Mat img1;
float scale = 255.0 / (max - min);
zw.convertTo(adjMap, CV_8UC1, scale);
applyColorMap(adjMap, img1, cv::COLORMAP_JET);
cv::imshow("image2D", img1); // The code hangs here
cv::waitKey(1);
}