We need to use opencv to read images in batches. I thought it was a few simple lines of code. I didn't expect a small error to keep the image invisible. The window can be displayed but the image is displayed.
I used iplimage, and some people used cvmat to check their differences. iplimage was derived from cvmat, and I did not go into details.
Vs2008 how to add opencv library, how to add header files I will not talk about, directly paste code, the program is very short, but I did not realize a place, the image file name cannot be displayed. The single slash of the image file name path must be replaced with a double slash, I also don't know whether it is what opencv requires. In short, pay attention to it later.
There are no special header files. The for loop achieves dynamic file names and window names. Do not forget to release the memory at last. Otherwise, the memory will crash when the number of images is read.
Int I; char windowname [100]; // display window name // read images in batches in a loop (I = 0; I <2; I ++) {// pass the dynamic file name sprintf_s (filename, "F :\\ opencv_programs \ 20130716 \ 20130716 \ trainningimg \ trainningimgw.d.jpg", I) to filename; sprintf_s (windowname, "IMG % d", I); // The cvloadimage function reads the image iplimage * IMG = cvloadimage (filename); cvnamedwindow (windowname, cv_window_autosize ); // The cvshowimage function displays the image cvshowimage (windowname, IMG); cvwaitkey (0); // when the number of images is large, the memory cvreleaseimage (& IMG) should be released; cvdestroywindow (windowname );}