Opencv for batch image reading

Source: Internet
Author: User

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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.