fanfuhan OpenCV 教学027 ~ opencv-027-边缘保留滤波算法(EPF)–均值迁移模糊(mean-shift blur) – jashliao部落格
fanfuhan OpenCV 教学027 ~ opencv-027-边缘保留滤波算法(EPF)–均值迁移模糊(mean-shift blur)
资料来源: https://fanfuhan.github.io/
https://fanfuhan.github.io/2019/04/07/opencv-027/
GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV
C++
#include#include using namespace std; using namespace cv; /* * 均值迁移模糊 */ int main() { Mat src = imread("../images/test.png"); if (src.empty()) { cout << "could not load image.." << endl; } imshow("input", src); Mat dst; pyrMeanShiftFiltering(src, dst, 15, 30); imshow("mean_shift_blur", dst); waitKey(0); return 0; }
Python
import cv2 as cv import numpy as np src = cv.imread("D:/images/example.png") cv.namedWindow("input", cv.WINDOW_AUTOSIZE) cv.imshow("input", src) h, w = src.shape[:2] dst = cv.pyrMeanShiftFiltering(src, 15, 30, termcrit=(cv.TERM_CRITERIA_MAX_ITER+cv.TERM_CRITERIA_EPS, 5, 1)) result = np.zeros([h, w*2, 3], dtype=src.dtype) result[0:h,0:w,:] = src result[0:h,w:2*w,:] = dst cv.imshow("result", result) cv.imwrite("D:/result.png", result) cv.waitKey(0) cv.destroyAllWindows()