Pg1: from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * def init(): glClearColor(0.0,0.0,0.0,1.0) gluOrtho2D(0,100,0,100) def plotLine(x1,y1,x2,y2): m = 2 * (y2 - y1) pk = m - (x2 - x1) y=y1 glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0,0.0,0.0) glPointSize(10.0) glBegin(GL_POINTS) for x in range(x1,x2+1): glVertex2f(x,y) pk =pk + m if (pk>= 0): y=y+1 pk =pk - 2 * (x2 - x1) glEnd() glFlush() x1 = int(input("Enter x1: ")) y1 = int(input("Enter y1: ")) x2 = int(input("Enter x2: ")) y2 = int(input("Enter y2: ")) print("starting window....") glutInit(sys.argv) glutInitDisplayMode(GLUT_RGB) glutInitWindowSize(500,500) glutInitWindowPosition(0,0) glutCreateWindow("Bresenham Line Algorithm") glutDisplayFunc(lambda:plotLine(x1,y1,x2,y2)) init() glutMainLoop() Pg6: from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * import time angle = 0 scale = 1.0 scale_direction = 1 translation = [0.0, 0.0, 0.0] translation_direction = [1, 1, 1] vertices = ( (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1), (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1) ) edges = ( (0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4), (0, 4), (1, 5), (2, 6), (3, 7) ) surfaces = ( (0, 1, 2, 3), (3, 2, 7, 6), (6, 7, 5, 4), (4, 5, 1, 0), PROGRAM-06 Develop a program to demonstrate Animation effects on simple objects. (1, 5, 7, 2), (4, 0, 3, 6) ) colors = ( (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (1, 0, 1), (0, 1, 1) ) def draw_cube(): glBegin(GL_QUADS) for i, surface in enumerate(surfaces): glColor3fv(colors[i]) for vertex in surface: glVertex3fv(vertices[vertex]) glEnd() glBegin(GL_LINES) glColor3fv((0, 0, 0)) for edge in edges: for vertex in edge: glVertex3fv(vertices[vertex]) glEnd() def display(): global angle, scale, translation glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(0.0, 0.0, -10) glScalef(scale, scale, scale) glTranslatef(*translation) glRotatef(angle, 1, 1, 1) draw_cube() glutSwapBuffers() angle += 0.5 def animate(): PROGRAM-06 Develop a program to demonstrate Animation effects on simple objects. global scale, scale_direction, translation, translation_direction # Update scale scale += 0.01 * scale_direction if scale >= 1.5 or scale <= 0.5: scale_direction *= -1 # Update translation for i in range(3): translation[i] += 0.01 * translation_direction[i] if translation[i] >= 1 or translation[i] <= -1: translation_direction[i] *= -1 glutPostRedisplay() time.sleep(0.01) def keyboard(key, x, y): if key == b'\x1b': # ESC key glutLeaveMainLoop() def reshape(width, height): if height == 0: height = 1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, width / height, 0.1, 50.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def main(): glutInit() glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(800, 600) glutCreateWindow("Cube with Animation") glEnable(GL_DEPTH_TEST) glutDisplayFunc(display) glutIdleFunc(animate) glutReshapeFunc(reshape) glutKeyboardFunc(keyboard) glutMainLoop() if __name__ == "__main__": main() Pg:07 import cv2 def split_image(image_path): image = cv2.imread(image_path) height, width, _ = image.shape left = image[0:height, 0:width//2] right = image[0:height, width//2:width] up = image[0:height//2, 0:width] down = image[height//2:height, 0:width] return left, right, up, down def display_quadrants(left, right, up, down): cv2.imshow('Left Quadrant', left) cv2.imshow('Right Quadrant', right) cv2.imshow('Upper Quadrant', up) cv2.imshow('Lower Quadrant', down) cv2.waitKey(0) cv2.destroyAllWindows() def main(): image_path = "Your image name.jpg" left, right, up, down = split_image(image_path) display_quadrants(left, right, up, down) if __name__ == "__main__": main() Pgm:08 import cv2 import numpy as np def rotate_image(image, angle): height, width = image.shape[:2] rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), angle, 1) rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height)) return rotated_image def scale_image(image, scale_factor): scaled_image = cv2.resize(image, None, fx=scale_factor, fy=scale_factor, interpolation=cv2.INTER_LINEAR) return scaled_image def translate_image(image, tx, ty): translation_matrix = np.float32([[1, 0, tx], [0, 1, ty]]) translated_image = cv2.warpAffine(image, translation_matrix, (image.shape[1], image.shape[0])) return translated_image def main(): # Read the image image_path = "your_image_path.jpg" # Replace with the path to your image original_image = cv2.imread(image_path) # Rotate the image rotated_image = rotate_image(original_image, 45) # Scale the image scaled_image = scale_image(original_image, 1.5) # Translate the image translated_image = translate_image(original_image, 50, 50) # Display the images cv2.imshow('Original Image', original_image) cv2.imshow('Rotated Image', rotated_image) cv2.imshow('Scaled Image', scaled_image) cv2.imshow('Translated Image', translated_image) cv2.waitKey(0) cv2.destroyAllWindows() if __name__ == "__main__": main() Pgm:09 import cv2 import numpy as np def display_image(title, image): cv2.imshow(title, image) cv2.waitKey(0) cv2.destroyAllWindows() def canny_edge_detection(image): # Convert the image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Apply Gaussian blur to reduce noise blurred = cv2.GaussianBlur(gray, (5, 5), 0) # Perform Canny edge detection edges = cv2.Canny(blurred, 50, 150) return edges def texture_filtering(image): # Convert the image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Apply Laplacian filter for edge detection laplacian = cv2.Laplacian(gray, cv2.CV_64F) # Convert the Laplacian result to uint8 laplacian_uint8 = np.uint8(np.absolute(laplacian)) return laplacian_uint8 def main(): # Read the image image_path = "your_image_path.jpg" # Replace with the path to your image image = cv2.imread(image_path) # Apply Canny edge detection edges = canny_edge_detection(image) display_image('Canny Edge Detection', edges) # Apply texture filtering textures = texture_filtering(image) display_image('Texture Filtering (Laplacian)', textures) if __name__ == "__main__": main() Pgm:10 import cv2 def display_image(title, image): cv2.imshow(title, image) cv2.waitKey(0) cv2.destroyAllWindows() def blur_image(image): # Apply Gaussian blur blurred = cv2.GaussianBlur(image, (5, 5), 0) return blurred def main(): # Read the image image_path = "your_image_path.jpg" # Replace with the path to your image image = cv2.imread(image_path) # Blur the image blurred_image = blur_image(image) # Display the original and blurred images display_image('Original Image', image) display_image('Blurred Image', blurred_image) if __name__ == "__main__": main() Pgm:11 import cv2 def display_image(title, image): cv2.imshow(title, image) cv2.waitKey(0) cv2.destroyAllWindows() def contour_image(image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) _, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) contour_image = image.copy() cv2.drawContours(contour_image, contours, -1, (0, 255, 0), 2) return contour_image def main(): # Read the image image_path = "your_image_path.jpg" # Replace with the path to your image image = cv2.imread(image_path) contoured_image = contour_image(image) display_image('Original Image', image) display_image('Contoured Image', contoured_image) if __name__ == "__main__": main() Pgm:12 import cv2 def display_image(title, image): cv2.imshow(title, image) cv2.waitKey(0) cv2.destroyAllWindows() def detect_faces(image_path): face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') image = cv2.imread(image_path) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) return image def main(): image_path = "your_image_path.jpg" # Replace with the path to your image image_with_faces = detect_faces(image_path) display_image('Image with Faces Detected', image_with_faces) if __name__ == "__main__": main()