3

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 Answers3

4
from matplotlib import pyplot as plt

plt.savefig('foo.png')

Link: https://stackoverflow.com/a/9890599/15308682

Ordinata
  • 96
  • 2
3

Have you tried plt.savefig? Documentation: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html

boxhot
  • 189
  • 5
1

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

cv2.imwrite('edges.jpg', edges)
Norbert Tiborcz
  • 306
  • 2
  • 9