mirror of
https://github.com/zebrajr/opencv.git
synced 2026-01-15 12:15:17 +00:00
HitMiss tutorial
This commit is contained in:
32
samples/cpp/tutorial_code/ImgProc/HitMiss.cpp
Normal file
32
samples/cpp/tutorial_code/ImgProc/HitMiss.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(){
|
||||
Mat input_image = (Mat_<uchar>(8, 8) <<
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 255, 255, 255, 0, 0, 0, 255,
|
||||
0, 255, 255, 255, 0, 0, 0, 0,
|
||||
0, 255, 255, 255, 0, 255, 0, 0,
|
||||
0, 0, 255, 0, 0, 0, 0, 0,
|
||||
0, 0, 255, 0, 0, 255, 255, 0,
|
||||
0, 255, 0, 255, 0, 0, 255, 0,
|
||||
0, 255, 255, 255, 0, 0, 0, 0);
|
||||
|
||||
Mat kernel = (Mat_<uchar>(3, 3) <<
|
||||
0, 1, 0,
|
||||
1, -1, 1,
|
||||
0, 1, 0);
|
||||
|
||||
Mat output_image;
|
||||
morphologyEx(input_image, output_image, MORPH_HITMISS, kernel);
|
||||
|
||||
namedWindow("Original", CV_WINDOW_NORMAL);
|
||||
imshow("Original", input_image);
|
||||
namedWindow("Hit or Miss", CV_WINDOW_NORMAL);
|
||||
imshow("Hit or Miss", output_image);
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user