fanfuhan OpenCV 教學027 ~ opencv-027-邊緣保留濾波算法(EPF)–均值遷移模糊(mean-shift blur)

fanfuhan OpenCV 教學027 ~ opencv-027-邊緣保留濾波算法(EPF)–均值遷移模糊(mean-shift blur)

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 <iostream>
#include <opencv2/opencv.hpp>

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()

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *