0

Using openCV I imported 4 direction images and called them (L, R, U, D), represented by arrays in uint8 format.

I created a function that generates a random sequence of arrows in list form, Arrow_Seq. This consists of n uint8 arrays.

Now I want to save files with names that makes sense as I will be saving a few thousand of these image files.

To concatenate the sequence I'm using:

 Arrow_Seq[i] = np.hstack(Arr_Seq)

To save each sequence I've used:

cv2.imwrite('ArrSeq_' + str(i) + '.png', Arrow_Seq[i])

That enables me to save each file in numerical order which is not helpful as it doesn't help me identify which arrow sequence the file has inside it.

How do I save files so they are denoted something like: LUURRD.png? That tells me the sequence is Left, Up, Up, Right, Right, Down.

I assume I need to generate a variable that lists the variables inside of Arrow_Seq? If so that's where I'm having trouble - pulling out those elements just gives me the uint8 array of values and not the name of the variable direction being represented.

bsils
  • 25
  • 6
  • Why not add an attribute to the class (you're using classes, right?) that contains the letter for that image. And then store the letter in the initializer and access it on save. – Ignacio Vazquez-Abrams Mar 14 '15 at 22:05
  • I'd imagine you could build that part of the filename in the same loop that you build `Arr_Seq` -- e.g. `i=random.randint(0,3); Arr_Seq.append(arrows[i]); nameinfo += "LRUD"[i]` – jedwards Mar 14 '15 at 22:11
  • @IgnacioVazquez-Abrams I wasn't using classes, perhaps I can look into that. I'm still in the learning stage of python so I'm sure there is much that is inefficient in my overall approach! – bsils Mar 14 '15 at 22:15
  • When I use the class strategy: `class Direction: def __init__(self, array, dir_name): self.array = array self.dir_name = dir_name` and set say L = Direction(L, "L") and so forth... when I then let the previous code process I get an error when attempting to save the files using cv2.imwrite: TypeError: img data type = 17 is not supported – bsils Mar 14 '15 at 23:31

0 Answers0