6 const std::array<int, 8>& box) {
8 srcimage.copyTo(image);
10 std::vector<std::vector<int>> points;
12 for (
int i = 0; i < 4; ++i) {
14 tmp.push_back(box[2 * i]);
15 tmp.push_back(box[2 * i + 1]);
16 points.push_back(tmp);
18 int x_collect[4] = {box[0], box[2], box[4], box[6]};
19 int y_collect[4] = {box[1], box[3], box[5], box[7]};
20 int left = int(*std::min_element(x_collect, x_collect + 4));
21 int right = int(*std::max_element(x_collect, x_collect + 4));
22 int top = int(*std::min_element(y_collect, y_collect + 4));
23 int bottom = int(*std::max_element(y_collect, y_collect + 4));
26 image(cv::Rect(left, top, right - left, bottom - top)).copyTo(img_crop);
28 for (
int i = 0; i < points.size(); i++) {
33 int img_crop_width = int(
sqrt(
pow(points[0][0] - points[1][0], 2) +
34 pow(points[0][1] - points[1][1], 2)));
35 int img_crop_height = int(
sqrt(
pow(points[0][0] - points[3][0], 2) +
36 pow(points[0][1] - points[3][1], 2)));
41 pts_std[2] =
cv::Point2f(img_crop_width, img_crop_height);
45 pointsf[0] =
cv::Point2f(points[0][0], points[0][1]);
46 pointsf[1] =
cv::Point2f(points[1][0], points[1][1]);
47 pointsf[2] =
cv::Point2f(points[2][0], points[2][1]);
48 pointsf[3] =
cv::Point2f(points[3][0], points[3][1]);
50 cv::Mat M = cv::getPerspectiveTransform(pointsf, pts_std);
53 cv::warpPerspective(img_crop, dst_img, M,
54 cv::Size(img_crop_width, img_crop_height),
55 cv::BORDER_REPLICATE);
57 if (
float(dst_img.rows) >=
float(dst_img.cols) * 1.5) {
58 cv::Mat srcCopy = cv::Mat(dst_img.rows, dst_img.cols, dst_img.depth());
60 cv::flip(srcCopy, srcCopy, 0);
cv::Mat GetRotateCropImage(const cv::Mat &srcimage, const std::array< int, 8 > &box)
base::Status pow(device::Tensor *input, device::Tensor *exponent, device::Tensor *output)
base::Status sqrt(device::Tensor *input, device::Tensor *output)
base::Status transpose(device::Tensor *input, std::shared_ptr< ir::TransposeParam > param, device::Tensor *output)