我想在不同的窗口中多次显示相同的图像,我已经使用了for循环,但我只得到一个窗口显示。任何人都可以提供有关如何在多个窗口中显示输出图像的任何建议吗?以下是使用C API的OpenCV中的代码。在这里,我只是从argv [1]加载图像并尝试在4个不同的窗口中显示它。
#include "cv.h"
#include "highgui.h"
#include <stdlib.h>
#include <stdio.h>
int main( int argc, char** argv ) {
int i;
IplImage* img = cvLoadImage( argv[1],1);
cvMoveWindow("Example1", 100, 100);
cvNamedWindow( "Example1", 1);
for(i =0; i<=4;i++) // for loop to display the same image in 4 different windows
{
cvShowImage( "Example1", img );
}
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
P.S。我问了一个类似的问题show multiple images in different window in OpenCV之前没有解决,代码很难理解,所以我用一个更简单的代码来尝试这个问题。
答案 0 :(得分:1)
for(i =0; i<=4;i++) // hmm, i<=4 will actually run 5 times ...
{
cvShowImage( "Example1", img ); // <-- same window name for all == only 1 shown
}
但是,请丢弃c api并使用c ++! 请!
#include "opencv2/opencv.hpp"
int main( int argc, char** argv ) {
cv::Mat img = cv::imread( argv[1],1);
for( int i=0; i<4; i++ ) // for loop to display the same image in 4 different windows
{
cv::String name = cv::format("Example%d",i);
cv::namedWindow( name, 1);
cv::imshow( name, img );
}
cv::waitKey(0);
}
答案 1 :(得分:1)
你去吧
int i;
IplImage* img = cvLoadImage("/home/khashayar/Downloads/bug14.png", 1);
cvMoveWindow("Example1", 100, 100);
cvNamedWindow("Example1", 1);
for (i = 0; i <= 4; i++)
{
char str[5] = "test";
str[4] = i+48;
cvShowImage(str, img);
}
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1");