The role of destroyallWindows in OpenCV

Preface

Because I was learning OpenCV before, of course, there are many materials on the Internet, basically I am learning the wheels made by the predecessors. But I like to get to the bottom of the question. I have been writing the code and sometimes forget to write the destroyallWindos function. The code can also run normally, but I see that some reference codes have the sentence destroyallWindos at the end. I have some ideas, so I found some information. So I wrote an article to record it, I hope you can read it if you forget it later


One, look at the code first

import cv2
# 这里0.jpg是同目录下的一张图片
img = cv2.imread("0.jpg")
cv2.imshow("CHJ", img)
cv2.waitKey(0)

Such code can run, and will always wait for keyboard input, but there is no destroyallWindows

2. Online information

1. Stack Overflow's answer


You can take a look at the answer on stackoverflow

2. Official answer

This is the official link: Official document
English:
You can call destroyWindow() or destroyAllWindows() to close the window and de-allocate any associated memory usage. For a simple program, you do not really have to call these functions because all the resources and windows of the application are closed automatically by the operating system upon exit.
Baidu translation:
you can call destroyWindow() or destroyAllWindows() to close the window and deallocate any related memory usage. For a simple program, you don't actually need to call these functions, because the operating system will automatically close all resources and windows of the application when you exit


to sum up

If there is no previous operation to release the memory, destroyallWIndows will release the memory occupied by that variable


Guess you like

Origin blog.csdn.net/qq_45712772/article/details/109250148