28 lines
587 B
C++
28 lines
587 B
C++
// 修改像素
|
|
#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;
|
|
} |