C ++显示图像并保持图像直到下一张图像的最佳方式

时间:2017-04-10 18:16:28

标签: c++ opencv

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

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

2 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:1)

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

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);
}
相关问题