MCPcopy Create free account
hub / github.com/ShiqiYu/libfacedetection / main

Function main

example/detect-camera.cpp:47–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45using namespace cv;
46
47int main(int argc, char* argv[])
48{
49 if(argc != 2)
50 {
51 printf("Usage: %s <camera index>\n", argv[0]);
52 return -1;
53 }
54
55 int * pResults = NULL;
56 //pBuffer is used in the detection functions.
57 //If you call functions in multiple threads, please create one buffer for each thread!
58 unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
59 if(!pBuffer)
60 {
61 fprintf(stderr, "Can not alloc buffer.\n");
62 return -1;
63 }
64
65
66 VideoCapture cap;
67 Mat im;
68
69 if( isdigit(argv[1][0]))
70 {
71 cap.open(argv[1][0]-'0');
72 if(! cap.isOpened())
73 {
74 cerr << "Cannot open the camera." << endl;
75 return 0;
76 }
77 }
78
79 if( cap.isOpened())
80 {
81 while(true)
82 {
83 cap >> im;
84 //cout << "Image size: " << im.rows << "X" << im.cols << endl;
85 Mat image = im.clone();
86
87 ///////////////////////////////////////////
88 // CNN face detection
89 // Best detection rate
90 //////////////////////////////////////////
91 //!!! The input image must be a BGR one (three-channel) instead of RGB
92 //!!! DO NOT RELEASE pResults !!!
93 TickMeter cvtm;
94 cvtm.start();
95
96 pResults = facedetect_cnn(pBuffer, (unsigned char*)(image.ptr(0)), image.cols, image.rows, (int)image.step);
97
98 cvtm.stop();
99 printf("time = %gms\n", cvtm.getTimeMilli());
100
101 printf("%d faces detected.\n", (pResults ? *pResults : 0));
102 Mat result_image = image.clone();
103 //print the detection results
104 for(int i = 0; i < (pResults ? *pResults : 0); i++)

Callers

nothing calls this directly

Calls 2

ptrMethod · 0.80
facedetect_cnnFunction · 0.50

Tested by

no test coverage detected