-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample5.cpp
More file actions
56 lines (41 loc) · 1.29 KB
/
Copy pathexample5.cpp
File metadata and controls
56 lines (41 loc) · 1.29 KB
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
// Corner Detection
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudafilters.hpp>
#include <opencv2/cudabgsegm.hpp>
#include <opencv2/cudaobjdetect.hpp>
#include <opencv2/cudaoptflow.hpp>
#include <opencv2/cudastereo.hpp>
#include <opencv2/cudafeatures2d.hpp>
cv::VideoCapture cap(0);
cv::RNG rng(12345); // random number
int main(int argc, char** argv)
{
cv::cuda::printCudaDeviceInfo(0);
cv::Mat img, corners;
cv::cuda::GpuMat imgGpu, gray, cornersGpu;
while(cap.isOpened()) {
cap.read(img);
imgGpu.upload(img);
cv::cuda::cvtColor(imgGpu, gray, cv::COLOR_BGR2GRAY);
auto cornerDetector =
cv::cuda::createGoodFeaturesToTrackDetector(gray.type(), 100, 0.01, 10, 3, true);
cornerDetector->detect(gray, cornersGpu);
cornersGpu.download(corners);
for(int i=0; i<corners.cols;++i) {
int r = rng.uniform(0,255);
int g = rng.uniform(0,255);
int b = rng.uniform(0,255);
cv::Point2f point = corners.at<cv::Point2f>(0, i);
circle(img, point, 6, cv::Scalar(b,g,r), 2, 8);
}
imshow("Image", img);
if(cv::waitKey(1) == 'q') break;
}
cap.release();
return 0;
}