Question
P[ease can you solve this program with screenshot its important a screenshot plaese Python OpenCV | cv2.line() method OpenCV-Python is a library of Python bindings
P[ease can you solve this program with screenshot
its important a screenshot plaese
Python OpenCV | cv2.line() method
OpenCV-Python is a library of Python bindings designed to solve computer vision problems.cv2.line() method is used to draw a line on any image.
Syntax: cv2.line(image, start_point, end_point, color, thickness)
Parameters:
image: It is the image on which line is to be drawn.
start_point: It is the starting coordinates of line. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value).
end_point: It is the ending coordinates of line. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value).
color: It is the color of line to be drawn. For BGR, we pass a tuple. eg: (255, 0, 0) for blue color.
thickness: It is the thickness of the line in px.
Return Value: It returns an image.
# Python program to explain cv2.line() method
# importing cv2 import cv2
# path path = r'lab3.jpg'
# Reading an image in grayscale mode image = cv2.imread(path, 0)
# Window name in which image is displayed window_name = 'Image'
# Start coordinate, here (0, 0) # represents the top right corner of image start_point = (0, 0)
# End coordinate, here (696, 548) # represents the bottom left corner of image end_point = (696, 548)
# Black color in BGR color = (0, 0, 0)
# Line thickness of 5 px thickness = 5
# Using cv2.line() method # Draw a diagonal black line with thickness of 5 px image = cv2.line(image, start_point, end_point, color, thickness)
# Displaying the image cv2.imshow(window_name, image) cv2.waitKey(0) cv2.destroyAllWindows() |
Python OpenCV | cv2.rectangle() method
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.rectangle() method is used to draw a rectangle on any image.
Syntax: cv2.rectangle(image, start_point, end_point, color, thickness)
Parameters: image: It is the image on which rectangle is to be drawn. start_point: It is the starting coordinates of rectangle. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value). end_point: It is the ending coordinates of rectangle. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value). color: It is the color of border line of rectangle to be drawn. For BGR, we pass a tuple. eg: (255, 0, 0) for blue color. thickness: It is the thickness of the rectangle border line in px. Thickness of -1 px will fill the rectangle shape by the specified color.
Return Value: It returns an image. |
Code
# Python program to explain cv2.line() method
# importing cv2 import cv2
# path path = r'lab3.jpg'
# Reading an image in grayscale mode image = cv2.imread(path)
# Window name in which image is displayed window_name = 'Image'
# Start coordinate, here (5, 5) # represents the top left corner of rectangle start_point = (5, 5)
# Ending coordinate, here (220, 220) # represents the bottom right corner of rectangle end_point = (220, 220)
# Blue color in BGR color = (255, 0, 0)
# Line thickness of 10 px thickness = 10
# Using cv2.rectangle() method # Draw a rectangle with blue line borders of thickness of 2 px image = cv2.rectangle(image, start_point, end_point, color, thickness)
# Displaying the image cv2.imshow(window_name, image) cv2.waitKey(0) cv2.destroyAllWindows() |
Python OpenCV | cv2.circle() method
OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2.circle() method is used to draw a circle on any image.
Syntax: cv2.circle(image, center_coordinates, radius, color, thickness) Parameters: image: It is the image on which circle is to be drawn. center_coordinates: It is the center coordinates of circle. The coordinates are represented as tuples of two values i.e. (X coordinate value, Y coordinate value). radius: It is the radius of circle. color: It is the color of border line of circle to be drawn. For BGR, we pass a tuple. eg: (255, 0, 0) for blue color. thickness: It is the thickness of the circle border line in px. Thickness of -1 px will fill the circle shape by the specified color. Return Value: It returns an image. |
Code
# Python program to explain cv2.line() method
# importing cv2 import cv2
# path path = r'lab3.jpg'
# Reading an image in grayscale mode image = cv2.imread(path)
# Window name in which image is displayed window_name = 'Image'
# Center coordinates center_coordinates = (200, 200)
# Radius of circle radius = 100
# Blue color in BGR color = (0, 0, 255)
# Line thickness of 2 px thickness = 2
# Using cv2.circle() method # Draw a circle with blue line borders of thickness of 2 px image = cv2.circle(image, center_coordinates, radius, color, thickness)
# Displaying the image cv2.imshow(window_name, image) cv2.waitKey(0) cv2.destroyAllWindows() |
Lab 3 Task:
Install Open CV and run the three codes for drawing line, rectangle and circle. Take screenshots of the three codes running successfully on your computer along with the code to Blackboard.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started