Trending November 2023 # How To Work Background Subtraction In Opencv # Suggested December 2023 # Top 14 Popular

You are reading the article How To Work Background Subtraction In Opencv updated in November 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 How To Work Background Subtraction In Opencv

Introduction to OpenCV Background Subtraction

The process of removing the background from a given image and displaying only the foreground objects is called background subtraction in OpenCV, and to perform the operation of background subtraction, we make use of three algorithms, namely BackgroundSubtractorMOG, BackgroundSubtractorMOG2, and BackgroundSubtractorGMG and in order to implement any of these algorithms on a given image, we have to create the corresponding object of the algorithm and then make use of backgroundsubtractor.apply() function on the image to subtract the background from the foreground in a given image and backgroundsubtractor.apply() function returns an image with only the foreground objects in the given image.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax to implement the BackgroundSubtractorMOG algorithm to perform background subtraction in OpenCV is as follows:

object = bgsegm.createBackgroundSubtractorMOG() background_subtracted_image = object.apply(source_image)

The syntax to implement the BackgroundSubtractorMOG2 algorithm to perform background subtraction in OpenCV is as follows:

object1 = createBackgroundSubtractorMOG2() background_subtracted_image = object1.apply(source_image)

source_image is the image whose background is to be subtracted from the foreground.

The syntax to implement the BackgroundSubtractorGMG algorithm to perform background subtraction in OpenCV is as follows:

object2 = bgsegm.createBackgroundSubtractorGMG() background_subtracted_image = object2.apply(source_image)

source_image is the image whose background is to be subtracted from the foreground.

How to work background subtraction in OpenCV?

Working of background subtraction in OpenCV is as follows:

The process of separating the background from the foreground objects is called Background subtraction in OpenCV.

Three algorithms that can be used to perform background subtraction in OpenCV are BackgroundSubtractorMOG algorithm, BackgroundSubtractorMOG2 algorithm, and BackgroundSubtractorGMG algorithm.

The algorithms work by looping through all the pixels in a given image.

If the pixels in the image match the threshold associated with the algorithms, then they are classified as match components; otherwise, they are classified as non-match components.

The non-matching components are declared as background in the image by the algorithm and is removed from the image.

To implement any of these algorithms to perform background subtraction of a given image, the object of the corresponding algorithm must be created.

Then using the object of the corresponding algorithm, apply() function must be used.

The backgroundsubtractor,apply() function removes the background from the image and returns the image with only the foreground object.

Examples Example #1

OpenCV program in Python to perform background subtraction on a given video by implementing the BackgroundSubtractorMOG algorithm and then displaying the background-subtracted images as the output on the screen:

#importing the required module import cv2 #reading the video whose background is to be subtracted using BackgroundSubtractorMOG algorithm videoread = cv2.VideoCapture('C:/Users/admin/Desktop/images/sports.mp4') #implementing BackgroundSubtractorMOG algorithm by creating an object of the algorithm object1 = cv2.bgsegm.createBackgroundSubtractorMOG(); while(1): #reading the individual frames from the video ret, imageframe = videoread.read() #using backgroundsubtractor.apply() function to remove the background from the frame bg_subtracted_video = object1.apply(imageframe); #displaying the background subtracted video as the output on the screen cv2.imshow('BackgroundSubtractorMOG', bg_subtracted_video); cv2.waitKey(0) videoread.release() cv2.destroyAllWindows()

The output of the given program is shown in the snapshot below:

In the above program, we are importing the required modules. Then we read the video whose background is to be subtracted using the BackgroundSubtractorMOG algorithm. Then we are implementing the BackgroundSubtractorMOG algorithm by creating an object of the algorithm. Then we are reading the individual frames from the video. Then we are using backgroundsubtractor.apply() function to remove the background from the frame. Then we display the background-subtracted video as the output on the screen.

Example #2

OpenCV program in Python to perform background subtraction on a given video by implementing the BackgroundSubtractorMOG2 algorithm and then displaying the background-subtracted images as the output on the screen:

