zoukankan      html  css  js  c++  java
  • 图形锐化_opencv/C++

    #include "stdafx.h"
    #include<iostream>
    #include<opencv2/core/core.hpp>
    #include<opencv2/imgproc/imgproc.hpp>
    #include<opencv2/highgui/highgui.hpp>

    void sharpen(const cv::Mat &image, cv::Mat &result)
    {
    //如有必要则分割图像
    result.create(image.size(), image.type());
    for (int j = 1; j < image.rows - 1; j++)
    {
    //处理除了第一行和最后一行之外的所有行
    const uchar* previous = image.ptr<const uchar>(j - 1);//上一行
    const uchar* current = image.ptr<const uchar>(j);//当前行
    const uchar* next = image.ptr<const uchar>(j + 1);//下一行
    uchar* output = result.ptr<uchar>(j);//输出行
    for (int i = 1; i < image.cols - 1; i++)
    {
    *output++ = cv::saturate_cast<uchar>(5 * current[i] - current[i - 1] - current[i + 1] - previous[i] - next[i]);
    }
    }
    //将未处理的像素设置为0
    result.row(0).setTo(cv::Scalar(0));
    result.row(result.rows - 1).setTo(cv::Scalar(0));
    result.col(0).setTo(cv::Scalar(0));
    result.col(result.cols - 1).setTo(cv::Scalar(0));
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    cv::Mat image = cv::imread("boldt.jpg");
    cv::Mat myImage;
    sharpen(image,myImage);
    cv::namedWindow("Image");
    cv::imshow("Image", image);
    cv::imwrite("output.jpg", image);
    cvWaitKey();
    return 0;
    }

  • 相关阅读:
    Docker容器查看ip地址
    抽象工厂模式
    idea插件
    作业统计
    tarjan强连通图分量
    Android动画浅析
    位运算
    mongodb笔记
    依赖倒置原则
    单一职责原则
  • 原文地址:https://www.cnblogs.com/hnzsb-vv1130/p/6587082.html
Copyright © 2011-2022 走看看