OPENCV batch image reading method

  • 2020-05-24 05:55:03
  • OfStack

As follows:


#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
  int num=4;// The number of pictures read; 
  char filename[100];
  char windowname[100];
  IplImage* pScr;
  unsigned char *Readfigsmethod1(int num);//  Read in num A picture 

  {
    for (int i = 1; i <= num; i++)
    {
      sprintf(filename, "C:/Users/hsy/Desktop/ grapes /%d.jpg", i);//  Name the image after a number: for example 1.jpg 2.jpg And so on, into the D:/test/ folder 
      sprintf(windowname, "window%d grapes .jpg", i);
      cvNamedWindow(windowname, CV_WINDOW_AUTOSIZE);
      pScr = cvLoadImage(filename, 1);// Import images 
      cvShowImage(windowname, pScr);// Display images 
    }
    cvWaitKey(0);
    cvReleaseImage(&pScr);// Release the image 
    cvDestroyAllWindows();// Destruction of the window 

    return 0;
  }
}

Note: the main problem with continuous image reading is that filename points to the image directory, sprintf(filename,"D:/test/% d.jpg ",i) can be used to make
filename can run from 1.jpg, 2.jpg,1 to num.jpg.filename =D: /test/ i.jpg.


Related articles: