CGLABMANUALNEW
CGLABMANUALNEW
float cubeVertices[8][3] = {
{-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0},
{-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}
};
void drawCube() {
glBegin(GL_QUADS);
int faces[6][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {0, 3, 7, 4}, {1, 2, 6, 5}, {3, 2, 6, 7}, {0, 1, 5, 4}};
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 4; ++j)
glVertex3fv(cubeVertices[faces[i][j]]);
glEnd();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
drawCube();
glFlush();
int option;
printf("\nChoose Transformation:\n1. Translation\n2. Rotation\n3. Scaling\n4. Exit\nEnter
your choice: ");
scanf("%d", &option);
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("3D Object Transformations");
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 1.0, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
4. Develop a program to demonstrate 2D transformation on basic objects
#include<GL/glut.h>
#include<stdio.h>
#include<math.h>
int b[4][4]={{100,100},{100,200},{200,200},{200,100}};
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
for(int i=0;i<4;i++)
glVertex2i(b[i][0],b[i][1]);
glEnd();
glFlush();
char option;
printf("enter the option");
scanf("%c",&option);
switch(option)
{
case 't':glTranslatef(20,20,0); break;
case 's':glScalef(2,2,1); break;
case 'r':glRotatef(-45,0,0,1); break;
case 'e': exit(0); break;
}
}
void main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutCreateWindow("new window");
glClearColor(0.0,0.0,0.0,0.0);
glutDisplayFunc(display);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,500,0,500);
glutMainLoop();
}
5. Develop a program to demonstrate 3D transformation on 3D objects
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float cubeVertices[8][3] = {
{-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0},
{-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}
};
void drawCube() {
glBegin(GL_QUADS);
int faces[6][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {0, 3, 7, 4}, {1, 2, 6, 5}, {3, 2, 6, 7}, {0, 1, 5, 4}};
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 4; ++j)
glVertex3fv(cubeVertices[faces[i][j]]);
glEnd();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
drawCube();
glFlush();
int option;
printf("\nChoose Transformation:\n1. Translation\n2. Rotation\n3. Scaling\n4. Exit\nEnter
your choice: ");
scanf("%d", &option);
glutPostRedisplay();
}
// Initialize OpenGL
if image is None:
print("Failed to load the image.")
else:
# Split the image into quadrants
top_left, top_right, bottom_left, bottom_right = split_image(image)
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
# Rotation
angle = 45 # Rotation angle in degrees
center = (image.shape[1] // 2, image.shape[0] // 2) # Center of rotation
rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) # Rotation matrix
rotated_image = cv2.warpAffine(image, rotation_matrix, (image.shape[1],
image.shape[0]))
# Scaling
scale_factor = 0.5 # Scaling factor (0.5 means half the size)
scaled_image = cv2.resize(image, None, fx=scale_factor, fy=scale_factor)
# Translation
translation_matrix = np.float32([[1, 0, 100], [0, 1, -50]]) # Translation matrix (100 pixels
right, 50 pixels up)
translated_image = cv2.warpAffine(image, translation_matrix, (image.shape[1],
image.shape[0]))
cv2.waitKey(0)
cv2.destroyAllWindows()
9. Read an image and extract and display low-level features such as edges,
textures using filtering techniques.
import cv2
import numpy as np
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
if image is None:
print("Failed to load the image.")
else:
# Display the original image
cv2.imshow("Original Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
if image is None:
print("Failed to load the image.")
else:
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.waitKey(0)
cv2.destroyAllWindows()
if image is None:
print("Failed to load the image.")
else:
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)