#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, char** argv) { Mat src, dst; src = imread("E:/opencv3.2/TestOpenCVInstall/Debug/Test.jpg"); if (!src.data) { printf("could not load image... "); return -1; } namedWindow("input image", CV_WINDOW_AUTOSIZE); imshow("input image", src); //medianBlur(src, dst, 3); bilateralFilter(src, dst, 15, 100, 5); namedWindow("BiBlur Filter Result", CV_WINDOW_AUTOSIZE); imshow("BiBlur Filter Result", dst); Mat resultImg; Mat kernel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); filter2D(dst, resultImg, -1, kernel, Point(-1, -1), 0); imshow("Final Result", resultImg); waitKey(0); return 0; }
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; Mat src, dst; char OUTPUT_WIN[] = "output image"; int element_size = 3; int max_size = 21; void CallBack_Demo(int, void*); int main(int argc, char** argv) { src = imread("E:/opencv3.2/TestOpenCVInstall/Debug/Test.jpg"); if (!src.data) { printf("could not load image... "); return -1; } namedWindow("input image", CV_WINDOW_AUTOSIZE); imshow("input image", src); namedWindow(OUTPUT_WIN, CV_WINDOW_AUTOSIZE); createTrackbar("Element Size :", OUTPUT_WIN, &element_size, max_size, CallBack_Demo); CallBack_Demo(0, 0); waitKey(0); return 0; } void CallBack_Demo(int, void*) { int s = element_size * 2 + 1; Mat structureElement = getStructuringElement(MORPH_RECT, Size(s, s), Point(-1, -1)); dilate(src, dst, structureElement, Point(-1, -1), 1); // erode(src, dst, structureElement); imshow(OUTPUT_WIN, dst); return; }
#include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespace cv; int main(int argc, char** argv) { Mat src, dst; src = imread("E:/opencv3.2/TestOpenCVInstall/Debug/openclose.png"); if (!src.data) { printf("could not load image... "); } namedWindow("input image", CV_WINDOW_AUTOSIZE); imshow("input image", src); char output_title[] = "morphology demo"; namedWindow(output_title, CV_WINDOW_AUTOSIZE); Mat kernel = getStructuringElement(MORPH_RECT, Size(11, 11), Point(-1, -1)); morphologyEx(src, dst, CV_MOP_OPEN, kernel); //开操作 /*morphologyEx(src, dst, CV_MOP_BLACKHAT, kernel);*/ //morphologyEx(src, dst, CV_MOP_TOPHAT, kernel); imshow(output_title, dst); waitKey(0); return 0; }