Freeing Ram by deleting image matrix

asked 2016-02-15 11:30:52 -0500

Dr Dre gravatar image

I have a simple code

import cv2
import numpy as np

Image = cv2.imread('blue.jpg')

Threshold = np.zeros(Image.shape, np.uint8) 
cv2.threshold(Image, 121, 255,   cv2.THRESH_BINARY, Threshold) 
cv2.imshow("WindowName", Threshold )


I want to delete matrix

"Image" from memeory i.e clear memory to save space in ram

How can i acheive this

edit retag flag offensive close merge delete


Why do you want to do it manually? Just let it go out of scope and python will clean up for you.

FooBar gravatar imageFooBar ( 2016-02-15 13:07:38 -0500 )edit

what if i want to delete it manually . What syntax shalll i use

Dr Dre gravatar imageDr Dre ( 2016-02-15 18:47:41 -0500 )edit

Just call deallocate(). That will empty the data from the Mat, but there will be a tiny amount of overhead. This does what you want though.

Tetragramm gravatar imageTetragramm ( 2016-02-15 20:38:45 -0500 )edit

Is there a deallocate in python?

FooBar gravatar imageFooBar ( 2016-02-16 08:21:40 -0500 )edit