Ask Your Question
1

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 )

cv2.waitKey(0) 
cv2.destroyAllWindows()

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

Comments

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

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-11-13 04:41:58 -0500

i tried something like this

import cv2
import numpy as np

Image = np.zeros((20000,20000), np.uint8) 

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

cv2.waitKey(0)
Image = np.zeros((1,1), np.uint8)
Threshold = np.zeros((1,1), np.uint8)
cv2.imshow("WindowName", Threshold )

cv2.waitKey(0)
cv2.destroyAllWindows()
edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 1,424 times

Last updated: Feb 15 '16