Compare commits
2 Commits
183d7fea8d
...
3aa643e052
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
out
|
||||
24
basic/readpixel.cpp
Normal file
24
basic/readpixel.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// 读取像素
|
||||
#include<opencv2/opencv.hpp>
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
string image_path = "../img/1.png";
|
||||
Mat image = imread(image_path);
|
||||
|
||||
if (image.empty()) {
|
||||
cout << "错误:无法加载图像,请检查路径是否正确。" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Vec3b pixel_value = image.at<Vec3b>(100, 150);
|
||||
|
||||
cout << "B: " << (int)pixel_value[0] << " "
|
||||
<< "G: " << (int)pixel_value[1] << " "
|
||||
<< "R: " << (int)pixel_value[2] << endl;
|
||||
|
||||
}
|
||||
28
basic/roi.cpp
Normal file
28
basic/roi.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// 修改像素
|
||||
#include<opencv2/opencv.hpp>
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main()
|
||||
{
|
||||
string image_path = "../img/1.png";
|
||||
Mat image = imread(image_path);
|
||||
Mat result = image.clone();
|
||||
|
||||
if (image.empty()) {
|
||||
cout << "错误:无法加载图像,请检查路径是否正确。" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Rect roi_rect(0, 0, 100, 100);
|
||||
Mat roi = result(roi_rect);
|
||||
roi.setTo(Scalar(0, 255, 0));
|
||||
imshow("Original (Unchanged)", image);
|
||||
imshow("Modified Copy", result);
|
||||
waitKey(0);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
34
start/display.cpp
Normal file
34
start/display.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user