简体   繁体   中英

Processing Only One Image Uses All of Ram

I am running this code in google colab (I also tried at my local). I use only one image and it uses all of the ram. Do I do something wrong? Is it normal to use 16 gb ram? I added %matplotlib inline and it still crashes?

import cv2
import matplotlib.pyplot as plt
import numpy as np 

f = cv2.imread('/content/gdrive/MyDrive/grass.png')
f = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY).astype(float)

plt.imshow(f)
plt.colorbar()

def gauss1(sigma, width):
    
    hwidth = round((width-1)/2)
    x = np.arange(-hwidth, hwidth+1,1)
    
    g = np.exp(-x**2/(2*sigma**2))
    return g/np.sum(g)
    
    
g1=gauss1(2,11)
g1=np.reshape(g1,(1,-1))
plt.imshow(g1)

f1 = cv2.filter2D(f,-1,g1)
fig = plt.figure(figsize=(10, 20))
fig.add_subplot(1,2,1)
plt.imshow(f)
fig.add_subplot(1,2,2)
plt.imshow(f1)

It does not even produce last code snippet's output.

Use:

  • If you're using terminal/console, use plt.show() to show the matplotlib output.
  • Use %matplotlib inline if you are using any ipython notebook kernel such as jupyter notebooks, google colab or kaggle notebooks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM