| 14 | using namespace cv; |
| 15 | |
| 16 | int main(int argc, char* argv[]) |
| 17 | { |
| 18 | if (argc != 2) |
| 19 | { |
| 20 | printf("Usage: %s <image_file_name>\n", argv[0]); |
| 21 | return -1; |
| 22 | } |
| 23 | //load an image and convert it to gray (single-channel) |
| 24 | Mat image = imread(argv[1]); |
| 25 | if (image.empty()) |
| 26 | { |
| 27 | fprintf(stderr, "Can not load the image file %s.\n", argv[1]); |
| 28 | return -1; |
| 29 | } |
| 30 | |
| 31 | #ifdef _OPENMP |
| 32 | int num_thread = omp_get_num_procs(); |
| 33 | omp_set_num_threads(num_thread); |
| 34 | printf("There are %d threads, %d processors.\n", num_thread, omp_get_num_procs()); |
| 35 | #else |
| 36 | int num_thread = 1; |
| 37 | printf("There is %d thread.\n", num_thread); |
| 38 | #endif |
| 39 | |
| 40 | int * pResults = NULL; |
| 41 | unsigned char * pBuffers[1024];//large enough |
| 42 | |
| 43 | //pBuffer is used in the detection functions. |
| 44 | //If you call functions in multiple threads, please create one buffer for each thread! |
| 45 | unsigned char * p = (unsigned char *)malloc(DETECT_BUFFER_SIZE * num_thread); |
| 46 | if (!p) |
| 47 | { |
| 48 | fprintf(stderr, "Can not alloc buffer.\n"); |
| 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | for (int i = 0; i < num_thread; i++) |
| 53 | pBuffers[i] = p + (DETECT_BUFFER_SIZE)*i; |
| 54 | |
| 55 | int total_count = 256; |
| 56 | |
| 57 | pResults = facedetect_cnn(pBuffers[0], image.ptr<unsigned char>(0), (int)image.cols, (int)image.rows, (int)image.step); |
| 58 | |
| 59 | TickMeter tm; |
| 60 | tm.start(); |
| 61 | #ifdef _OPENMP |
| 62 | #pragma omp parallel for |
| 63 | #endif |
| 64 | for (int i = 0; i < total_count; i++) |
| 65 | { |
| 66 | #ifdef _OPENMP |
| 67 | int idx = omp_get_thread_num(); |
| 68 | #else |
| 69 | int idx = 0; |
| 70 | #endif |
| 71 | pResults = facedetect_cnn(pBuffers[idx], image.ptr<unsigned char>(0), (int)image.cols, (int)image.rows, (int)image.step); |
| 72 | } |
| 73 | tm.stop(); |
nothing calls this directly
no test coverage detected