1 | initial version |
the problem is here:
Mat dst = _dst.getMat();
dst is a copy , it is not synched with _dst, as you expected. instead, you should work with _dst:
void rotate(InputArray _src, OutputArray _dst, double angle,bool bKeepOldSize = false)
{
Mat src = _src.getMat();
Point2f pt(src.cols/2., src.rows/2.);
Mat r = getRotationMatrix2D(pt, angle, 1.0);
Size ImgSize = Size(src.cols, src.rows);
//Calculate the new image size if required
cv::Rect bbox = cv::RotatedRect(pt,src.size(), angle).boundingRect();
if(bKeepOldSize == false)
{
// adjust transformation matrix and destination matrix
r.at<double>(0,2) += bbox.width/2.0 - pt.x;
r.at<double>(1,2) += bbox.height/2.0 - pt.y;
ImgSize = bbox.size();
_dst.create(ImgSize,src.type()); // allocate larger Mat here
}
// pass it to warpAffine:
warpAffine(src, _dst, r, ImgSize,INTER_LANCZOS4,BORDER_CONSTANT,Scalar(0));
}
// test code:
int main()
{
Mat letters = imread("deskew.jpg",0);
threshold(letters,letters,128,255,CV_THRESH_BINARY);
Mat output;
rotate(letters,output,-8.0);
imwrite("output.png",output);
cerr << output.size() << endl;
return 0;
}
// cönsöle output:
[676 x 379]