c++ - What box to use when cropping a rotated image in opencv -
i have rotated image , want crop borders cut out , full cropped image viewable. tried method found on net didn't work , honest don't understand trying do. understand rotating part. points pushing points? 4 corners of image? method of pushing points not work me. used 4 corners of image instead worked rotating when try run getrectsubpix exception occurs because box wrong i'm not sure getrectsubpix needs then?
here output after running code. output iverted (why important?) , crop doesn't work.
cv::bitwise_not(img, img); std::vector<cv::point> points; cv::mat_<uchar>::iterator = img.begin<uchar>(); cv::mat_<uchar>::iterator end = img.end<uchar>(); (; != end; ++it) if (*it) points.push_back(it.pos()); cv::rotatedrect box = cv::minarearect(cv::mat(points)); cv::mat rot_mat = cv::getrotationmatrix2d(box.center, angle, 1); cv::mat rotated; cv::warpaffine(img, rotated, rot_mat, img.size(), cv::inter_cubic); cv::size box_size = box.size; if (box.angle < -45.) std::swap(box_size.width, box_size.height); cv::mat cropped; cv::getrectsubpix(rotated, box_size, box.center, cropped);
Comments
Post a Comment