1. Image Corrosion
The function is:
CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT,const Scalar& borderValue=morphologyDefaultBorderValue() );
2. The image is blurry
The function is
//! a synonym for normalized box filter CV_EXPORTS_W void blur( InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT );
3. Edge detection
The function is
//! applies Canny edge detector and produces the edge map. CV_EXPORTS_W void Canny( InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false );
Fourth, the test code
#pragma once class BaseDeal { public: BaseDeal(); //image erosion void DealErode(std::string strFileName); //image is blurry void DealBlur(std::string strFileName); //image edge detection void DealCanny(std::string strFileName); };
#include "stdafx.h" #include "BaseDeal.h" BaseDeal::BaseDeal() { } void BaseDeal::DealErode(std::string strFileName) { Mat srcMat = imread(strFileName); imshow("Original image", srcMat); Mat matElement = getStructuringElement(MORPH_RECT, Size(15,15)); Mat destMat; erode (srcMat, destMat, matElement); imshow("腐蚀", destMat); waitKey(1000); } void BaseDeal::DealBlur(std::string strFileName) { Mat srcImage = imread (strFileName); imshow("Mean filter{original image}", srcImage); Mat destImage; blur (srcImage, destImage, Size (7,7)); imshow("Mean filter{effect image}", destImage); } void BaseDeal::DealCanny(std::string strFileName) { Mat srcImage = imread (strFileName); imshow("Original image{edge detection}", srcImage); Mat matEdge; //Edge Mat Mat matGrayImage;//Grayscale image Mat //Convert original image to grayscale image cvtColor(srcImage, matGrayImage, CV_RGB2GRAY/*CV_BayerRG2GRAY*/); //Use 3*3 kernel noise reduction blur(matGrayImage, matEdge, Size(3,3)); //Run CANNY operator Canny(matEdge, matEdge, 3,9,3); imshow("Edge detection renderings", matEdge); waitKey(1000); }
main function
#include "stdafx.h" #include "BaseDeal.h" intmain() { BaseDeal base; //base.DealErode("F:/1.jpg"); //base.DealBlur("F:/1.jpg"); base.DealCanny("F:/2.jpg"); waitKey(6000); }
result image
Image erosion:
Image is blurry:
Edge detection:
This is because
cvtColor(srcImage, matGrayImage, CV_BayerRG2GRAY); CV_BayerRG2GRAY>7, the program will crash, maybe this value is too large and the size of the image will become larger, the final result picture shows that only a small part of the edge detection is detected, and a large part is lost ;
Correct image result:
The cvtColor function has bugs in OpenCV, CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 ); The value of code cannot exceed 7, that is, the value of 8 will crash.