-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.cpp
36 lines (27 loc) · 861 Bytes
/
image.cpp
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
#include <opencv2/opencv.hpp>
#include <iostream>
#include <unistd.h>
int main() {
char cwd[1024];
if (getcwd(cwd, sizeof(cwd)) != nullptr) {
std::cout << "Current directory: " << cwd << std::endl;
} else {
std::cerr << "Error: Unable to get the current directory" << std::endl;
return 1;
}
cv::Mat image = cv::imread("src/1111.png");
if (image.empty()) {
std::cerr << "Error: Unable to load image" << std::endl;
return 1;
}
cv::imshow("Original Image", image);
cv::waitKey(0);
std::string outputFilename = "output.jpg";
bool success = cv::imwrite(outputFilename, image);
if (!success) {
std::cerr << "Error: Unable to save image" << std::endl;
return 1;
}
std::cout << "Image saved as " << outputFilename << std::endl;
return 0;
}