Trending February 2024 # Working And Examples Of Typescript Enum # Suggested March 2024 # Top 7 Popular

You are reading the article Working And Examples Of Typescript Enum updated in February 2024 on the website Tai-facebook.edu.vn. 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 March 2024 Working And Examples Of Typescript Enum

Introduction to TypeScript enum

The new data type supported in TypeScript is called enumerations or enum using which lets us declare names which means a collection of related values which can be either string or numeric, and there are three types of enums in TypeScript, namely Numeric enum, string enum and Heterogeneous enum where numeric enum are the enums based on numbers that are they store numbers in the form of the string, string enum is the enums based on strings that is they store string values, heterogeneous enum are the enums based on both strings and numbers that is they store both string and numeric values.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

enum enum_name{ enum_value1, enum_value2, .. Enum_valuen }

where enum_name represents the name of the enum,

enum_value1, enum_value2, and enum_valuen represent the collection of related values, either string or numeric.

Working of enum in TypeScript

The new data type supported in TypeScript is called enumerations or enum using which lets us declare names which means a collection of related values that can be either string or numeric.

The keyword enum is used to define enum in TypeScript.

There are three types of enum in TypeScript, namely Numeric enum, string enum, and Heterogeneous enum.

Numeric enum is the enums based on numbers; they store numbers in the form of strings.

The enum values for numeric enum begin from zero and increase by one for each number.

There is also an option to initialize the first enum value ourselves in a numeric enum, and the rest of the values would be increased by one.

The enum values do not have to be in sequence in the numeric enum.

String enum is the enums based on strings that is they store string values.

The readability of the program increases by using a string enum.

Heterogeneous enum is the enums based on both strings and numbers; they store both string and numeric values.

Examples of TypeScript enum

Different examples are mentioned below:

Example #1

TypeScript program to demonstrate the usage of numeric enum that initializes values and are displayed as the output on the screen:

Code:

enum Country { India, USA, Germany, London } console.log("The values initialized by enum is as follows:"); console.log(Country.India); console.log(Country.USA); console.log(Country.Germany); console.log(Country.London);

Output:

In the above program, by using the keyword enum, we define a numeric enum whose values are initialized starting from zero and incremented by one for each member. Then the initialized values for the numeric enum are displayed as the output on the screen.

Example #2

TypeScript program to demonstrate the usage of numeric enum that initializes values where the first value is initialized by ourselves and are displayed as the output on the screen:

Code:

enum Country { India = 5, USA, Germany, London } console.log("The values initialized by enum is as follows:"); console.log(Country.India); console.log(Country.USA); console.log(Country.Germany); console.log(Country.London);

Output:

In the above program, by making use of the keyword enum, we are defining a numeric enum in which the first value is initialized as five by ourselves and then incremented by one for each member. Then the initialized values for the numeric enum are displayed as the output on the screen.

Example #3

TypeScript program to demonstrate the usage of string enum that initializes string values and are displayed as the output on the screen:

Code:

