-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect.cpp
68 lines (49 loc) · 1.46 KB
/
detect.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
59
60
61
62
63
64
65
66
67
68
#include<cv.h>
#include<highgui.h>
#include<cxcore.h>
//#include<stdio.h>
using namespace cv;
#define RAD 50
#define RAD_EPS 15
#define HIGH 80
#define LOW 70
int main()
{
cvNamedWindow("Vid",CV_WINDOW_AUTOSIZE);
CvCapture* detect=cvCreateCameraCapture(CV_CAP_ANY);
if(detect==NULL) return -1;
cvSetCaptureProperty(detect,CV_CAP_PROP_FRAME_HEIGHT,1280);
cvSetCaptureProperty(detect,CV_CAP_PROP_FRAME_WIDTH,1920);
CvArr* frame,*final,*copy,*ans;
char c;
CvMemStorage* str=cvCreateMemStorage(0);
CvSeq* circ;
frame=cvQueryFrame(detect);
copy=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
final=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
ans=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
while(1)
{
if(!frame)break;
cvCvtColor(frame,copy,CV_BGR2HSV);
cvInRangeS(copy,cvScalar(20,100,100),cvScalar(35,255,255),final);
cvDilate(final,final,NULL,1);
circ=cvHoughCircles(final,str,CV_HOUGH_GRADIENT,2,32.0,HIGH,LOW);
for( int i = 0; i < circ->total; i++ )
{
float* p = (float*) cvGetSeqElem( circ, i );
CvPoint pt = cvPoint( cvRound( p[0] ), cvRound( p[1] ) );
cvCircle(ans,pt,cvRound( p[2] ),CV_RGB(255,255,255),4);
}
cvShowImage("Vid",ans);
cvSet(ans,cvScalar(0,0,0));
c=cvWaitKey(20);
// cvSaveImage("p.jpg",final);
if(c==27)break;
// for(int i=0;i<10;i++)cvQueryFrame(detect);
frame=cvQueryFrame(detect);
}
cvDestroyWindow("Vid");
cvReleaseCapture(&detect);
return 0;
}