【问题标题】:I want to display output image in different windows in OpenCV我想在 OpenCV 的不同窗口中显示输出图像
【发布时间】:2013-07-25 07:32:39
【问题描述】:

我想在不同的窗口中多次显示相同的图像,为此我使用了 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" );
}

附:我曾问过类似的问题show multiple images in different window in OpenCV,之前没有解决,代码很难理解,所以我用更简单的代码尝试这个问题。

【问题讨论】:

  • 看到你的评论了!现在写代码;)

标签: c opencv image-processing


【解决方案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");

【讨论】:

  • 您的代码混合了 C 和 C++。它向我展示了很多错误
  • char str[5] = "test"; str[4] = i+48;
  • 它创建了一个 char* ,其中包含“test”和一个数字。要将数字放入char中,您应该使用他们的ascii代码,0的ascii代码是48。所以我们加上48的数字以获得我们想要的数字的正确ascii。它将导致 test0,test1, ...
  • 你知道如何以不同的名称保存相同的图像,因为我使用命令 cvSaveImage("out.ppm", dst); 在不同的窗口中显示如何更改“out.ppm”的名称,以便以不同的名称保存
  • 同样使用 char str[8] = "out"; str[3] = i+48; str[4] ='.'; str[5] ='p'; str[6] ='p'; str[7] ='m';
【解决方案2】:
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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    相关资源
    最近更新 更多