'How to write pre processed image

#Read the image

img = cv2.imread('../input/jagan-ap/AP CM Jagan Mohan Reddy approves....jpg')

#Pre processed the image. (Done pre-processing)

#Then I want to write this image into output directory of the Kaggle, tried below options but no use:

1    img.fromarray(roi_color).save('./output/')

2    cv2.imwrite('./output/',img)

3    plt.imsave(img, 'saveName.jpg')

Kindly suggest any other solution.



Solution 1:[1]

As you used OpenCV to open the image and you already have that as a dependency, there's little reason to suddenly introduce PIL or matplotlib as further deoendencies as in 1) and 3). Furthermore, your colours will be wrong because OpenCV uses BGR ordering and the others use RGB.

So, let's look at 2). If output is a directory, that can't work. You need to write to a file, so try:

cv2.imwrite('output/result.png',img)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Setchell