#python code
import cv2
import numpy as np
def filter_embossing():
src = cv2.imread("D:\\projects\\SampleCode\\006939-master\\ch07\\blurring\\rose.bmp", cv2.IMREAD_GRAYSCALE)
if src is None:
print("Image load failed!")
return
data = np.array([[-1, -1, 0],
[-1, 0, 1],
[ 0, 1, 1]], dtype=np.float32)
dst = cv2.filter2D(src, -1, data, delta=128)
cv2.imshow("src", src)
cv2.imshow("dst", dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
def main():
filter_embossing()
if __name__ == "__main__":
main()
// C++ code
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
void filter_embossing();
int main(void)
{
filter_embossing();
return 0;
}
void filter_embossing()
{
Mat src = imread("rose.bmp", IMREAD_GRAYSCALE);
if (src.empty()) {
cerr << "Image load failed!" << endl;
return;
}
float data[] = { -1, -1, 0, -1, 0, 1, 0, 1, 1 };
Mat emboss(3, 3, CV_32FC1, data);
Mat dst;
filter2D(src, dst, -1, emboss, Point(-1, -1), 128);
imshow("src", src);
imshow("dst", dst);
waitKey();
destroyAllWindows();
}
C++ Code 출처 : OpenCV 4로 배우는 컴퓨터 비전과 머신 러닝 - 황선규 저

'OpenCV' 카테고리의 다른 글
ch07 sharpen (0) | 2024.05.20 |
---|---|
ch07 noise (0) | 2024.05.20 |
ch07 blurring (0) | 2024.05.20 |
ch06 logical (0) | 2024.05.20 |
ch06 arithmetic (0) | 2024.05.20 |