今天利用Laplance算子对皮卡丘处理的图片
让我们先了解下 对应理论知识点吧:
上此我们使用Sobel算子只求一阶导,求最大值来处理数据,这里求二阶导,取0值。这就是简单的理论部分。
代码部分:
// opencv0019.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat src, dst;
src = imread("D:/images/pkq.jpg");
if (!src.data) {
printf("could not load image");
}
char input_title[] = "input image";
char output_title[] = "Laplaiance Result";
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
Mat gray_src, edge_image;
GaussianBlur(src, dst,Size(3,3),0,0);
cvtColor(src, gray_src, CV_BGR2GRAY);
Laplacian(gray_src, edge_image, CV_16S, 3);
convertScaleAbs(edge_image, edge_image);
//选择阈值
threshold(edge_image, edge_image, 0, 255, THRESH_OTSU|THRESH_BINARY);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(output_title, edge_image);
waitKey(0);
return 0;
}