#importing the required module import cv2 #reading the video whose background is to be subtracted using BackgroundSubtractorMOG2 algorithm videoread = cv2.VideoCapture('C:/Users/admin/Desktop/images/sports.mp4') #implementing BackgroundSubtractorMOG2 algorithm by creating an object of the algorithm object1 = cv2.createBackgroundSubtractorMOG2(); while(1): #reading the individual frames from the video ret, imageframe = videoread.read() #using backgroundsubtractor.apply() function to remove the background from the frame bg_subtracted_video = object1.apply(imageframe); #displaying the background subtracted video as the output on the screen cv2.imshow('BackgroundSubtractorMOG2', bg_subtracted_video); cv2.waitKey(0) videoread.release() cv2.destroyAllWindows()

The output of the given program is shown in the snapshot below:

In the above program, we are importing the required modules. Then we read the video whose background is to be subtracted using the BackgroundSubtractorMOG2 algorithm. Then we implement the BackgroundSubtractorMOG2 algorithm by creating an object of the algorithm. Then we are reading the individual frames from the video. Then we are using backgroundsubtractor.apply() function to remove the background from the frame. Then we display the background-subtracted video as the output on the screen.

Example #3

OpenCV program in Python to perform background subtraction on a given video by implementing the BackgroundSubtractorGMG algorithm and then displaying the background-subtracted images as the output on the screen:

#importing the required module import cv2 #reading the video whose background is to be subtracted using BackgroundSubtractorGMG algorithm videoread = cv2.VideoCapture('C:/Users/admin/Desktop/images/sports.mp4') #implementing BackgroundSubtractorGMG algorithm by creating an object of the algorithm object1 = cv2.bgsegm.createBackgroundSubtractorGMG(); while(1): #reading the individual frames from the video ret, imageframe = videoread.read() #using backgroundsubtractor.apply() function to remove the background from the frame bg_subtracted_video = object1.apply(imageframe); #displaying the background subtracted video as the output on the screen cv2.imshow('BackgroundSubtractorGMG', bg_subtracted_video); cv2.waitKey(0) videoread.release() cv2.destroyAllWindows()

The output of the given program is shown in the snapshot below:

In the above program, we are importing the required modules. Then we read the video whose background is to be subtracted using the BackgroundSubtractorGMG algorithm. Then we implement the BackgroundSubtractorGMG algorithm by creating an object of the algorithm. Then we are reading the individual frames from the video. Then we use using background subtractor. apply the () function to remove the background from the frame. Then we display the background-subtracted video as the output on the screen.

Conclusion

In this article, we have learned the concept of Background Subtraction by implementing BackgroundSubtractorMOG, BackgroundSubtractorMOG2, and BackgroundSubtractorGMG algorithms with corresponding programming examples and their outputs to demonstrate them.

Recommended Articles

We hope that this EDUCBA information on “OpenCV Background Subtraction” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading How To Work Background Subtraction In Opencv

How To Change The Background In Microsoft Teams

Microsoft Teams, like Zoom, allows you to make video calls among devices and hold virtual meetings. The app is particularly useful for remote teams to hold meetings when co-workers are spread across different locations.

The background effects in Microsoft Teams allow you to remove the distractions of what’s happening around you in a video call and present a professional image. Plus, the feature helps others in the meeting focus on what you’re saying, not the strange object behind your shoulder.

Table of Contents

Whether you want an office environment, a tastefully decorated room, or a silly background, we’ll show you how to change the background in Teams.

How to Change the Background on a Computer or Mobile Device

You can change the background in a Teams meeting before joining or during the meeting. Teams lets you blur, select a pre-made image like a tranquil park or upload a custom image like your company logo as your background. You should know that changing your background may not hide sensitive information like your name or phone number from other people in the call or meeting.

How to Change the Background on a Computer

If you have a Windows PC or Mac, use the steps below to change the background on your computer.

How to Change the Background Before a Meeting Starts

You can change the background in Teams before a meeting starts to avoid interruptions.

Select Background filters just below the video image in the same window while choosing your audio and video settings.

You’ll see the background options on the right side of the screen.

Select Blur to subtly conceal everything around you.

You can also select a pre-made image from the ones provided.

