}\r
\r
namedWindow( "result", 1 ); \r
- Size fontSz = cv::getTextSize("T[]", FONT_HERSHEY_SIMPLEX, 1.0, 2, 0);\r
-\r
+ \r
Mat frame, frame_cpu, gray_cpu, resized_cpu, faces_downloaded, frameDisp;\r
vector<Rect> facesBuf_cpu;\r
\r
/* parameters */\r
bool useGPU = true;\r
double scale_factor = 1;\r
-\r
+ double font_scale = 0.8;\r
+ \r
bool visualizeInPlace = false; \r
bool findLargestObject = false; \r
+ int minNeighbors = 4;\r
\r
printf("\t<space> - toggle GPU/CPU\n");\r
printf("\tL - toggle lagest faces\n");\r
cascade_gpu.visualizeInPlace = visualizeInPlace; \r
cascade_gpu.findLargestObject = findLargestObject; \r
\r
- detections_num = cascade_gpu.detectMultiScale( resized_gpu, facesBuf_gpu ); \r
+ detections_num = cascade_gpu.detectMultiScale( resized_gpu, facesBuf_gpu, 1.2, minNeighbors); \r
facesBuf_gpu.colRange(0, detections_num).download(faces_downloaded);\r
\r
}\r
minSize = Size(cvRound(minSize.width * ratio), cvRound(minSize.height * ratio)); \r
}\r
\r
- cascade_cpu.detectMultiScale(resized_cpu, facesBuf_cpu, 1.2, 4, (findLargestObject ? CV_HAAR_FIND_BIGGEST_OBJECT : 0) | CV_HAAR_SCALE_IMAGE, minSize); \r
+ cascade_cpu.detectMultiScale(resized_cpu, facesBuf_cpu, 1.2, minNeighbors, (findLargestObject ? CV_HAAR_FIND_BIGGEST_OBJECT : 0) | CV_HAAR_SCALE_IMAGE, minSize); \r
detections_num = (int)facesBuf_cpu.size();\r
}\r
\r
cv::rectangle(resized_cpu, faces[i], Scalar(255)); \r
}\r
\r
- Point text_pos(5, 25);\r
- int offs = fontSz.height + 5;\r
- Scalar color = CV_RGB(255, 0, 0);\r
+ int tickness = font_scale > 0.75 ? 2 : 1;\r
\r
+ Point text_pos(5, 25); \r
+ Scalar color = CV_RGB(255, 0, 0);\r
+ Size fontSz = cv::getTextSize("T[]", FONT_HERSHEY_SIMPLEX, font_scale, tickness, 0);\r
+ int offs = fontSz.height + 5;\r
\r
cv::cvtColor(resized_cpu, frameDisp, CV_GRAY2BGR);\r
\r
char buf[4096];\r
- sprintf(buf, "%s, FPS = %0.3g", useGPU ? "GPU" : "CPU", 1.0/tm.getTimeSec()); \r
- putText(frameDisp, buf, text_pos, FONT_HERSHEY_SIMPLEX, 1.0, color, 2);\r
- sprintf(buf, "scale = %0.3g, [%d*scale x %d*scale]", scale_factor, frame.cols, frame.rows); \r
- putText(frameDisp, buf, text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, 1.0, color, 2);\r
- putText(frameDisp, "Hotkeys: space, 1, Q, L, V, Esc", text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, 1.0, color, 2);\r
+ sprintf(buf, "%s, FPS = %0.3g", useGPU ? "GPU (device) " : "CPU (host)", 1.0/tm.getTimeSec()); \r
+ putText(frameDisp, buf, text_pos, FONT_HERSHEY_SIMPLEX, font_scale, color, tickness);\r
+ sprintf(buf, "scale = %0.3g, [%d x %d] x scale, Min neighbors = %d", scale_factor, frame.cols, frame.rows, minNeighbors); \r
+ putText(frameDisp, buf, text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, font_scale, color, tickness);\r
+ putText(frameDisp, "Hotkeys: space, 1/Q, 2/E, 3/E, L, V, Esc", text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, font_scale, color, tickness);\r
\r
if (findLargestObject)\r
- putText(frameDisp, "FindLargestObject", text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, 1.0, color, 2);\r
+ putText(frameDisp, "FindLargestObject", text_pos+=Point(0,offs), FONT_HERSHEY_SIMPLEX, font_scale, color, tickness);\r
\r
if (visualizeInPlace && useGPU)\r
- putText(frameDisp, "VisualizeInPlace", text_pos+Point(0,offs), FONT_HERSHEY_SIMPLEX, 1.0, color, 2);\r
+ putText(frameDisp, "VisualizeInPlace", text_pos+Point(0,offs), FONT_HERSHEY_SIMPLEX, font_scale, color, tickness);\r
\r
cv::imshow( "result", frameDisp);\r
\r
if( key == 27)\r
break;\r
\r
- switch (key)\r
+ switch ((char)key)\r
{\r
- case (int)' ': useGPU = !useGPU; printf("Using %s\n", useGPU ? "GPU" : "CPU");break;\r
- case (int)'v': case (int)'V': visualizeInPlace = !visualizeInPlace; printf("VisualizeInPlace = %d\n", visualizeInPlace); break;\r
- case (int)'l': case (int)'L': findLargestObject = !findLargestObject; printf("FindLargestObject = %d\n", findLargestObject); break;\r
- case (int)'1': scale_factor*=1.05; printf("Scale factor = %g\n", scale_factor); break;\r
- case (int)'q': case (int)'Q':scale_factor/=1.05; printf("Scale factor = %g\n", scale_factor); break;\r
+ case ' ': useGPU = !useGPU; printf("Using %s\n", useGPU ? "GPU" : "CPU");break;\r
+ case 'v': case 'V': visualizeInPlace = !visualizeInPlace; printf("VisualizeInPlace = %d\n", visualizeInPlace); break;\r
+ case 'l': case 'L': findLargestObject = !findLargestObject; printf("FindLargestObject = %d\n", findLargestObject); break;\r
+ case '1': scale_factor*=1.05; printf("Scale factor = %g\n", scale_factor); break;\r
+ case 'q': case 'Q':scale_factor/=1.05; printf("Scale factor = %g\n", scale_factor); break;\r
+\r
+ case '3': font_scale*=1.05; printf("Fond scale = %g\n", font_scale); break;\r
+ case 'e': case 'E':font_scale/=1.05; printf("Fond scale = %g\n", font_scale); break;\r
+\r
+ case '2': ++minNeighbors; printf("Min Neighbors = %g\n", minNeighbors); break;\r
+ case 'w': case 'W':minNeighbors = max(minNeighbors-1, 0); printf("Min Neighbors = %g\n", minNeighbors); break;\r
}\r
\r
} \r