-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample6.cpp
More file actions
63 lines (48 loc) · 1.5 KB
/
Copy pathexample6.cpp
File metadata and controls
63 lines (48 loc) · 1.5 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
57
58
59
60
61
62
63
// Hough
#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);
int main()
{
cv::Mat img;
cv::cuda::GpuMat imgGpu, gray, circlesGpu;
std::vector<cv::Vec3f> circles;
while(cap.isOpened()) {
cap.read(img);
imgGpu.upload(img);
cv::cuda::cvtColor(imgGpu, gray, cv::COLOR_BGR2GRAY);
// Image Filtering
auto gaussianFilter = cv::cuda::createGaussianFilter(CV_8UC1, CV_8UC1, {3,3}, 1);
gaussianFilter->apply(gray, gray);
// Circle Detector
auto circleDetection = cv::cuda::createHoughCirclesDetector(1, 100, 120, 50, 1, 50, 5);
circleDetection->detect(gray, circlesGpu);
circles.resize(circlesGpu.size().width);
if(!circles.empty()) {
circlesGpu.row(0).download(cv::Mat(circles).reshape(3,1));
}
for(size_t i=0; i < circles.size();i++)
{
int r = rng.uniform(0,255);
int g = rng.uniform(0, 255);
int b = rng.uniform(0,255);
cv::Vec3i cir = circles[i];
circle(img, cv::Point(cir[0], cir[1]), cir[2], cv::Scalar(b,g,r), 2, cv::LINE_AA);
}
imshow("Image", img);
if(cv::waitKey(1) =='q') break;
}
cap.release();
return 0;
}