Not able to create separate image for each input image.

asked 2018-12-04 05:23:09 -0500

updated 2018-12-04 05:23:44 -0500

I'm able to achieve the desired result of converting every image into black & green but output is over writing the same file instead of creating a separate file for each corresponding image

from glob import glob
for fn in glob('camera/*.jpg'):
    img = cv2.imread(fn)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, (50, 50, 50), (70, 255,255))
    imask = mask>0
    green = np.zeros_like(img, np.uint8)
    green[imask] = img[imask]
    cv2.imwrite("*.jpg", green)
    ch = cv2.waitKey()
    if ch == 100:
        break
    cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

I don't understand :

cv2.imwrite("*.jpg", green)

*.jpg is forbidden on windows and linux?

cv2.waitKey() without an imshow does not work

You must process string fn to give a good name for your file :

name = "myImage"+str(idx)+".jpg"
cv2.imwrite(name, green)
idx += 1
LBerger gravatar imageLBerger ( 2018-12-04 08:15:55 -0500 )edit