-2

I am trying to write image in my opencv code, which is fine if i write without directory. But when I am trying to write in directory, it run but does not write in directory.

for i in xrange(3):
    path = 'resultImages/result'
    print os.path.join(path,str(i),'.png')
    cv.imwrite(os.path.join(path,str(i),'.png'),images[i*3+2])

Anything wrong here?

I reffered OpenCV - Saving images to a particular folder of choice but no help.

user2129623
  • 2,167
  • 3
  • 35
  • 64
  • if resultImages is inside the directory where the images are automatically saved, try putting '/' in front of resultImages ('/resultImages/result') – murksiuke Oct 23 '18 at 11:02
  • 1
    Make sure you dirpath exists. – Kinght 金 Oct 23 '18 at 11:05
  • @Silencer: dir path is there, and also tried with `('/resultImages/result')` but no luck – user2129623 Oct 23 '18 at 11:07
  • 1
    did you try using the full path? 'D:/..../result' – murksiuke Oct 23 '18 at 11:12
  • try using `os.path.exists(path)` to check if the path exists... also `os.path.join(path,str(i),'.png')` this should give something like `resultImages/result/0/.png` and it should be something like `os.path.join(path,str(i)+'.png')` – api55 Oct 23 '18 at 11:29

1 Answers1

0

The problem is due to the fact you are using ".png" as a sub directory inside the os.path.join() function

Try changing it to this:

for i in xrange(3):
    path = 'resultImages/result'
    print os.path.join(path,str(i) + '.png')
    cv.imwrite(os.path.join(path,str(i) +'.png'),images[i*3+2])

I hope it helped

Guilherme Uzeda
  • 216
  • 2
  • 11