enum Capital { India = 'New Delhi', USA = 'Washington', Germany = 'Berlin', England = 'London' } console.log("The values initialized by string enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

Output:

In the above program, by using the keyword enum, we define a string enum whose values are initialized to certain string values. Then the initialized values for the string enum is displayed as the output on the screen.

Example #4

TypeScript program to demonstrate the usage of heterogeneous enum that initializes both string values and numeric values and are displayed as the output on the screen:

Code:

enum Capital { India = 1, USA = 'Washington', Germany = 3, England = 'London' } console.log("The values initialized by heterogeneous enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

In the above program, by using the keyword enum, we define a heterogeneous enum whose values are initialized to certain string values and certain numeric values. Then the initialized values for the heterogeneous enum is displayed as the output on the screen.

Example #5

TypeScript program to demonstrate the usage of heterogeneous enum that initializes both string values and numeric values and are displayed as the output on the screen:

Code:

enum Capital { India = 8, USA = 12, Germany = 'Berlin', England = 'London' } console.log("The values initialized by heterogeneous enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

Output:

In the above program, by using the keyword enum, we define a heterogeneous enum whose values are initialized to certain string values and certain numeric values. Then the initialized values for the heterogeneous enum is displayed as the output on the screen.

Recommended Articles

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

You're reading Working And Examples Of Typescript Enum

Syntax And Examples Of Teradata Qualify

Introduction to Teradata Qualify

Hadoop, Data Science, Statistics & others

is considered and accordingly on top of it an analytical function can be covered, with correspondence to this analytical function if filtration is expected to happen then QUALIFY clause can be used. Moreover, the QUALIFY clause is very closely related to the HAVING clause with the only major difference is that for qualify the analytical function will be expected by default. Whereas in the case of HAVING clause the qualify will not be expected. Functionalities like these bring a large extent of flexibility in data level segregation and sophisticated data reporting using high-capability systems like Teradata. So as mentioned before whenever there will also need to apply the filter process over an analytical-based output then the qualifying clause is the best element for use.

Syntax of Teradata Qualify

QUALIFY Search_condition

Syntax 

Specifies

QUALIFY The statement of Qualify process is achieved by means of this QUALIFY statement. As notified before this statement is very closely related to the HAVING clause. For the case of an HAVING clause the HAVING clause will be placed without the analytical function being covered up but In this case of the QUALIFY clause the QUALIFY clause is used along with the analytical function output.

search_condition This belongs to the search condition which is expected to be set by the search rows.

 Key Points on Qualify

This is compliant with ANSI standard

The search conditions which involve the Qualify clause cannot imply a Large object column. So, the process of Qualify cannot be applied on columns that involve these LOB. This applies to any type of LOB’s like CLOB or BLOB or even other LOB’s.

As explained in the conditions above mentioning the QUALIFY clause must by default involve an analytical or a statistical function associated with it. The analytical or the statistical function must be associated with any of the positions in the latter part of the query.

When any security constraints are mentioned in the query which involves a QUALIFY clause then it is very important to ensure encoding in place. This means whenever a row-level constraint is in place then accordingly it needs to be ensured and maintained strictly within an encoded format.

It is mandatory to have a column-level specification active so this can be specified without a default argument. So, mentioning the built-in function allows the arguments handled at the level of the column to operate with a predicate to be involved.

Sampling is another important process for selecting some specific records from the bucket of available values. This is achieved by means of the SAMPLE clause. By unfortunately the usage of the DEFAULT clause does not allow the sophisticated use of the QUALIFY clause along with it. It is obligatory to have a column-level condition dynamic so this can be quantified without an avoidance argument. So, citing the built-in function consents the arguments handled in the level of the column to operate with a predicate to be involved.

Examples of Teradata Qualify Example #1

Here in the below given example a test table called Qualify_test is created. The created table is inserted with a large set of records, around 10 records are been inserted. The inserted records are a combination of ID, Name, and AGE. Then these records printed onto the console using the Select statement. From there on the created records are then printed based on the QUALIFY statement. In the Qualify-based print, the records are initially ranked using the RANK function. Then the RANK function is also additionally listed with the condition that to list all the records with AGE values that are greater than the 3rd RANK. So the least age records form the 1st RANK, the Next set forms the 2nd RANK, and the next set forms the 3rd RANK, and the next and goes on. The Query used here takes the records which are equal and greater than RANK 3 and displays them on the console.

Query:

SELECT * FROM EDUCBA.QUALIFY_TEST;

Output:

Example #2

Query:

Output:

Conclusion

Filtering records provides the flexibility to pick the needed records alone from the databases. So, options like these provide the flexibility to pick the needed records alone from the huge set of data available. Moreover, the QUALIFY clause performs upon the analytic function such as RANK, COUNT, SUM, or even any further kind of analytic function that can be flexibly applied on top of this. Functionalities like these bring a large extent of flexibility in data level using high capability systems like Teradata. So as mentioned before whenever there will also be a need to apply the filter process over an analytical based output then the qualifying clause is the best element for use.

Recommended Articles

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

3 Great Examples Of Ugc Video Campaigns

“So now all we need is a load of people with cameras to tell everyone else how great our product is…”

Regardless of who did it first, what I love about both pieces (Coke and Sainsbury’s) is the use of real people, simply being alive and honest, no script, no plot and no director – just ad-lib fun in front of the camera.

All on behalf of a brand, all aiding the brands to tell a real and true story about themselves by way of persona association (with real humans), without the need for contrived scripts, storyboards and of course interruptive marketing messages.

Brand Storytelling

As with every digital marketing buzzword nowadays, someone creates a phrase in a blog, then everyone (me included!) takes the ball and runs with it and oh wow, ‘brand storytelling’ is without doubt, one of those phrases. But what is it and is the concept in any way innovative in today’s marketing?

Whilst I fully accept that brand storytelling means very different things to different people; to me, it’s as simple as defining the story of your brand. But this is multi-layered and thus requires layer upon layer of content (specific to your defined personas) which, together, builds a clear, consistent and engaging story about your brand.

I suppose that’s the whole point in brand storytelling is to engage with your customers by truly understanding what it is they actually want to see and hear from your brand.

The Inbound Marketing Funnel

Every inbound or content marketing model, regardless of how detailed, is made up similar stages. Whilst I’m aware that I’ve used Hubspot’s diagram in a previous blog, it really is the most simple in order to demonstrate my thinking. In fact, if it were turned on its side, it would work better as a sales funnel whereby brands can guide their prospects through different stages, beginning with attracting them, then ultimately they pop out of the end as delighted customers.

Content (or inbound) marketing begins with the simple premise that in order to engage with today’s consumers, brands must have (quality) content both on and off their sites.

The offsite content opportunity provides what Google refers to as ‘the Zero Moment of Truth’, the point at which a consumer reaches for their mobile or desktop device in order to thoroughly research a product or service they’re interested in. The process ends at what Google refers to as ‘the Second Moment of Truth’ – the customers’ brand experience.

The brand experience is the point of opportunity when it comes to user generated content.

Some video content can be compelling for its instructive nature its emotional nature. As humans, we naturally engage with content on an emotional level, and if that content is real life, made up of real people, then it is bound to engage us further than content which is more overtly contrived in nature.

You need a Creative Wrapper

So you have a selection of happy customers and a way to get to them via the miracle of technology, in order to ask them if they’d mind sharing their brand experience via video. But is that enough? Well, yes and no. In reality, you may need to do a little brand storytelling of your own in order to get them on board. This could be done in the simplest form by wrapping the whole piece up in a creative campaign. Enter ‘The AHH Effect’.

An integrated campaign (brand story) designed to wrap the whole concept up. In essence, a huge content campaign all around how drinking Coke makes you feel. Pretty snazzy huh? And LOADS of fun.

chúng tôi is a purpose-built content hub, stuffed with games, music and user-generated content (including the content from the TV ad). It’s a really smart combination of emotional links back to the brand all wrapped up neatly in ‘The AHH Effect’ creative campaign. It’s a smart blend of brand and digital. No wonder the fans jumped at the chance to make videos as part of it.

So what are you waiting for? Go grab a fistful of happy customers; give them a creative platform on which to shout about your brand, a loose brief as to what you need them to do then craft what comes back into an engaging and (hopefully) hugely influential part of your next content campaign.

I’d write more, but I’ve become addicted to the ‘MPC AHH’ Hip-Hop Jam creator…

How To Convert String To Number In Typescript?

The string and number are both primitive data types in TypeScript. Sometimes, we get the number in the string format, and we need to convert the string values to the number to perform mathematical operations on the value. If we perform the mathematical operation on the string values, it gives weird results. For example, adding another number value to the string of numbers appends the number to the string rather than adding.

We will learn to convert strings to numeric values using various methods and approaches in TypeScript.

So, we require to convert the string to a number in TypeScript.

Use the ‘+’ unary operator

The unary operator takes a single operand. Before evaluating an operand, it converts the operand to the number value. So, we can use it to convert strings to numeric values.

Syntax

Users can follow the syntax below to convert the string to a number value.

let numberValue: number = +stringNmber;

In the above syntax, we have used the stringNumber variable as an operand of the unary ‘+’ operator.

Example

In this example, the stringNumber variable contains the number value in the string format. Afterward, we used the unary ‘+’ operator to convert the stringNumber string value to the number and stored the evaluated value in the numberValue variable to the number data type.

In the output, users can observe that type of the numberValue variable is number.

let stringNmber: string = "124354656"; let numberValue: number = +stringNmber; console.log("The type of numberValue variable is " + typeof numberValue); console.log("The value of the numberValue variable is " + numberValue);

On compiling, it will generate the following JavaScript code −

var stringNmber = "124354656"; var numberValue = +stringNmber; console.log("The type of numberValue variable is " + typeof numberValue); console.log("The value of the numberValue variable is " + numberValue); Output 

The above code will produce the following output –

The type of numberValue variable is number The value of the numberValue variable is 124354656 Use the Number() constructor

A Number is an object in TypeScript, and we can use it as a constructor to create an instance of the Number object.

We can pass a number value as a Nuber() constructor parameter in the number or string format.

Syntax

Users can follow the syntax below to use the Number() constructor to convert the string to the number value.

let num: number = Number(str);

In the above syntax, we have passed the number value in the string format as a parameter of the Number() constructor.

Example

In this example, we have created the string1 and string2 variables containing the number values in the string format. After that, we converted both variables to numbers using the Number() constructor and stored them in the number1 and number2 variables.

After converting the string values to the numbers, users can observe their type in the output.

let string1: string = "35161"; let string2: string = "65986132302"; let number1: number = Number(string1); let number2: number = Number(string2); console.log("The value of number1 is " + number1); console.log("The type of number1 is " + typeof number1); console.log("The value of number2 is " + number2); console.log("The type of number2 is " + typeof number2);

On compiling, it will generate the following JavaScript code −

var string1 = "35161"; var string2 = "65986132302"; var number1 = Number(string1); var number2 = Number(string2); console.log("The value of number1 is " + number1); console.log("The type of number1 is " + typeof number1); console.log("The value of number2 is " + number2); console.log("The type of number2 is " + typeof number2); Output 

The above code will produce the following output –

The value of number1 is 35161 The type of number1 is number The value of number2 is 65986132302 The type of number2 is number Use parseInt() method

The parseInt() method of TypeScript extracts the integer value from the number’s string or the number itself, removing the decimal part of the number.

Syntax

Users can follow the syntax below to convert the string to a number using the parseInt() method in TypeScript.

let num: number = parseInt(str);

In the above syntax, we have passed the number value in the string format as a parseInt() method parameter.

Example

In the example below, the convertNumToString() function converts the string to a number and returns the number value. In the function, we have used the parseInt() method to extract the number from the string.

We have invoked the convertNumToString() function two times by passing different numbers in the string format as an argument, and users can observe converted number values in the output.

let stringNumber: string = "12234567998"; let stringNumber2: string = "34345465.4333"; function convertNumToString(str: string) {   let num: number = parseInt(str);   return num; } console.log(   "After converting the " +     stringNumber +     " to number value is " +     convertNumToString(stringNumber) ); console.log(   "After converting the " +     stringNumber2 +     " to number value is " +     convertNumToString(stringNumber2) );

On compiling, it will generate the following JavaScript code −

var stringNumber = "12234567998"; var stringNumber2 = "34345465.4333"; function convertNumToString(str) { var num = parseInt(str); return num; } console.log("After converting the " + stringNumber + " to number value is " + convertNumToString(stringNumber)); console.log("After converting the " + stringNumber2 + " to number value is " + convertNumToString(stringNumber2)); Output 

The above code will produce the following output –

After converting the 12234567998 to number value is 12234567998 After converting the 34345465.4333 to number value is 34345465 Use the parseFlot() method

The parseFloat() method does the same work as the parseInt() method to convert the string to a number. The only difference is that it doesn’t remove the values after the decimal point, which means it extracts the float number value from the string, whereas the parseInt () method extracts the integer value from the string.

Syntax

Users can follow the syntax below to use the parseFloat() method to convert string to number.

let numberValue: number = parseFloat(stringValue);

In the above syntax, stringValue is a float number in the string format.

Example

In the example below, the stringToFloat() function demonstrates to use of the parseFloat() method to extract the float number value from the given string. We have invoked the stringToFloat() function three times.

We have passed the string with the number and other characters as an argument of the stringToFloat() function while invoking it for the third time. In the output, we can see that it removes the characters from the string and extracts the float number value only.

let strFloat: string = "34356757"; let strFloat2: string = "7867.465546"; function stringToFloat(stringValue: string) {   let numberValue: number = parseFloat(stringValue);   console.log(     "The " +       stringValue +       " value after converting to the number is " +       numberValue   ); } stringToFloat(strFloat); stringToFloat(strFloat2); stringToFloat("232343.43434fd");

On compiling, it will generate the following JavaScript code −

var strFloat = "34356757"; var strFloat2 = "7867.465546"; function stringToFloat(stringValue) { var numberValue = parseFloat(stringValue); console.log("The " + stringValue + " value after converting to the number is " + numberValue); } stringToFloat(strFloat); stringToFloat(strFloat2); stringToFloat("232343.43434fd"); Output 

The above code will produce the following output –

The 34356757 value after converting to the number is 34356757 The 7867.465546 value after converting to the number is 7867.465546 The 232343.43434fd value after converting to the number is 232343.43434

In this tutorial, users learned the four methods to convert the number value given in string format to the actual number. The best way to convert string to number is using the unary operator, which is more time efficient than other operators. However, users can also use the Number() constructor.

Working Of Substr() Function In C++

Introduction to C++ Substring

In C++, a substring refers to a part of a string. To retrieve a substring from a given string in C++, the substr() function is used. It takes the two parameters position and length, where position represents the starting position of the substring in the given string, and length represents the number of characters in the substring to be retrieved from the given string. This substr() function returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length.

Start Your Free Software Development Course

Syntax:

substr(position, length)

Where “position” represents the starting position of the substring in the given string, and “length” represents the number of characters in the substring to retrieve from the given string.

Working of Substr() Function in C++

Working of substr() function in C++ is as follows:

In C++, we use the substr() function to retrieve a substring from a given string. A substring in C++ refers to a part of the string.

The substr() function takes two parameters: position and length.

The parameter position represents the starting position of the substring in the given string.

The parameter length represents the number of characters in the substring to retrieve from the given string.

The substr() function returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length.

Examples of C++ Substring

Following are the examples:

Example #1

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = "Welcome to C++_learning"; string strtwo = strone.substr(11, 12); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

In the above program, we have included the headers iostream and string, allowing us to use cin, court, and substr. The program executes the primary method and defines a string variable, “strone,” to store the original string from which a substring will be extracted. Using the substr function, the program extracts a substring from the string “strone,” starting from a specified position and extending for a specified length. The resulting substring is stored in the string variable “strtwo.” Finally, the program displays the extracted substring, which is stored in the variable “strtwo,” as the output on the screen.

Example #2

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = " EDUCBA is the best site for learning"; string strtwo = strone.substr(0, 6); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

Example #3

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = " Learning is fun"; string strtwo = strone.substr(12, 3); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

In the above program, we have included the headers iostream and string, allowing us to use cin, court, and substr. The program calls the main method and defines a string variable called “strone” to store the original string. The program then uses the substr function to extract a substring from the string “strone” starting from a specified position and extending for a specified length. It stores the resulting substring in the string variable “strtwo.” Finally, the program displays the extracted substring, which is stored in the variable “strtwo,” as the output on the screen.

Recommended Articles

We hope that this EDUCBA information on “C++ Substring” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Working Of Bitwise_And() Operator In Opencv

Introduction to OpenCV bitwise_and

Whenever we are dealing with images while solving computer vision problems, there arises a necessity to wither manipulate the given image or extract parts of the given image based on the requirement, in such cases we make use of bitwise operators in OpenCV and when the elements of the arrays corresponding to the given two images must be combined bit wise, then we make use of an operator in OpenCV called but wise and operator using which the arrays corresponding to the two images can be combined resulting in merging of the two images and bit wise operation on the two images returns an image with the merging done as per the specification.

Start Your Free Software Development Course

The syntax to define bitwise_and() operator in OpenCV is as follows:

bitwise_and(source1_array, source2_array, destination_array, mask)

where source1_array is the array corresponding to the first input image on which bitwise and operation is to be performed,

source2_array is the array corresponding to the second input image on which bitwise and operation is to be performed,

destination_array is the resulting array by performing bitwise operation on the array corresponding to the first input image and the array corresponding to the second input image and

mask is the mask operation to be performed on the resulting image and it is optional.

Working of bitwise_and() Operator in OpenCV

Working of bitwise_and() operator in OpenCV is as follows:

In order to be able to perform bit wise conjunction of the two arrays corresponding to the two images in OpenCV, we make use of bitwise_and operator.

To be able to make use of bitwise_and operator in our program, we must import the module cv2.

The images whose arrays are to be combined using bitwise_and operator are read using imread() function.

Then the corresponding arrays of those images are passed to the bitwise_and operator.

The bitwise_and operator returns an array that corresponds to the resulting image from the merger of the given two images.

The operation of bitwise_and can be done on images having same dimensions only.

Examples of OpenCV bitwise_and

Following are the examples are given below:

Example #1

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

Code:

#importing the modules cv2 and numpy import cv2 import numpy as np #reading the two images that are to be merged using imread() function imageread1 = cv2.imread('C:/Users/admin/Desktop/plane.jpg') imageread2 = cv2.imread('C:/Users/admin/Desktop/car.jpg') #using bitwise_and operation on the given two images resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None) #displaying the merged image as the output on the screen cv2.imshow('Merged_image', resultimage) cv2.waitKey(0) cv2.destroyAllWindows()

Output:

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #2

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

#importing the modules cv2 and numpy import cv2 import numpy as np #reading the two images that are to be merged using imread() function imageread1 = cv2.imread('C:/Users/admin/Desktop/logo.png') imageread2 = cv2.imread('C:/Users/admin/Desktop/educbalogo.jpg') #using bitwise_and operation on the given two images resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None) #displaying the merged image as the output on the screen cv2.imshow('Merged_image', resultimage) cv2.waitKey(0) cv2.destroyAllWindows()

Output:

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #3

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

 Code:

#importing the modules cv2 and numpy import cv2 import numpy as np #reading the two images that are to be merged using imread() function imageread1 = cv2.imread('C:/Users/admin/Desktop/tree.jpg') imageread2 = cv2.imread('C:/Users/admin/Desktop/educbatree.jpg') #using bitwise_and operation on the given two images resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None) #displaying the merged image as the output on the screen cv2.imshow('Merged_image', resultimage) cv2.waitKey(0) cv2.destroyAllWindows()

Output:

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Example #4

OpenCV program in python to demonstrate bitwise_and operator to read two images using imread() function and then merge the given two images using bitwise_and operator and then display the resulting image as the output on the screen:

 Code:

#importing the modules cv2 and numpy import cv2 import numpy as np #reading the two images that are to be merged using imread() function imageread1 = cv2.imread('C:/Users/admin/Desktop/plane1.jpg') imageread2 = cv2.imread('C:/Users/admin/Desktop/educbatree.jpg') #using bitwise_and operation on the given two images resultimage = cv2.bitwise_and(imageread1, imageread2, mask = None) #displaying the merged image as the output on the screen cv2.imshow('Merged_image', resultimage) cv2.waitKey(0) cv2.destroyAllWindows()

Output:

In the above program, we are importing the module cv2 and numpy. Then we are reading the two images that are to be merged using imread() function. Then we making use of the bitwise_and operator by specifying the two input images as the parameters which returns the merged image as the resulting image displayed as the output on the screen. The output is shown in the snapshot above.

Recommended Articles

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

Update the detailed information about Working And Examples Of Typescript Enum on the Tai-facebook.edu.vn 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!