Select Add new and then choose the image (JPG, PNG or BMP) you want to upload from your computer to upload a custom image of your choice.

How to Change the Background in Teams During a Meeting

Follow the steps below to change the background if you’ve already joined a meeting. 

Select More actions from the meeting controls.

Select Apply background effects.

Select Blur or choose a pre-made image to replace your background.

Select Add new and upload a custom PNG, JPG or BMP image file from your computer.

Note: The new background you choose will apply in all your calls and meetings until you turn it off or change it again.

How to Turn Off Background Effects in Teams

Follow the steps below if you want to turn off the background effects in Teams.

Select the no background icon (circle within a rectangle)

Select Preview to see how your background looks without the effect. If satisfied, select Apply.

Note: If you’re a Linux user or use Teams via an optimized virtual desktop infrastructure, you won’t be able to use the background feature.

Change the Background in Teams on Android or iOS Devices

Here’s how to change the background from your Android device or iPhone.

How to Change the Background Before a Meeting Starts

Here’s how to do it on your mobile device.

Tap Background effects at the upper side of the screen, while setting up your audio and video preferences.

The background options will appear just below your picture.

Tap Blur to subtly conceal everything behind you.

You can also choose one of the available images.

Tap Add (+) to upload a custom PG, PNG or BMP image file from your device. 

Tap Done at the top to apply the background to your meeting.

How to Change the Background During a Meeting

Here’s how you can change the background during a meeting or call.

Tap More options from the call or meeting controls.

Tap Background effects and select a background or upload a custom image to be your background.

To turn off background effects just  tap on the no background icon (circle within a rectangle) to remove the virtual background.

Hide Your Mess During Meetings

When on a video call or meeting, you want to focus on the task at hand without worrying about whether other participants can see the mess behind you. With the background effects feature in Teams, you can add some professionalism or a little fun to video calls. 

How To Change The Desktop Background In Windows 11

Changing the desktop background on Windows 11 PC and laptops can give them the right personalized touch that you might be looking for on your device. However, we have seen many people struggle when it comes to changing the desktop background in Windows 11. So, if you are one of these users, this article should greatly help you.

In this in-depth guide, we have come up with various different ways to change the desktop background on Windows 11 PCs and laptops. Yes, you read that right! There are multiple ways that you can avail to change the desktop background on your Windows 11 PC or laptop. So, sit tight and check them out in the following sections right below.

Change Desktop Background in Windows 11

Now, changing the desktop background in Windows 11 can be fairly easy, although there are many different ways that you can use to perform the task on your PC or laptop. Below, you can find step-by-step guides on some of the most common ways to change the desktop background on your Windows 11 device.

You can use any one of the following methods to change the desktop background on your Windows 11 PC or laptop to set your favorite image, be it an anime character or a beautiful landscape image, as your desktop wallpaper in Windows 11.

1. Via Settings

The Settings app in Windows 11 is a settings hub on your PC or laptop via which you can change various system settings on your device. Other than allowing users to tweak system settings, it also allows them to personalize their devices by changing the desktop background.

Moreover, unlike the other methods mentioned in this article, this method lets you choose the type of desktop background. This essentially means that other than setting a preferred image as your desktop background, you can choose to set a slideshow of various images, images from Windows Spotlight, or even a solid color as your desktop background in Windows 11.

Now, with these in mind, let’s take a look at how you can use the Settings app on your PC or laptop to change the desktop background in Windows 11:

1. Use Windows + I to launch the Settings app on your Windows 11 PC or laptop.

Congratulations! You have successfully changed the desktop background in Windows 11 on your PC or laptop.

Solid Color, Slideshow, and Windows Spotlight as Desktop Background in Windows 11

In the case of the Solid color option, you will have to choose your preferred color that you want as the desktop background on your Windows 11 PC or laptop. Similarly, for the Slideshow option, you can choose multiple images from your library to create a slideshow and set it as the desktop background.

The Windows Spotlight option, on the other hand, does not require any personalization. It automatically cycles through pre-set images from Bing on the desktop background while you use your Windows 11 PC or laptop.

2. Via File Explorer in Windows 11

