0% found this document useful (0 votes)
36 views1 page

Assignment 8

The document contains Python code using OpenCV to read, display, and manipulate images. It includes functionalities for resizing, flipping, cropping, converting to grayscale, and saving images with a new name. The code also handles user input for image dimensions and file naming, with error checking for valid inputs.

Uploaded by

Rahane Ayushi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views1 page

Assignment 8

The document contains Python code using OpenCV to read, display, and manipulate images. It includes functionalities for resizing, flipping, cropping, converting to grayscale, and saving images with a new name. The code also handles user input for image dimensions and file naming, with error checking for valid inputs.

Uploaded by

Rahane Ayushi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import cv2

img = cv2.imread('image.png')
if img is not None:
print("Image successfully read.")
else:
print("Failed")

# cv2.imshow("Image",img)
# cv2.waitKey(0) #destroys the window when any key is pressed.

# #save the image with new name:

# newname = input("Enter the new name with extension: ")

# if(newname ==None):
# print("Please enter name")
# elif(not(newname.endswith('jpg') or newname.endswith('webp') or
newname.endswith('png'))):
# print("Give extension!")
# else:
# cv2.imwrite(newname,img)
# print("Image saved successfully..")

# width = int(input("Enter width: "))


# height = int(input("Enter Height: "))

# resized_img = cv2.resize(img,(width,height))
# cv2.imshow("Resized Image",resized_img)
# cv2.waitKey(0)

# if img is None:
# print("No img")
# else:
# flipped_img = cv2.flip(img,0)
# cv2.imshow("Flipped Image",flipped_img)
# cv2.waitKey(0)

# x = 114
# y=214
# w=400
# h=233

# cropped_img = img[y:y+h, x:x+w]

# cv2.imshow("Cropped img", cropped_img)


# cv2.waitKey(0)

# gray_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# cv2.imshow("gray",gray_img)
# cv2.waitKey(0)

# alpha = 3.3

# img2 = cv2.convertScaleAbs(img,alpha=alpha,beta=0)
# cv2.imshow("sd",img2)
# cv2.waitKey(0)

You might also like