Professional Documents
Culture Documents
ASSIGNMENT- 02
Course Instructor: Lecturer Anum Abdul Salam
1
Task : Open cv along with output of code
Main Code:
public:
// Load image from file
Mat ImageLoad(const string& Path) {
return imread(Path);
}
2
else {
cout << "Image : " << endl;
imshow(windowName, image);
waitKey(0);
destroyAllWindows();
}
}
3
rotationMatrix.at<double>(0, 2) += bbox.width / 2.0 - center.x;
rotationMatrix.at<double>(1, 2) += bbox.height / 2.0 - center.y;
4
}
switch (choice) {
case 1:
cvtColor(filterImage, filterImage, COLOR_BGR2GRAY);
display(filterImage, "Grayscale Image");
EditSavePrompt(filterImage);
break;
case 2:
int kernelSize;
do {
cout << "Enter kernel size for blur filter (it should be odd
and maximum kernelSize is 31): ";
cin >> kernelSize;
} while (kernelSize % 2 != 1 || kernelSize > 31 || kernelSize <
0);
GaussianBlur(filterImage, filterImage, Size(kernelSize,
kernelSize), 0);
display(filterImage, "Blurred Image");
EditSavePrompt(filterImage);
break;
case 3:
sharpen(filterImage);
break;
case 4:
break;
5
default:
cout << "Invalid choice. Try again." << endl;
}
} while (choice != 4);
}
6
EditSavePrompt(adjusted);
}
else if (choice == 4) {
break;
}
} while (choice >= 1 && choice <= 4);
}
7
input(file);
orig_image = ImageLoad(file);
flag = true;
int choice;
int option;
if (orig_image.empty()) {
cerr << "Error: Could not open or find the image." << endl;
return -1;
}
cout << "Welcome to image Editor: " << endl;
do {
cout << "Press 1: To resize Image " << endl
<< "Press 2: To Rotate Image " << endl
<< "Press 3: To Crop Image" << endl
<< "Press 4: To Adjust Image Brightness and Contrast " << endl
<< "Press 5: To Apply Filters on Image " << endl
<< "Press 6: To save Image " << endl
<< "Press 7: To display Image " << endl
<< "Press 8: To exit the Image Editor " << endl;
cin >> choice;
switch (choice) {
case 1:
if (flag) ResizeImage(orig_image);
else ResizeImage(edit_image);
break;
case 2:
if (flag) RotateImage(orig_image);
else RotateImage(edit_image);
break;
case 3:
if (flag) CropImage(orig_image);
else CropImage(edit_image);
break;
case 4:
if (flag) ContrastAdjustment(orig_image);
else ContrastAdjustment(edit_image);
break;
case 5:
if (flag) ApplyFilter(orig_image);
else ApplyFilter(edit_image);
break;
case 6:
do {
cout << "Press 1: To Save the original image." << endl
<< "Press 2: To save the edited image." << endl
8
<< "Enter your Choice: ";
cin >> option;
} while (option < 1 || option > 2);
if (option == 1) {
cout << "Press 1: To Save the Image by its name." << endl
<< "Press 2: To save the image by a new name." << endl
<< "Enter your Choice: ";
cin >> option;
SavePrompt(option, orig_image);
}
else if (option == 2) {
if (edit_image.empty()) {
cerr << "Error: Could not open or find the image." <<
endl;
return -1;
}
else {
cout << "Press 1: To Save the Edited Image in place of
the original image." << endl
<< "Press 2: To save the Edited image." << endl
<< "Enter your Choice: ";
cin >> option;
SavePrompt(option, edit_image);
}
}
break;
case 7:
if (flag) display(orig_image, "Preview");
else display(edit_image, "Preview");
break;
case 8:
break;
default:
choice = 0;
}
} while (choice != 8);
return 0;
}
9
do {
cout << "Press 1: To save this Edited Image" << endl
<< "Press 2: To remove this Edited image Only" << endl
<< "Press 3: To remove all Edited Image" << endl;
cin >> choice;
if (choice == 1) {
flag = false;
edit_image = image;
break;
}
else if (choice == 2) {
if (!edit_image.empty()) {
flag = false;
image = edit_image;
}
else {
cout << "No Edit Image Exists." << endl;
flag = true;
}
break;
}
else if (choice == 3) {
flag = true;
edit_image = empty;
break;
}
else if (choice < 1 || choice > 3)
cout << "Invalid choice. Try again." << endl;
} while (choice < 1 || choice > 3);
}
10
else
cout << "Invalid input: " << endl;
} while (option != 0);
}
};
int main() {
ImageEdit image;
return image.menu();
}
Output:
11
12
13
14
15
16
17
18
Saved Image (Edit1.png):
19
UML Diagram:
20
ImageEdit
- file: string
- orig_image: Mat
- edit_image: Mat
- flag: bool
- sharpen(Mat&): void
- input(string&): void
- extension(string&): void
- EditSavePrompt(Mat&): void
21