int perImgProcessing(const Mat img, const string faceDetectModel, const string detectionModelPath, const string trackingModelPath, const float ec_mc_y, const float ec_y, vecM &result) { // face detection #if OPENCV FACE_HANDLE face_detection_handle; int ret_fd_init = getDetectionHandle(&face_detection_handle, faceDetectModel); if(0 != ret_fd_init || NULL == &face_detection_handle) { cout << "Error init for face alignment!" << endl; return -1; } vecR rect; string error; int ret_fd = detectFace(face_detection_handle, img, rect, error); if(0 != ret_fd) { cout << error <<endl; return -1; } #else #endif // face alignment FACE_HANDLE face_alignment_handle; int ret_fa = getAlignmentHandle(&face_alignment_handle, detectionModelPath, trackingModelPath); if(0 != ret_fa || NULL == face_alignment_handle) { cout << "Error init for face alignment!" << endl; return -1; } for(int i = 0; i < rect.size(); ++i) { Mat temp; faceAlignment(face_alignment_handle, img, rect[i], ec_mc_y, ec_y, temp, error); /*if(0 != ret) { cout << error << endl; continue; }*/ result.push_back(temp); } releaseDetectionHandle(&face_detection_handle); releaseAlignmentHandle(&face_alignment_handle); return 0; }
// load format(imgW, i) and add information to the back of imgs and lens void CmIllustr::LoadImgs(CStr &imgW, vecM &imgs, vecD &lens, int W, int H) { bool toRow = W > H; double crnt = -space; if (imgs.size()){ // There exist a predefined image for sketch lens.push_back(toRow ? H*imgs[0].cols*1./imgs[0].rows : W*imgs[0].rows*1./imgs[0].cols); crnt += lens[0] + space; } for (int i = 0; i < 500; i++){ string imgN = format(_S(imgW), i), inDir, maskN; vecS names; int subN = CmFile::GetNames(imgN, names, inDir); if (subN == 0) continue; Mat img = imread(inDir + names[0]); if (img.data == NULL){ printf("Can't load image file %-70s\n", _S(names[0])); continue; } if (subN > 1){ Mat mask1u = imread(inDir + names[1], CV_LOAD_IMAGE_GRAYSCALE), big1u; dilate(mask1u, big1u, Mat(), Point(-1, -1), 5); bitwise_xor(mask1u, big1u, mask1u); img.setTo(Scalar(0, 0, 255), mask1u); } lens.push_back(toRow ? H*img.cols*1./img.rows : W*img.rows*1./img.cols); imgs.push_back(img); crnt += lens[lens.size() - 1] + space; if (crnt >= max(H, W)) break; } int num = imgs.size(); if (num && abs(crnt - max(H,W)) > abs(crnt - lens[num - 1] - space - max(H,W))) imgs.resize(num - 1), lens.resize(num - 1); printf("%s: %d\n", _S(imgW), num); if (crnt < max(H, W)) { printf(_S(imgW + ": not enough images\n")); exit(0); } }