Another easy method that you can use to change the desktop background in Windows 11 is via File Explorer. However, it is worth noting that this method only works if you opt to set a specific picture as the desktop wallpaper on your PC or laptop.

This means that you will not get the option of slideshow, solid color, or Windows Spotlight in File Explorer. In fact, you will be able to select the said options only via the Personalization settings in the Settings app in Windows 11.

On that note, let’s take a look at the steps on how to change the desktop background in Windows 11 via File Explorer:

1. Use Windows + E to launch File Explorer on your Windows 11 PC or laptop.

2. Locate the image that you want to set as the desktop background.

That’s it! Your selected image will now be set as the desktop background on your Windows 11 PC or laptop.

1. Locate the image file on the desktop screen on your Windows 11 PC or laptop.

Following the above actions, the selected image will be set as the desktop background on your Windows 11 PC or laptop.

4. Via the Photos App in Windows 11

The Photos app is the default image-gallery app in Windows 11 that lets users manage their photos on their PCs and laptops. And much like the above-mentioned methods, the Photos app in Windows 11 can also help you change the desktop background on your PC or laptop.

Follow the steps right below to use the Photos to change the desktop background on your Windows 11 PC or laptop:

1. Locate the image that you want to set as the desktop background on your Windows 11, be it in File Explorer or on the desktop screen itself.

Note: You must set the Photos app as the default image-viewing application on your Windows 11 PC or laptop to open images using the said app.

4. On the drop-down menu, take the cursor to the Set as option.

Note: At this stage, you can also select the Lock Screen option to set the selected image as the Lock Screen background on your Windows 11 device.

6. Now, you can close the image and enjoy it as the desktop background on your Windows 11 PC or laptop.

5. Use Wallpaper Apps in Windows 11

Now, other the than methods discussed in this article, you can also use one of the various wallpaper apps that are available for Windows 11 PCs and laptops to change the desktop background.

There are a lot of options to choose from and you can check out some of the wallpaper applications via the Microsoft Store application on your Windows 11 PC or laptop.

While some of the wallpaper applications in Windows 11 offer high-quality wallpapers within the app themselves, others use third-party sources such as Bing, Unsplash, and Pexels to offer wallpapers for your PC or laptop. So, we’d recommend browsing through the wallpaper application on the Microsoft Store to see find your preferred one to change the dekstop background of your PC or laptop.

FAQs

What is a desktop background?

When we are talking about Windows PCs or laptops, a desktop background is essentially the wallpaper that appears on the Desktop screen. By default, it is set to a system or OEM wallpaper on Windows PCs and laptops.

How do I make my desktop background change automatically in Windows 11?

To make the desktop background or wallpaper change automatically on your Windows 11 PC or laptop, you can set your wallpaper as Slideshow or Windows Spotlight via the Settings app. In Slideshow, you can choose your own images to cycle through on the desktop, while in Windows Spotlight, you will get images from Bing.

What is the shortcut to change the desktop background in Windows 11?

There are no hotkeys to instantly change the desktop background in Windows 11. However, if you have an image opened in the Photos app on your Windows 11 PC or laptop, you can use the Ctrl + B shortcut to instantly set the selected/ opened image as the desktop background.

Wrapping Up

So, there you have it! This was all about how to change the desktop background in Windows 11. While there are multiple ways to set or change the desktop background on your Windows 11 PC or laptop, we think that changing the desktop background via the Settings app is the best option. 

This is mainly because you get multiple options like Slideshow and Windows Spotlight in the Settings app that you can utilize when changing your wallpaper. With the other methods, you can only set a specific image as the desktop background on your Windows 11 device.

How To Set Background Color Of A Particular Div In Jquery?

jQuery is a very popular and widely used JavaScript library used in the process of writing and manipulating HTML documents, handling events, and adding dynamic effects and animations to web pages. Sometimes we need to style a particular div in our web page but don’t know which method to use and how to use it.

The process of styling the div is very easy and setting the background color of a particular div element can be achieved with the help of jQuery. Its process includes selecting the particular div element with the help of selectors, and then applying the CSS styles to set the background color.

