Trending September 2023 # Working Of Gui Features In Opencv # Suggested October 2023 # Top 13 Popular | Dacvumuahe.com

Trending September 2023 # Working Of Gui Features In Opencv # Suggested October 2023 # Top 13 Popular

You are reading the article Working Of Gui Features In Opencv updated in September 2023 on the website Dacvumuahe.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 October 2023 Working Of Gui Features In Opencv

Introduction to OpenCV GUI

The interactive visual components in OpenCV is called Graphical User Interface or GUI and features in OpenCV GUI are reading an image, displaying the image, writing an image to a file, to draw a line, to draw a circle, to draw a rectangle, to draw an ellipse, to draw a text, etc. using imread() function, imwrite() function, imshow() function, line() function, rectangle() function, ellipse() function and polylines() function, and all these features are available as processing functions and can be accessed from the Graphical User Interface or GUI.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax to define imread() function in OpenCV is as follows:

imread('path_to_the_file', flag)

flag specifies the mode in which the file must-read. There are three modes in which the file can be read namely color mode, grayscale mode and the image as is. This parameter is optional.

The syntax to define imshow() function in OpenCV is as follows:

imshow(window_name, image)

image is the image to be displayed in a window.

returnvalue = imwrite(file_path, image)

returnvalue is the Boolean value returned by the imwrite() function.

The syntax to define line() function in OpenCV is as follows:

line(input_image, start_point, end_point, color, thickness)

where input_image is the image on which the line must be drawn,

start_point represents the x coordinate of the line,

end_point represents the y coordinate of the line,

color represents the color of the line to be drawn and

thickness represents the thickness of the line to be drawn.

The syntax to define rectangle() function in OpenCV is as follows:

rectangle(input_image, int left, int top, int right, int bottom)

bottom represents they coordinate in the bottom right corner.

The syntax to define ellipse() function in OpenCV is as follows:

ellipse(input_image, center_coordinates, axeslength, angle, startangle, endangle, color, thickness)

where input_image is the image on which the ellipse must be drawn,

center_coordinates represents the center of the ellipse,

axeslength is a tuple of two variables representing major and minor axis of ellipse,

angle represents the rotation angle of ellipse in degrees,

startangle is the starting angle of the elliptic angle in degrees,

endangle is the ending angle of the elliptic angle in degrees and

color is the color of the ellipse to be drawn and

thickness is the thickness of the ellipse to be drawn.

The syntax to define polylines() function in OpenCV is as follows:

polylines(input_image, array, isclosed, color, thickness)

array is the polygonal curves array,

isclosed is a Boolean value whose value is true if the polygon to be drawn is closed or the value is false if the polygon to be drawn is not closed.

color is the color of the polygon to be drawn and

thickness is the thickness of the polygon to be drawn.

Working of GUI Features in OpenCV

Working of GUI features in OpenCV is as follows:

imread() function is used to read the image from a given specified file.

imshow() function is used to display the given file.

imwrite() function is used to save the given image to a file.

line() function is used to draw a line

rectangle() function is used to draw a rectangle.

ellipse() function is used to draw an ellipse.

polylines() function is used to draw a polygon.

Examples

Let us discuss examples of OpenCV GUI.

Example #1

OpenCV program in python to demonstrate imread(), imwrite() and imshow() function.

import cv2 readimage = cv2.imread('C:/Users/admin/Desktop/Images/logo.png', cv2.IMREAD_GRAYSCALE) cv2.imwrite('C:/Users/admin/Desktop/Images/results/logo.png', readimage) cv2.imshow("resulting_image", readimage) cv2.waitKey(0)

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

In the above program, we are reading an image using imread() function and then writing the image to a file using imwrite() function and finally displaying the image using imshow() function. The output is shown in the snapshot above.

Example #2

OpenCV program in python to demonstrate line() function

import cv2 readimage = cv2.imread('C:/Users/admin/Desktop/Images/logo.png', cv2.IMREAD_GRAYSCALE) result = cv2.line(readimage,(0,0),(511,511),(255,0,0),5) cv2.imshow("resulting_image", readimage) cv2.waitKey(0)

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

Example #3

OpenCV program in python to demonstrate rectangle() function:

import cv2 readimage = cv2.imread('C:/Users/admin/Desktop/Images/plane.jpg', cv2.IMREAD_GRAYSCALE) result = cv2.rectangle(readimage,(384,0),(510,128),(0,255,0),3) cv2.imshow("resulting_image", readimage) cv2.waitKey(0)

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

In the above program, we are reading an image using imread() function and then drawing a rectangle on the image using rectangle() function, and finally displaying the image using imshow() function. The output is shown in the snapshot above.

Example #4

OpenCV program in python to demonstrate ellipse() function

import cv2 readimage = cv2.imread('C:/Users/admin/Desktop/Images/plane.jpg', cv2.IMREAD_GRAYSCALE) result = cv2.ellipse(readimage,(256,256),(100,50),0,0,180,255,-1) cv2.imshow("resulting_image", readimage) cv2.waitKey(0)

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

In the above program, we are reading an image using imread() function and then drawing an ellipse on the image using ellipse() function and finally displaying the image using imshow() function. The output is shown in the snapshot above.

Example #5

OpenCV program in python to demonstrate polylines() function:

import cv2 import numpy as np readimage = cv2.imread('C:/Users/admin/Desktop/Images/plane.jpg', cv2.IMREAD_GRAYSCALE) arraypoints = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32) arraypoints = arraypoints.reshape((-1,1,2)) result = cv2.polylines(readimage,[arraypoints],True,(0,255,255)) cv2.imshow("resulting_image", readimage) cv2.waitKey(0)

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

In the above program, we are reading an image using imread() function and then drawing a polygon on the image using polylines() function, and finally displaying the image using imshow() function. The output is shown in the snapshot above.

Conclusion

In this article, we have learnt the concept of GUI features in OpenCV with corresponding programming examples and their outputs to demonstrate them.

Recommended Articles

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

You're reading Working Of Gui Features In Opencv

Update the detailed information about Working Of Gui Features In Opencv on the Dacvumuahe.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!