0

What would be a good way to store multiple images loaded using OpenCV in Python? In C++ it can be simply done using vector of Mat's.

How to do it in Python? Buil in arrays AFAIK are suitable only for simple data. Should I use some vector or something like that library?

2
  • 2
    a C++ vector and a python list are very very similar. Commented Feb 11, 2013 at 23:54
  • 2
    @BostonJohn: A C++ vector stores copies of its elements, a Python list stores references. Commented Feb 12, 2013 at 0:06

2 Answers 2

1

When I am working with OpenCV my choice is to use numpy ndarrays. It is fast and easy convert back and forth between numpy arrays and OpenCV Image/Matrix classes, only a thin wrapper is needed, and numpy provides you with a ton of numerical tricks and libraries to use.

That being said, there would be nothing wrong with simply using lists of cv's native iplimage class (a structure inherited from intel image processing library).

Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure what you're asking. What would be wrong with making a user specified object Image like this:

from opencv.cv import *
class Image:
    def __init__(self, file):
        image = cvLoadImage (file)
        # whatever else you may need to store or do


list = []
someImg = Image("C:/somefile.png")
list.append(someImg)

and then storing those in a list? That's how I would do it in your situation, but I may be mis-interpreting the specifics of your question.

Edit: I also haven't really used OpenCV in python, so I'm not sure how the imports and image creation works, but it appears to be something like this. Reference: here or here

Also, the numpy.ndarray is a good one, since you seem to be referring to using a vector (here python list) of matrices (here numpy.ndarrays), which you may be more comfortable with.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.