jQuery has various methods by which we can set the background color of any div element in HTML. In this article, we will see how we can set the background color of a particular div, along with the different approaches that can be used in jQuery.

Approaches to set background color of particular div

Setting the background color is a very simple task but being simple, there are many ways through which the same task can be done. Let’s now see some of the different ways through which we can do this −

Using CSS() Method

The CSS () method is a built-in method of jQuery that is used to set or get the value of any CSS property of an HTML element. This method can be used to set the background color of a particular div. To accomplish that, see the following syntax first −

Syntax $(document).ready(function() { $("#myDiv").css("background-color", "red"); }); Example

In this approach, we have used one of the jQuery methods called CSS () method which can be used set the background color of a particular div element having a specific ID. Below is the HTML code for the example −

#divNew { width: 300px; height: 200px; border: 1px solid green; } $(document).ready(function() { $(“#divNew”).css(“background-color”, “green”); });

In this example, we have used a div element having the ID “divNew” consisting of some CSS properties like width, height, and border defined in the CSS style. Here, we are going to use the jQuery selector that selects the div element with the ID “divNew” and set its background color to green using the jQuery css() method.

Using attr() Method

The attr() method is another jQuery method used to set the value of an attribute of an HTML element. We can use this method to set the background color of any particular div. To do this, we can set the “style” attribute of the div element to “background-color: green” (just for example). See the below syntax for more detail −

Syntax $(document).ready(function() { $("#myDiv").attr("style", "background-color: red"); }); Example

In this approach, we use the”style” attribute of the div to add any background color to the particular div element. Below is the HTML code for the example −

#divNew { width: 300px; height: 200px; border: 1px solid black; } .background { background-color: blue; } $(document).ready(function() { $(“#divNew”).attr(“style”, “background-color: pink”); });

In this example, we have created a div element with the ID “divNew” which has some properties like width, height, etc defined in the CSS style. Here, we are going to use one of the jQuery selectors that selects the div element having the ID “divNew” to set its “style” attribute to include the background color in the div element.

Using addClass() Method

The addClass() method is also a part of jQuery which is a built-in method used to add one or more CSS classes to an HTML element. This method can also be used for setting the background color of a particular div. To do that, we have to create a CSS class with the desired background color after which we can add it to the div element using the same method. See the following syntax −

Syntax $(document).ready(function() { .red-background { background-color: red; } $("#myDiv").addClass("red-background"); }); Example

In this approach, we are required to create a CSS class with a specific background color and then use the addClass() method to add the class to the particular div element. Below is the HTML code for the example −

#divNew { width: 300px; height: 200px; border: 1px solid green; } .background { background-color: blue; } $(document).ready(function() { $(“#divNew”).addClass(“background”); });

In this example, we have defined a CSS class with the name “background” to add our background color to add a div element. After creating the class, we can now add this class to the div element with the ID “divNew” using our jQuery addClass() method in the code.

Conclusion

jQuery gives users multiple ways to style, and add functionality to their HTML documents or pages. Setting the background color of a particular div in HTML is one such problem in which there are various ways to achieve the task. The CSS() method is the first method that we have seen in this article which can be used to set the background color of any div element by selecting the div with their ID. Second, the attr() method is also used to set the style attribute of the div element to add the background color. And the last method was the addClass() method which is also used to add the background color by creating a CSS class with the desired background color and adding it to the div element. Each method discussed in this article is easy to use and can help achieve the desired user interface on web pages.

An Introduction To Computer Vision With Opencv

This article was published as a part of the Data Science Blogathon

Introduction.

A Brief Introduction to Machine Learning.

An Introduction to OpenCV Library.

OpenCV Python Programming.

Source: GeeksCoders.

A Brief Introduction to Machine Learning.

Machine Learning is a trending field of Information Technology in present times. As can be inferred from the name, Machine Learning is a field in which Machines are trained and taught, exactly how to identify, detect, and recognize patterns in data- both structured and unstructured. Machine Learning lends itself to the modern-day in several aspects- from Medicine to Augmented Reality, to Artificial Intelligence, and more. There are different types or categories of Machine Learning, the most dominant types are:

Supervised Machine Learning.

Unsupervised Machine Learning.

