14끝
This commit is contained in:
63
ch14/corners/main.cpp
Normal file
63
ch14/corners/main.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <iostream>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void corner_harris() {
|
||||
Mat src = imread("../../resources/images/building.jpg", IMREAD_GRAYSCALE);
|
||||
|
||||
Mat harris;
|
||||
cornerHarris(src, harris, 3, 3, 0.04);
|
||||
|
||||
Mat harris_norm;
|
||||
normalize(harris, harris_norm, 0, 255, NORM_MINMAX, CV_8U);
|
||||
|
||||
Mat dst;
|
||||
cvtColor(src, dst, COLOR_GRAY2BGR);
|
||||
|
||||
for (int j = 1; j < harris.rows - 1; j++) {
|
||||
for (int i = 1; i < harris.cols - 1; i++) {
|
||||
if (harris_norm.at<char>(j, i) > 120) {
|
||||
if (harris.at<float>(j, i) > harris.at<float>(j - 1, i) &&
|
||||
harris.at<float>(j, i) > harris.at<float>(j + 1, i) &&
|
||||
harris.at<float>(j, i) > harris.at<float>(j, i - 1) &&
|
||||
harris.at<float>(j, i) > harris.at<float>(j, i + 1)) {
|
||||
circle(dst, Point(i, j), 5, Scalar(0, 0, 255), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imshow("src", src);
|
||||
imshow("harris_norm", harris_norm);
|
||||
imshow("dst", dst);
|
||||
|
||||
waitKey(0);
|
||||
destroyAllWindows();
|
||||
}
|
||||
|
||||
void corner_fast() {
|
||||
Mat src = imread("../../resources/images/building.jpg", IMREAD_GRAYSCALE);
|
||||
|
||||
vector<KeyPoint> keypoints;
|
||||
FAST(src, keypoints, 60, true);
|
||||
|
||||
Mat dst;
|
||||
cvtColor(src, dst, COLOR_GRAY2BGR);
|
||||
|
||||
for (KeyPoint kp : keypoints) {
|
||||
Point pt(cvRound(kp.pt.x), cvRound(kp.pt.y));
|
||||
circle(dst, pt, 5, Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
imshow("src", src);
|
||||
imshow("dst", dst);
|
||||
|
||||
waitKey(0);
|
||||
destroyAllWindows();
|
||||
}
|
||||
|
||||
int main() {
|
||||
corner_fast();
|
||||
}
|
||||
Reference in New Issue
Block a user