Rectangle rec=new Rectangle ();
rec.X = 215;
rec.Width = 40;
rec.Height = 40;
rec.Y = 245;
Mat roi= CvInvoke.Imread("D:\\212.bmp", 0);
Mat qq = new Mat(roi, rec);
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
CvInvoke.Threshold(qq, qq, 100, 255, ThresholdType.Binary);
CvInvoke.FindContours(qq, contours, null, RetrType.Ccomp, ChainApproxMethod.ChainApproxSimple);
Mat qq1 = CvInvoke.Imread("D:\\212.bmp",0);
Size s = new Size();
s.Height = 500; s.Width = 500;
Mat qq2 = Mat.Zeros(qq.Rows, qq.Cols, qq.Depth, qq.NumberOfChannels);
CvInvoke.DrawContours(qq2, contours, 1, new MCvScalar(255, 255, 255), 1);
// CvInvoke.DrawContours(qq2, contours,1,new MCvScalar(255,0,255),1);
Rectangle r= CvInvoke.BoundingRectangle(contours[1]);
CvInvoke.Rectangle(qq2, r, new MCvScalar(255, 255, 255),1);
xuanzhuan1(qq2, ref qq2);
imageBox1.Image = qq2;
RotatedRect c= CvInvoke.MinAreaRect(contours[1]);
double angle = c.Angle;//旋转角度