Reinforcement Learning.

Source: TowardsDataScience.

The key aspect of each type is as follows:

Supervised Machine Learning will train a model using Labelled data.

Unsupervised Machine Learning will train a model using unlabelled data.

Reinforcement Learning teaches the model or agent, how to differentiate the right action from the wrong.

An Introduction to OpenCV Library.

OpenCV is a programming library/package that has been created especially for allowing programmers to enter the world of Computer Vision. The primary developer of the OpenCV package is Intel Corporation, and the package was released to the public during the year 1999-2000.

OpenCV stands for Open-Source Computer Vision (Library). It is the most commonly used, popular, and well-documented Computer Vision library. It is open-source, which means that one does not require a license to utilize the software.

As one may know, most Machine Learning Algorithms require inputs to be quantitative in nature, i.e., numerical. OpenCV allows us to apply Machine Learning techniques to images, however, oftentimes we are required to preprocess and prepare the raw images for them to be transformed into features (columns of data) that are useful and usable by our Machine Learning Algorithms.

Source: DataFlair.

OpenCV Python Programming.

We will now how to process an image with the OpenCV package in Python Programming Language. For this learning experience, we will use the OpenCV chúng tôi You may navigate to, and download the image at this link, or you may save the image found below.

Source: Wikipedia.

Loading an Image into System Memory.

To load an image into our system RAM (Random Access Memory), we are required to make use of the imread() method provided by OpenCV. We are aware that images are a source of data- images are sources of data, from which we can acquire information and infer patterns. The crucial point to note about the imread() method is that when we utilize it in our program, fundamentally our raw image is transformed into a data/object type that we are familiar with- i.e., it becomes a NumPy Array. First, let us load our image in GRAYSCALE colour mode, and explore from there.

import cv2 # load it in GRAYSCALE color mode... image = cv2.imread("""C:/Users/Shivek/Pictures/487px-OpenCV_Logo_with_text_svg_version.svg.png""", 0) cv2.imshow('Analytics Vidhya Computer Vision', image) cv2.waitKey(0) cv2.destroyAllWindows() We shall now examine the above lines of code. import cv2

If one is familiar with the Python Programming Language, one will understand that this is the standard syntax used to import dependencies/libraries/packages into the current script. In this line of code, we import all methods, operations, and functions that are offered by the Computer Vision library.

# load it in GRAYSCALE color mode... image = cv2.imread("""C:/Users/Shivek/Pictures/487px-OpenCV_Logo_with_text_svg_version.svg.png""", 0)

We thereafter load the image in grayscale color mode, and we do this using the imread() method. The imread() method takes in two primary arguments, viz., filename (of string datatype), and flag (of integer datatype). Please Note: you will be required to replace

C:/Users/Shivek/Pictures/487px-OpenCV_Logo_with_text_svg_version.svg.png

-with the location in which the image is stored on your computer. As one can see, I have passed in the filename and location of the image on my pc, and thereafter used a flag of 0. Flags are essentially predefined arguments that do not change, and are used as required- The flag 0 will load your image in the GRAYSCALE format- meaning black and white. Taken from the OpenCV Documentation, here are two flags you are most likely to use in your experience with OpenCV:

Hence, in our example, since we would like to obtain our image in GRAYSCALE format, we have used a value of 0, which corresponds to the predefined flag for IMREAD_GRAYSCALE.

cv2.imshow('Analytics Vidhya Computer Vision', image)

We make use of the imshow() method to display the image that has been loaded into memory, onto the digital display (screen). We need to understand that the imshow() is a very powerful OpenCV method because it creates a display for us- it will return a GUI Window to us, which contains our image that has been loaded into memory. This method requires two arguments- A title for the window to be displayed (containing the image); and the image itself- remember that an image may be stored in a variable- Hence, we are able to pass in the variable name containing our image- in our case the variable image.

The GRAYSCALE image output will be as follows:

cv2.waitKey(0)

