OpenCV(开源计算机视觉库)是一个用于处理实时图像和视频的开源库
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat image = imread("input.jpg", IMREAD_GRAYSCALE);
Mat equalizedImage;
equalizeHist(image, equalizedImage);
imshow("Original Image", image);
imshow("Equalized Image", equalizedImage);
waitKey(0);
return 0;
}
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat image = imread("input.jpg", IMREAD_COLOR);
Mat stretchedImage;
double minVal, maxVal;
minMaxLoc(image, &minVal, &maxVal);
for (int i = 0; i< image.rows; i++) {
for (int j = 0; j< image.cols; j++) {
Vec3b pixel = image.at<Vec3b>(i, j);
for (int k = 0; k < 3; k++) {
pixel[k] = saturate_cast<uchar>(255 * (pixel[k] - minVal) / (maxVal - minVal));
}
stretchedImage.at<Vec3b>(i, j) = pixel;
}
}
imshow("Original Image", image);
imshow("Stretched Image", stretchedImage);
waitKey(0);
return 0;
}
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat image = imread("input.jpg", IMREAD_COLOR);
Mat denoisedImage;
GaussianBlur(image, denoisedImage, Size(5, 5), 0);
imshow("Original Image", image);
imshow("Denoised Image", denoisedImage);
waitKey(0);
return 0;
}
#include <opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
Mat image = imread("input.jpg", IMREAD_COLOR);
Mat filteredImage;
medianBlur(image, filteredImage, 5);
imshow("Original Image", image);
imshow("Filtered Image", filteredImage);
waitKey(0);
return 0;
}
这些示例展示了如何使用OpenCV在C++中进行基本的图像增强。你可以根据需要调整参数以获得更好的效果。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。