-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurf.cpp
58 lines (44 loc) · 1.32 KB
/
surf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Saugat Malla
Project 4
*/
/*
Code for Task 7
*/
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp> // Include this for SURF
using namespace cv;
using namespace cv::xfeatures2d; // Add this namespace for SURF
using namespace std;
int main() {
// Open webcam
VideoCapture cap(0);
if (!cap.isOpened()) {
cerr << "Error: Couldn't access the webcam." << endl;
return -1;
}
Mat frame, frame_gray;
vector<KeyPoint> keypoints;
Mat descriptors;
Ptr<Feature2D> surf = SURF::create(); // Initialize SURF detector
namedWindow("SURF Feature Detection", WINDOW_NORMAL);
while (true) {
cap >> frame; // Capture frame from webcam
// Convert frame to grayscale
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
// Detect SURF keypoints and compute descriptors
surf->detectAndCompute(frame_gray, Mat(), keypoints, descriptors);
// Draw keypoints on the original image
Mat surf_keypoints;
drawKeypoints(frame, keypoints, surf_keypoints);
// Display the resulting frame
imshow("SURF Feature Detection", surf_keypoints);
// Exit when 'q' is pressed
if (waitKey(1) == 'q')
break;
}
// Release the camera
cap.release();
destroyAllWindows();
return 0;
}