How to loop over all the images using openCV 3.0.0 and C++?
i want to loop over my images that saved on my working folder and apply in all of them a converter to gray and then to equalized. I have the code but just for one image and I want it for 50 images.
Here is the code:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = imread("user2-6.jpg", CV_LOAD_IMAGE_COLOR);
if (!image.data)
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
// Create a new matrix to hold the gray image
Mat gray;
// convert RGB image to gray
cvtColor(image, gray, CV_BGR2GRAY);
namedWindow("Display window", CV_WINDOW_AUTOSIZE);
imshow("Display window", image);
namedWindow("Result window", CV_WINDOW_AUTOSIZE);
imshow("Result window", gray);
Mat img = imread("user2-6.jpg", CV_LOAD_IMAGE_COLOR); //open and read the image
if (img.empty())
{
cout << "Image cannot be loaded..!!" << endl;
return -1;
}
cvtColor(img, img, CV_BGR2GRAY); //change the color image to grayscale image
Mat img_hist_equalized;
equalizeHist(img, img_hist_equalized); //equalize the histogram
//create windows
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
namedWindow("Histogram Equalized", CV_WINDOW_AUTOSIZE);
//show the image
imshow("Original Image", img);
imshow("Histogram Equalized", img_hist_equalized);
waitKey(0); //wait for key press
destroyAllWindows(); //destroy all open windows
return 0;
}