Open Multiple Images with OpenCV in Python

Building on our previous example of opening a single image, this guide will explain how to open multiple images. The easiest way to load multiple images is to put all the images into a single folder and loop through the directory opening each one.

This guide doesn’t introduce any new OpenCV functions you shouldn’t already be familiar with from the previous example, but we will include new packages os and os.path to make a list of images to process.

The code

A note on OpenCV image support from the OpenCV docs (http://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html)

Note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 – codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png). Furthermore, OpenEXR is also a possibility.

Boilerplate code

 

  • Ayesha Jabeen

    my question is that if user select img from directory we print the path of that img how can we save that path in variable and use any where that path in oour code