这个opencv程序用于同时从一个文件夹中加载不同的图像,但它只读取一个图像

This opencv program is for loading different images from a folder at the same time, but it reads only one image

本文关键字:图像 一个 opencv 读取 加载 用于 程序 这个 文件夹      更新时间:2023-10-16

这个OpenCV程序用于同时从文件夹中加载不同的图像。但它只读取一张图像,请帮助我找到这里发生的事情。

 #include <stdio.h>
    #include <stdlib.h>
    #include <dirent.h>
    #include<cv.h>
    #include<highgui.h>
    using namespace std;
    using namespace cv;
    int main(int argc, char *argv[])
    {
       struct dirent *dirpent;
       DIR *dirp;
       IplImage* image;
       if(argc!=2)
       {
       printf("Cant continue with the programn");
       return 0;
       }
       dirp= opendir(argv[1]);
       if(dirp==NULL)
            {
                cout<<"error"<<endl;
            }
           while(dirpent=readdir(dirp))
           {    
            char *b=dirpent->d_name;
             if(b[0]=='.')
              {
              }
            else
             {
                image=(IplImage*)cvLoadImage(dirpent->d_name);
                cvNamedWindow("output");
                cvShowImage("output",image);
                cvWaitKey(0);
                cvReleaseImage(&image);
                cvDestroyWindow("output");  
            }        
          }
 closedir(dirp);
   return 0;
   }
尝试将

以下行移出(之后)while -scope:

cvReleaseImage(&image);
cvDestroyWindow("output");  

并将以下行移动到 while -scope 之前,因为您不需要每次都创建窗口。

cvNamedWindow("output");