-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePhotoEditor.cpp
More file actions
118 lines (104 loc) · 3.4 KB
/
SimplePhotoEditor.cpp
File metadata and controls
118 lines (104 loc) · 3.4 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
// Check if an image file is provided as an argument
if (argc != 2) {
cout << "Usage: " << argv[0] << " <image_file>" << endl;
return -1;
}
// Load the image
Mat image = imread(argv[1]);
if (image.empty()) {
cout << "Could not open or find the image: " << argv[1] << endl;
return -1;
}
Mat originalImage = image.clone();
// Display the original image
imshow("Original Image", image);
// Create a menu-driven interface
int option;
bool exitMenu = false;
while (!exitMenu) {
cout << "Select an option:" << endl;
cout << "1. Resize" << endl;
cout << "2. Crop" << endl;
cout << "3. Apply Gaussian Blur" << endl;
cout << "4. Apply Sobel Edge Detection" << endl;
cout << "5. Apply Sepia Filter" << endl;
cout << "6. Reset to Original Image" << endl;
cout << "7. Save Image" << endl;
cout << "8. Exit" << endl;
cin >> option;
switch (option) {
case 1: {
// Resize the image
int newWidth, newHeight;
cout << "Enter new width: ";
cin >> newWidth;
cout << "Enter new height: ";
cin >> newHeight;
resize(image, image, Size(newWidth, newHeight));
break;
}
case 2: {
// Crop the image
int x, y, width, height;
cout << "Enter top-left corner coordinates (x, y): ";
cin >> x >> y;
cout << "Enter width: ";
cin >> width;
cout << "Enter height: ";
cin >> height;
Rect roi(x, y, width, height);
image = originalImage(roi).clone();
break;
}
case 3: {
// Apply Gaussian blur
GaussianBlur(image, image, Size(5, 5), 0, 0);
break;
}
case 4: {
// Apply Sobel edge detection
Mat grayscaleImage;
cvtColor(image, grayscaleImage, COLOR_BGR2GRAY);
Sobel(grayscaleImage, image, CV_8U, 1, 1);
break;
}
case 5: {
// Apply Sepia filter
Mat kernel = (Mat_<float>(3, 3) <<
0.272, 0.534, 0.131,
0.349, 0.686, 0.168,
0.393, 0.769, 0.189);
transform(image, image, kernel);
break;
}
case 6: {
// Reset to original image
image = originalImage.clone();
break;
}
case 7: {
// Save the modified image
imwrite("modified_image.jpg", image);
cout << "Modified image saved as modified_image.jpg" << endl;
break;
}
case 8: {
// Exit
exitMenu = true;
break;
}
default:
cout << "Invalid option! Please try again." << endl;
break;
}
// Display the modified image
imshow("Modified Image", image);
waitKey(0);
}
return 0;
}