| 166 | } |
| 167 | |
| 168 | void FaceRoiAndDetectorParameter( // get ROI around the face, rotate if necessary |
| 169 | Image& face_roi, // out |
| 170 | DetectorParameter& detpar_roi, // out: detpar wrt the ROI |
| 171 | const Image& img, // in: original image |
| 172 | const DetectorParameter& detpar, // in: wrt img frame, only x,y,w,h,rot used |
| 173 | bool flip, // in: mirror the ROI? |
| 174 | double botfrac, // in: default ROI_FRAC |
| 175 | double leftfrac, // in: dist from center to left margin |
| 176 | double topfrac, // in |
| 177 | double rightfrac) // in |
| 178 | { |
| 179 | Rect rect_roi = RoiRect(detpar, img.cols, img.rows, flip, |
| 180 | botfrac, leftfrac, topfrac, rightfrac); |
| 181 | |
| 182 | detpar_roi = ImgDetParToRoiFrame(detpar, rect_roi); |
| 183 | |
| 184 | // following "if"s are for efficiency (avoid rotation etc. when possible). |
| 185 | |
| 186 | if (detpar.rot == 0 && IsRoiEntireImg(rect_roi, img.cols, img.rows)) |
| 187 | face_roi = img; |
| 188 | |
| 189 | else if (!Valid(detpar.rot) || detpar.rot == 0) |
| 190 | face_roi = Image(img, rect_roi); |
| 191 | |
| 192 | else // rotate image so face is upright, results go into face_roi |
| 193 | warpAffine(Image(img, rect_roi), face_roi, |
| 194 | getRotationMatrix2D(cv::Point2f(float(detpar_roi.x), |
| 195 | float(detpar_roi.y)), |
| 196 | -detpar.rot, 1.), |
| 197 | cv::Size(face_roi.cols, face_roi.rows), |
| 198 | cv::INTER_AREA, cv::BORDER_REPLICATE); |
| 199 | |
| 200 | // TODO For efficiency could combine this flip with above rot img when possible? |
| 201 | if (flip) |
| 202 | FlipImgInPlace(face_roi); |
| 203 | } |
| 204 | |
| 205 | } // namespace stasm |
no test coverage detected