CG Program Explanation
CG Program Explanation
1. The bresenham_line function takes four arguments: x1, y1, x2, and
y2, which represent the starting and ending points of the line segment.
2. Inside the function, it calculates the deltas (dx and dy) between the
starting and ending points, and determines the step direction (x_step
and y_step) for each axis.
6. It updates the error term (error) and adjusts the coordinates of x and
y based on the Bresenham's line algorithm.
7. After the loop, the function returns the line_points list containing
the coordinates of the line points.
3. A turtle instance t is created, and its speed and pen size are set.
• The rectangle is translated 200 units to the right, and a new rectangle
is drawn at (0, 0).
• The circle is translated 200 units to the right, and a new circle is
drawn at (300,100).
position, with given radius, height, and color. It returns the created
cylinder object.
7. Defines a function scale that scales a 3D object by given sx, sy, and
sz scale factors along the x, y, and z axes, respectively.
10.Rotates the cuboid by 45 degrees around the y-axis using the rotate
function.
11.Scales the cuboid by a factor of 1.5 along all axes using the scale
function.
15.Scales the cylinder by a factor of 1.5 along all axes using the scale
function.
10.Enters the main loop, which runs until the user closes the window.
• Handles the Pygame event queue, checking for the QUIT event to
exit the loop.
• Clears the color and depth buffers using glClear.
• Draws the 3D cube by iterating over the edges and vertices, using
6. Enters the main loop, which runs until the user closes the window.
8. Handles the Pygame event queue, checking for the QUIT event to
exit the loop.
4. The height and width of the image are obtained from the shape
attribute of the image.
5. The image is split into four quadrants using NumPy array slicing:
10.A blank canvas with the same dimensions as the original image is
created using np.zeros(). This canvas will be used to display the four
quadrants.
11.The four quadrants are placed on the canvas using NumPy array
assignment.
4. The height and width of the image are obtained from the shape
attribute of the image.
14.The script waits for a key press (cv2.waitKey(0)) before closing the
windows.
7. The original image (img), the detected edges (edges), and the
extracted texture
8. The script waits for a key press (cv2.waitKey(0)) before closing the
windows.
7. The original image and the filtered images are displayed using
cv2.imshow().
8. The script waits for a key press (cv2.waitKey(0)) before closing the
windows.
1. The cv2 library is imported from OpenCV, and the numpy library is
imported for numerical operations.
argument indicates that all contours should be drawn, the (0, 255, 0)
argument specifies the color (green in this case), and the 2 argument
specifies the thickness of the contour lines.
8. The original image and the contour image are displayed using
cv2.imshow().
9. The script waits for a key press (cv2.waitKey(0)) before closing the
windows.
cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml'). This classifier is a pre-trained
model that can detect frontal faces in images.
11.The image with the detected faces and rectangles is displayed using
12.The script waits for a key press (cv2.waitKey(0)) before closing the
window.
13.Finally, the window is closed using cv2.destroyAllWindows().