Python | cv2 imwrite() Method

In this tutorial, we will see how to save an image in your own system using python by using open-cv which exists as cv2 (computer vision) library.

You can use imwrite() method of cv2 library to save an image on your system. To use cv2 library, you need to import cv2 library using import statement.

Now let’s see the syntax and return value of imwrite() method, then we will move on to the examples.

Syntax

Parameters

You need to pass two parameters to imwrite() method. Parameters are:

  1. path: Location address where you want to save an image in your system in string form with including the filename.

    here two cases will be possible :

    i) if you want to save an image in the current working directory then we have to mention only the name of the image with their extension like .jpg,.png etc.

    ii) if you want to save an image at somewhere else in your system not in the current working directory then we have to give complete path, also known as, absolute path of the image.

  2. image: It is the image pixel matrix of that image, which you want to save in your system.

Return Value

It returns either True or False. Return True if the image is successfully saved otherwise return False.

cv2 imwrite() method Examples

Now Let’s see the Python code :

Output :

Before saving an image, contents of directory shows :
[] After saving an image, contents of directory shows :
[‘image1.jpg’]

That’s all about cv2.imwrite() Method.


import_contacts

You may also like:

Related Posts

  • Make requirements.txt in Python
    03 May

    Make requirements.txt in python

    Table of ContentsWhat is the requirements.txt file in Python?Ways to make requirements.txt file in PythonUsing the pip to make requirements.txt in PythonUsing the conda command to make requirements.txt file in PythonUsing the pipreqs package to make requirements.txt file in PythonConclusion What is the requirements.txt file in Python? Every package is also updated regularly and features […]

  • Create an array of 1 to 10 in Python
    03 May

    Create an Array of 1 to 10 in Python

    Table of ContentsIntroductionHow to create an array of 1 to 10 in Python?Using the range() function to create an array of 1 to 10 in Python.Using list comprehension along with the range() function to create an array of 1 to 10 in Python.Using a user-defined function to create an array of 1 to 10 in […]

  • Remove Urls from String in Python
    03 May

    Remove Urls from Text in Python

    Table of ContentsIntroductionWays to remove URLs from Text in PythonUsing the re.sub() function to remove URLs from Text in PythonUsing the re.findall() function to remove URLs from Text in PythonUsing the re.search() function to remove URLs from Text in PythonUsing the urllib.urlparse class to remove URLs from Text in PythonConclusion In this post, we will […]

  • Create a list from 1 to 100 in Python
    03 May

    Create a List from 1 to 100 in Python

    Table of ContentsWays to create a list from 1 to 100 in PythonUsing the range() function to create a list from 1 to 100 in PythonUsing the numpy.arange() function to create a list from 1 to 100 in PythonUsing the for loop with range() to create a list from 1 to 100 in PythonConclusion In […]

  • Return vs Print in Python
    16 April

    Return vs Print in Python

    Table of ContentsReturn vs Print in PythonConclusion Return vs Print in Python In Python, we work with a wide range of functions that make our code simple. We can also create functions using the def keyword. A function can be defined as per our requirement and can display something or return a value. This is […]

  • Floor division in Python
    10 April

    Floor division in Python

    Table of ContentsWhat is Floor Division in Python?How to implement floor division in Python?Using the // operator to implement floor division in Python.Using the // operator to implement floor division on negative integers in Python.Using the // operator to implement floor division on floating-point numbers in Python.Using the // operator to implement floor division with […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.