| 43 | } |
| 44 | |
| 45 | void project(const Template &src, Template &dst) const |
| 46 | { |
| 47 | dst = src; |
| 48 | |
| 49 | shape_predictor *const sp = shapeResource.acquire(); |
| 50 | |
| 51 | cv::Mat cvImage = src.m(); |
| 52 | if (cvImage.channels() == 3) |
| 53 | cv::cvtColor(cvImage, cvImage, CV_BGR2GRAY); |
| 54 | |
| 55 | cv_image<unsigned char> cimg(cvImage); |
| 56 | array2d<unsigned char> image; |
| 57 | assign_image(image,cimg); |
| 58 | |
| 59 | if (src.file.rects().isEmpty()) { //If the image has no rects assume the whole image is a face |
| 60 | rectangle r(0, 0, cvImage.cols, cvImage.rows); |
| 61 | full_object_detection shape = (*sp)(image, r); |
| 62 | for (size_t i = 0; i < shape.num_parts(); i++) |
| 63 | dst.file.appendPoint(QPointF(shape.part(i)(0),shape.part(i)(1))); |
| 64 | } |
| 65 | else { // Crop the image on the rects |
| 66 | for (int j=0; j<src.file.rects().size(); ++j) |
| 67 | { |
| 68 | QRectF rect = src.file.rects()[j]; |
| 69 | rectangle r(rect.left(),rect.top(),rect.right(),rect.bottom()); |
| 70 | full_object_detection shape = (*sp)(image, r); |
| 71 | for (size_t i=0; i<shape.num_parts(); i++) |
| 72 | dst.file.appendPoint(QPointF(shape.part(i)(0),shape.part(i)(1))); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | shapeResource.release(sp); |
| 77 | } |
| 78 | }; |
| 79 | |
| 80 | BR_REGISTER(Transform, DLandmarkerTransform) |