Format Code

This commit is contained in:
2026-03-16 20:36:25 +08:00
parent 3ea1e48f4c
commit aa7ab9c429
4 changed files with 17 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
// 读取像素 // 读取像素
#include<opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include<iostream> #include <iostream>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
@@ -10,7 +10,8 @@ int main()
string image_path = "../img/1.png"; string image_path = "../img/1.png";
Mat image = imread(image_path); Mat image = imread(image_path);
if (image.empty()) { if (image.empty())
{
cout << "错误:无法加载图像,请检查路径是否正确。" << endl; cout << "错误:无法加载图像,请检查路径是否正确。" << endl;
return -1; return -1;
} }
@@ -20,5 +21,4 @@ int main()
cout << "B: " << (int)pixel_value[0] << " " cout << "B: " << (int)pixel_value[0] << " "
<< "G: " << (int)pixel_value[1] << " " << "G: " << (int)pixel_value[1] << " "
<< "R: " << (int)pixel_value[2] << endl; << "R: " << (int)pixel_value[2] << endl;
} }

View File

@@ -1,6 +1,6 @@
// 修改像素 // 修改像素
#include<opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include<iostream> #include <iostream>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
@@ -11,7 +11,8 @@ int main()
Mat image = imread(image_path); Mat image = imread(image_path);
Mat result = image.clone(); Mat result = image.clone();
if (image.empty()) { if (image.empty())
{
cout << "错误:无法加载图像,请检查路径是否正确。" << endl; cout << "错误:无法加载图像,请检查路径是否正确。" << endl;
return -1; return -1;
} }
@@ -24,5 +25,4 @@ int main()
waitKey(0); waitKey(0);
return 0; return 0;
} }

View File

@@ -1,6 +1,6 @@
// 图像通道分离与合并 // 图像通道分离与合并
#include<opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include<iostream> #include <iostream>
using namespace std; using namespace std;
using namespace cv; using namespace cv;
@@ -13,7 +13,7 @@ int main()
// 定义向量数组接收通道 // 定义向量数组接收通道
vector<Mat> channels; vector<Mat> channels;
// 拆分 // 拆分
split(result,channels); split(result, channels);
Mat b = channels[0]; Mat b = channels[0];
Mat g = channels[1]; Mat g = channels[1];
@@ -31,9 +31,9 @@ int main()
channels_to_merge.push_back(r); channels_to_merge.push_back(r);
merge(channels_to_merge, merged_img); merge(channels_to_merge, merged_img);
imshow("merged",merged_img); imshow("merged", merged_img);
waitKey(0); waitKey(0);
return(0); return (0);
} }

View File

@@ -1,10 +1,12 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <iostream> #include <iostream>
int main() { int main()
{
// 读取图像 // 读取图像
cv::Mat img = cv::imread("../img/1.png"); cv::Mat img = cv::imread("../img/1.png");
if (img.empty()) { if (img.empty())
{
std::cout << "无法读取图像" << std::endl; std::cout << "无法读取图像" << std::endl;
return -1; return -1;
} }