提取图片中人脸特征点
提取图片中人脸特征点
//提取图片中人脸特征点 QVector<cv::Point> facedetect_frontal_surveillance5(cv::Mat imageParam) { QVector<cv::Point> vec_pointsParam; cv::resize(imageParam, imageParam, cv::Size(600, 600)); cv::Mat img_result1 = cv::Mat(imageParam.size(), imageParam.type()); pBuffer3 = (unsigned char *)malloc(DETECT_BUFFER_SIZE); if (!pBuffer3) { fprintf(stderr, "Can not alloc buffer.\n"); return vec_pointsParam; } //vec_pointsParam = facedetect_frontal_surveillance4(imgParam, winName); int w1 = imageParam.cols; int h1 = imageParam.rows; cv::Mat gray; cv::cvtColor(imageParam, gray, CV_BGR2GRAY); int min_obj_width = 8; float scale1 = 1.1f; int min_neightbors1 = 2; int * pResults = NULL; //pBuffer is used in the detection functions. //pBuffer指针用于检测函数。 //If you call functions in multiple threads, please create one buffer for each thread! //如果您在多个线程中调用函数,请为每个线程创建一个缓冲区! int doLandmark = 2; /////////////////////////////////////////// // frontal face detection designed for video surveillance / 68 landmark detection //正面人脸检测专为视频监控/ 68标志性检测而设计 // it can detect faces with bad illumination. //它可以检测到不良照明的面部。 ////////////////////////////////////////// //!!! The input image must be a gray one (single-channel) //!!! DO NOT RELEASE pResults !!! pResults = facedetect_frontal_surveillance(pBuffer3, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step, scale1, min_neightbors1, min_obj_width, 0, doLandmark); //printf("%d faces detected.\n", (pResults ? *pResults : 0)); cv::Mat result_frontal_surveillance = imageParam.clone();; //print the detection results int heightParam2 = 0; int widthParam2 = 0; for (int i = 0; i < (pResults ? *pResults : 0); i++) { short * p = ((short*)(pResults + 1)) + 142 * i; int x = p[0]; int y = p[1]; int w = p[2]; int h = p[3]; int neighbors = p[4]; int angle = p[5]; printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x, y, w, h, neighbors, angle); rectangle(result_frontal_surveillance, cv::Rect(x, y, w, h), cv::Scalar(0, 255, 0), 2); if (doLandmark) { std::cout << ""; for (int j = 0; j < 68; j++) { int x1 = (int)p[6 + 2 * j]; int y1 = (int)p[6 + 2 * j + 1]; std::cout << " (" << x1 << "," << y1 << ") "; //circle(result_frontal_surveillance, cv::Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, cv::Scalar(0, 255, 0)); circle(result_frontal_surveillance, cv::Point(x1, y1), 1, cv::Scalar(0, 255, 0)); cv::Point point_index; point_index.x = x1; point_index.y = y1; vec_pointsParam.append(point_index); } std::cout << "" << std::endl; } //face_img = cv::Mat(index_img,index_img.type(),1,) //face_img = cv_img::copyRectangle(index_img, y, x, w, h); } free(pBuffer3); return vec_pointsParam; }
QQ 3087438119