destroyWindow() Function in OpenCV Python

The cv2.DestroyWindow() function in OpenCV is used to shut a specific window created the use of OpenCV. When running with pics or videos, you may want to open more than one show home windows, and this characteristic allows you to shut a specific window by way of specifying its name. This is especially useful for coping with assets successfully during image processing tasks.

How to use destroyWindow() Function in OpenCV Python

Step 1: This step imports the OpenCV library, that is critical for acting image processing obligations. OpenCV presents features for displaying, editing, and dealing with picture-associated home windows.

import cv2

Step 2: Here, the cv2.Imread() characteristic loads the image into reminiscence, and cv2.Imshow() displays the picture in a window named “Display Window”. This creates a graphical interface to visualise the photo.

image = cv2.imread('example.jpg')
cv2.imshow('Display Window', image)

Step 3: The program pauses execution and waits indefinitely for the user to press any key. This guarantees the window remains open till the user makes a decision to shut it.

cv2.waitKey(0)

Step 4: This function closes the window with the call “Display Window”. It is useful while you simplest want to shut one unique window in place of all OpenCV-created home windows.

cv2.destroyWindow('Display Window')

Output

The program will display the image in a window named "Display Window". Once you press a key, only this specific window will be closed while other OpenCV windows, if any, remain open.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top