温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

OpenCV在C++中的图像增强案例

发布时间:2024-08-26 19:27:43 来源:亿速云 阅读:83 作者:小樊 栏目:编程语言

OpenCV(开源计算机视觉库)是一个用于处理实时图像和视频的开源库

  1. 直方图均衡化:
#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;
}
  1. 对比度拉伸:
#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;
}
  1. 高斯噪声去除:
#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;
}
  1. 中值滤波:
#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++中进行基本的图像增强。你可以根据需要调整参数以获得更好的效果。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

c++
AI