diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c585e19 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out \ No newline at end of file diff --git a/img/1.png b/img/1.png new file mode 100644 index 0000000..02e03a1 Binary files /dev/null and b/img/1.png differ diff --git a/start/display.cpp b/start/display.cpp new file mode 100644 index 0000000..19504a3 --- /dev/null +++ b/start/display.cpp @@ -0,0 +1,34 @@ +#include +#include + +using namespace cv; +using namespace std; + +int main() { + string image_path = "../img/1.png"; + Mat image = imread(image_path); + + if (image.empty()) { + cout << "错误:无法加载图像,请检查路径是否正确。" << endl; + return -1; + } + + namedWindow("Display Image", WINDOW_AUTOSIZE); + imshow("Display Image", image); + + int key = waitKey(0); + + // 4. 根据用户按键执行操作 + if (key == 's') { // 如果按下 's' 键 + // 保存图像 + string output_path = "saved_image.jpg"; + imwrite(output_path, image); + cout << "图像已保存为 " << output_path << endl; + } else { // 如果按下其他键 + cout << "图像未保存。" << endl; + } + + destroyAllWindows(); + + return 0; +} \ No newline at end of file diff --git a/start/read.cpp b/start/read.cpp index 06f68b6..97f4286 100644 --- a/start/read.cpp +++ b/start/read.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace cv; int main(){ - Mat src = imread("/home/bi/下载/1.png"); + Mat src = imread("../img/1.png"); imshow("input",src); waitKey(0); destroyAllWindows();