-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment.py
More file actions
36 lines (28 loc) · 982 Bytes
/
Assignment.py
File metadata and controls
36 lines (28 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Instructions :-
1. Take user input for location of image / Upload
2. Load the image
3. Convert to GRAYSCALE
4. Ask user if he wants to save or see that image
5. If user opts for save , ask for output's filename to be given.
"""
import cv2
FILE_PATH = input("Enter file path or upload image")
img = cv2.imread(FILE_PATH)
if img is None:
print("Error: Image not found. Please check the file path.")
exit()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ask = int(input("To view image : Press 1\nTo save image : Press 2"))
if ask == 1:
cv2.imshow("Gray Image", gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
elif ask == 2:
output = input("Give a name for output file (with or without extension): ")
if not output.lower().endswith((".png", ".jpg", ".jpeg")):
output += ".png"
cv2.imwrite(output, gray)
print(f"Image saved as {output}")
else:
print("Please choose from the given options only.")