Saving output image from code into the system without taking screenshot in python

Viewed 103

So I am trying to save the output of the edge detection code directly into my system without taking the screenshot of the output. The code is displayed below: `

#edge
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image 
import PIL 

img = cv2.imread(r'C:\Users\Nampoothiri\OneDrive\Desktop\New folder\Girrafe.jpg', 0)
edges = cv2.Canny(img,100,200)


plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

`

I want to save the output output of the edge detection directly into the system and then open the image using tkinter. This is my final aim. So is there a way to do that?

3 Answers

To save image, you can use cv2.imwrite().

cv2.imwrite('edges.jpg', edges)
Related