public static void test(string img)
{
Mat src = CvInvoke.Imread(img);
Mat mask = new Mat();
CvInvoke.Canny(src, mask, 20, 40);
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
VectorOfRect hierarchy = new VectorOfRect();
CvInvoke.FindContours(mask, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxNone);
for (int i = 0; i < contours.Size; i++)
{
Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);
if (rect.Width < 500 || rect.Height < 1)
continue;
else
{
CvInvoke.Rectangle(src, rect, new MCvScalar(0, 0, 255), 1);
double angle = Math.Atan2(rect.Height, rect.Width);//0.20708893595777478
double theta = angle * (180 / Math.PI);
Image<Bgra, byte> Imga1 = new Image<Bgra, byte>(img);
Image<Bgra, byte> ss = Imga1.Rotate(-theta, new PointF(0, 0), Inter.Cubic, new Bgra(0, 0, 0, 0), false);
}
}
}