You see, when the imshow() function displays the image output on our screen, the window that pops up with our image tends to disappear as soon as it shows up; this is because there is no signal or flag to prompt the window to be visible until or unless a specific action or event has occurred or passed. In situations like these, if you wish for the window to remain on the screen you will specify a parameter to the waitKey() function. This function will accept an integer value representing the number of milliseconds you would like the window to remain on your screen before the window is destroyed/terminated. The question you are likely to have in mind is: What should I do to make the window display on my screen for an infinite duration of time?

There are two solutions to this problem:

cv2.waitKey(0)

Pass a value of 0 to the waitKey() function. Zero is the predefined flag that will specify to the GUI system, to display the window for an infinite duration of time- to be precise- waitKey(0) will wait infinitely for terminating the image window. Termination is prompted when the user presses any character or directional key on the keyboard.

cv2.waitKey()

The default behaviour for the waitKey() function is to wait infinitely, i.e., display the window for an unlimited period of time. The name of the argument to which we are passing a value is delay. And the default line of syntax for the waitKey() function is as follows:

cv2.waitKey(delay=None)

And delay=None provides us with the same output as delay=0.

cv2.destroyAllWindows()

The above line of code will do as specified in the syntax- i.e., it will destroy all windows that have been created during our OpenCV session. If you would like to destroy/close a single, specific window- you may pass the name of the window as a string.

Source: DataDrivenInvestor.

Conclusion.

This concludes my article on Machine Learning: An Introduction to Computer Vision. I do hope that you have new OpenCV takeaways from this article.

Feel free to connect with me on LinkedIn.

Thank you for your time.

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.

Related

How Does Redirect Work In Javascript?

Introduction to JavaScript Redirect

JavaScript redirect is the process of sending requests form one page to another page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. location is the function used in JavaScript to redirect at the specific URL.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Real Time Scenario:

Advantage:

We can add more information within a single page by this URL redirect.

Pre-requisites:

Basic HTML

Basic JavaScript

How does Redirect Work in JavaScript?

JavaScript redirect is working based on different types of redirect methods. Each redirect has its own specification.

Syntax:

location = "URL";

Description: It will set the new location for the current window.

location.href = "URL";

Description: It will set the new href for the current window.

location.assign("URL");

Description: It will assign the new URL to the current window.

location.replace("URL");

Description: It will replace the current window location with a new location.

location = "URL";

Description: It will just set the current window location itself.

location = "URL";

Description: It will set the topmost window location with a current window location.

Note: The difference between href and replace method is replace() method removes the URL of the current document from the document history, means it is not possible to use the “back” button for navigating to the original document.

Examples of JavaScript Redirect

Given below are the examples mentioned:

Example #1

Window location URL.

h1 { text-align: center; color: green; } p { font-size: 28px; border: solid 3px blue; color: maroon; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL window.location = url;

Output:

After few milliseconds (1sec) moved to URL:

Example #2

Window Location Redirect with Time Limit.

Code:

h1 { text-align: center; color: brown; } p { font-size: 28px; border: solid 3px red; color: green; } input { text-align: center; color: navy; } button { font-size: 22px; font-weight: bold; color: white; background: lightblue; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL Type URL :<input type=”text” name=”url” function getMyRedirectURL() { var url = document.getElementById(“urlID”).value; document.write(“It will redirect within 3 seconds…..please wait…”);//it will redirect after 3 seconds setTimeout(function() { window.location = url; }, 3000); }

Output:

Example #3

Replace Function URL.

Code:

h1 { text-align: center; color: navy; } p { font-size: 28px; border: double 2px teal; color: lime; } input { text-align: center; color: fuchsia; } .button { text-align: center; } button { font-size: 22px; font-weight: bold; color: white; background: red; } page to other page through accessing the corresponding URL (Unified Resource Locator). Redirecting URL is also used for sending the user from one URL to another URL. Window.location is the function used in website, while I am reading, I have some doubts with specific topics. Instead of providing everything there itself, we can simply summarize the topic and in between doubtable points can be provide with URL function getMyReplaceFun() { }

Output:

Recommended Articles

This is a guide to JavaScript Redirect. Here we discuss the introduction to JavaScript Redirect, working, and examples respectively. You may also have a look at the following articles to learn more –

Update the detailed information about How To Work Background Subtraction In Opencv on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!