本文整理汇总了C#中Image.Rotate方法的典型用法代码示例。如果您正苦于以下问题:C# Image.Rotate方法的具体用法?C# Image.Rotate怎么用?C# Image.Rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.Rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: imgSelector_SelectionChanged
void imgSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
FileInfo fio = imgSelector.SelectedItem as FileInfo;
Image<Bgr, Byte> srcImg = new Image<Bgr, byte>(fio.FullName);
int scale = 3;
NxConsole.Print(ConsoleColor.Green,
string.Format("[{0,5}ms] Image {1}:{2}*{3} loaded.", sw.Elapsed.Milliseconds, fio.Name, srcImg.Width, srcImg.Height));
;
setImage("imgProc0", GetBitmapSource(srcImg), "Origin");
NxConsole.Print(ConsoleColor.Green,
string.Format("[{0,5}ms] Finished rendering Origin.", sw.Elapsed.Milliseconds));
setImage("imgProc1", GetBitmapSource(srcImg.Rotate(90, new Bgr(System.Drawing.Color.GhostWhite))), "Nearest Neighbor");
NxConsole.Print(ConsoleColor.Green,
string.Format("[{0,5}ms] Finished rendering proc1.", sw.Elapsed.Milliseconds));
setImage("imgProc2", GetBitmapSource(srcImg.Rotate(180, new Bgr(System.Drawing.Color.GhostWhite))), "Bilinear");
NxConsole.Print(ConsoleColor.Green,
string.Format("[{0,5}ms] Finished rendering proc2.", sw.Elapsed.Milliseconds));
setImage("imgProc3", GetBitmapSource(srcImg.Rotate(270, new Bgr(System.Drawing.Color.GhostWhite))), "Cubic");
NxConsole.Print(ConsoleColor.Green,
string.Format("[{0,5}ms] Finished rendering proc3.", sw.Elapsed.Milliseconds));
}
示例2: ContainsFaces
public static bool ContainsFaces(Bitmap bitmap)
{
using (var img = new Image<Gray, byte>(bitmap))
{
bool rotate;
if (ContainsFaces(img, true, out rotate))
return true;
else if (!rotate)
return false;
var rotatedimg1 = img.Rotate(10, new Gray());
if (ContainsFaces(img, false, out rotate))
return true;
else if (!rotate)
return false;
rotatedimg1 = img.Rotate(-10, new Gray());
if (ContainsFaces(img, false, out rotate))
return true;
return false;
}
}
示例3: GetImage
public Bitmap GetImage()
{
viewer.Image = capture.QueryFrame();
img = (Image<Bgr, Byte>)viewer.Image;
img = img.Rotate(Config.Angle, new Bgr(255, 255, 255), false);
img.ROI = Config.Rect;
return img.ToBitmap();
}
示例4: TestOCREngGrayText
public void TestOCREngGrayText()
{
using (Tesseract ocr = GetTesseract())
using (Image<Gray, Byte> img = new Image<Gray, byte>(480, 200))
{
ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,");
IntPtr oclDevice = new IntPtr();
int deviceId = ocr.GetOpenCLDevice(ref oclDevice);
String message = "Hello, World";
CvInvoke.PutText(img, message, new Point(50, 100), CvEnum.FontFace.HersheySimplex, 1.0, new MCvScalar(255));
//
//ocr.Recognize(img);
using (Image<Gray, Byte> rotatedImg = img.Rotate(10, new Gray(), false))
{
ocr.PageSegMode = PageSegMode.AutoOsd;
ocr.Recognize(rotatedImg);
using (PageIterator pi = ocr.AnalyseLayout())
{
Orientation or = pi.Orientation;
LineSegment2D? baseLine = pi.GetBaseLine(PageIteratorLevel.Textline);
if (baseLine.HasValue)
{
CvInvoke.Line(rotatedImg, baseLine.Value.P1, baseLine.Value.P2, new MCvScalar(255));
//Emgu.CV.UI.ImageViewer.Show(rotatedImg);
}
}
/*
String messageOcr = ocr.GetText().TrimEnd('\n', '\r'); // remove end of line from ocr-ed text
EmguAssert.AreEqual(message, messageOcr,
String.Format("'{0}' is not equal to '{1}'", message, messageOcr));
Tesseract.Character[] results = ocr.GetCharacters();*/
}
}
}
示例5: _testMorphological
private Image<Gray, Single> _testMorphological(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration, int cols, int rows, int anchorX, int anchorY, int shape)
{
img = img.Sobel(0, 1, 3);
StructuringElementEx element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT); ;
if (shape == 1)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
else if (shape == 2)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(255));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
return img;
}
示例6: _testSobelParameters
public void _testSobelParameters(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration, int cols, int rows, int anchorX, int anchorY, int shape)
{
int xOrder = 0, yOrder = 0, appetureSize = 1;
for (appetureSize = 3; appetureSize < 8; appetureSize += 2)
{
for (xOrder = 0; xOrder < appetureSize-1; xOrder++)
for (yOrder = 0; yOrder < appetureSize-1; yOrder++)
{
img = img.Sobel(xOrder, yOrder, appetureSize);
StructuringElementEx element;
if (shape == 0)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
else if (shape == 1)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
else
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(255));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
img.Bitmap.Save(@"Sobel\" + xOrder + " " + yOrder + " " + appetureSize + ".png");
}
}
}
示例7: _imageProcessing
/// <summary>
///
/// </summary>
/// <param name="img">Input Image</param>
/// <param name="threshold">Threshold value (with 8-bit image is from 0 to 255)</param>
/// <param name="maxGrayVal">Maximum Gray Value</param>
/// <param name="closingIteration">number of Iterations</param>
/// <returns>Processed Image</returns>
public Image<Gray, Single> _imageProcessing(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration)
{
img = img.Sobel(0, 1, 3);
StructuringElementEx element = new StructuringElementEx(3, 3, -1, -1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(maxGrayVal));
}
else
{
//MessageBox.Show("Threshold is not appropriate, please choose another!");
throw new ArgumentOutOfRangeException("Threshold is not appropriate, please choose another threshold value!");
}
return img;
}
示例8: HoughTransform
/// <summary>
/// Calculate Hough Transform Plane
/// </summary>
/// <param name="img"></param>
/// <param name="angleSpacing">Radians</param>
/// <param name="minAngle">Radians</param>
/// <param name="maxAngle">Radians</param>
/// <returns></returns>
internal static Image<Gray, float> HoughTransform(Image<Gray, byte> img, float angleSpacing, float minAngle, float maxAngle)
{
int numberAngles = (int)((maxAngle - minAngle) / angleSpacing);
float angle = 0;
Image<Gray, byte> workImg = img.Clone();
Matrix<float> imgHough = null;
for (float col = 0; col < numberAngles; col++)
{
workImg = img.Rotate(angle, new Gray(0), true);
angle += angleSpacing;
Matrix<float> imgMatH = new Matrix<float>(workImg.Height, 1, 1);
workImg.Reduce<float>(imgMatH, Emgu.CV.CvEnum.REDUCE_DIMENSION.SINGLE_COL, Emgu.CV.CvEnum.REDUCE_TYPE.CV_REDUCE_SUM);
if (imgHough == null)
imgHough = imgMatH;
else
imgHough = imgHough.ConcateHorizontal(imgMatH);
}
Image<Gray, float> houghImg = new Image<Gray, float>(numberAngles, img.Height);
CvInvoke.cvConvert(imgHough, houghImg);
return houghImg;
}
示例9: _testMorphological
private Image<Gray, Single> _testMorphological(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration, int cols, int rows, int anchorX, int anchorY, int shape)
{
int xOrder = Int32.Parse(txtXorder.Text), yOrder = Int32.Parse(txtYorder.Text),
appetureSize = Int32.Parse(txtAppetureSize.Text);
//img = img.Sobel(0, 1, 5);
//img = img.Sobel(xOrder, yOrder, appetureSize);
img = sobel_Filter(img);
StructuringElementEx element;
if(shape==0)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
else if (shape == 1)
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_CROSS);
else
element = new StructuringElementEx(cols, rows, anchorX, anchorY, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(255), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(255), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(255));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
//img.Bitmap.Save(@"Sobel\" + xOrder + " " + yOrder + " " + appetureSize + ".png");
return img;
}
示例10: _imageProcessing
/// <summary>
///
/// </summary>
/// <param name="img">Input Image</param>
/// <param name="threshold">Threshold value (with 8-bit image is from 0 to 255)</param>
/// <param name="maxGrayVal">Maximum Gray Value</param>
/// <param name="closingIteration">number of Iterations</param>
/// <returns></returns>
private Image<Gray, Single> _imageProcessing(Image<Gray, Single> img, int threshold, int maxGrayVal, int closingIteration)
{
img = img.Sobel(0, 1, 4);
StructuringElementEx element = new StructuringElementEx(4, 4, 1, 1, Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_RECT);
//MessageBox.Show((int)Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE + "");
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(90.0, new Gray(maxGrayValue), false);
img = img.MorphologyEx(element, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, closingIteration);
img = img.Rotate(-90.0, new Gray(maxGrayValue), false);
if (threshold >= 0 && threshold <= maxGrayVal)
{
img = img.ThresholdBinary(new Gray(threshold), new Gray(maxGrayValue));
}
else
{
MessageBox.Show("Threshold is not appropriate, please choose another!");
}
return img;
}
示例11: RotateCut
public static Image<Bgr, byte> RotateCut(Image<Bgr, byte> FaceImage, Point[] points, out double theta,
out double rito)
{
double tanangle = Convert.ToDouble(points[0].Y - points[1].Y)/Convert.ToDouble(points[0].X - points[1].X);
Image<Bgr, byte> temp = FaceImage.Rotate(-Math.Atan(tanangle)*180/Math.PI,
new Bgr(Color.DeepSkyBlue));
double a = temp.Width;
theta = Math.Atan(tanangle);
double smallsider = a/(2*Math.Sqrt(2)*Math.Sin(Math.Abs(theta) + Math.PI/4));
Rectangle small = new Rectangle(Convert.ToInt32(a/2 - smallsider), Convert.ToInt32(a/2 - smallsider),
Convert.ToInt32(2*smallsider), Convert.ToInt32(2*smallsider));
temp.ROI = small;
rito = smallsider/(a/2);
return temp;
}
示例12: TestRotationSpeed
public void TestRotationSpeed()
{
Image<Bgr, Byte> img = new Image<Bgr, byte>(1024, 720);
img.SetRandNormal(new MCvScalar(100, 100, 100), new MCvScalar(50, 50, 50));
Stopwatch watch = Stopwatch.StartNew();
Image<Bgr, Byte> imgRotated = img.Rotate(90, new Bgr(), false);
watch.Stop();
Trace.WriteLine(String.Format("Rotation time (wrap affine): {0}", watch.ElapsedMilliseconds));
EmguAssert.AreEqual(img.Width, imgRotated.Height);
EmguAssert.AreEqual(img.Height, imgRotated.Width);
watch.Reset();
watch.Start();
Image<Bgr, Byte> imgRotated2 = new Image<Bgr, byte>(img.Height, img.Width);
CvInvoke.Transpose(img, imgRotated2);
CvInvoke.Flip(imgRotated2, imgRotated2, FlipType.Horizontal);
watch.Stop();
Trace.WriteLine(String.Format("Rotation time (transpose & flip): {0}", watch.ElapsedMilliseconds));
EmguAssert.IsTrue(imgRotated.Equals(imgRotated2));
}
示例13: TestRotation
public void TestRotation()
{
Image<Bgr, Byte> img = new Image<Bgr, byte>(100, 80);
img.SetRandNormal(new MCvScalar(100, 100, 100), new MCvScalar(50, 50, 50));
Image<Bgr, Byte> imgRotated = img.Rotate(90, new Bgr(), false);
EmguAssert.AreEqual(img.Width, imgRotated.Height);
EmguAssert.AreEqual(img.Height, imgRotated.Width);
imgRotated = img.Rotate(30, new Bgr(255, 255, 255), false);
//ImageViewer.Show(imgRotated);
}
示例14: AfterReducingImage
protected override Image<Bgr, byte> AfterReducingImage(Image<Bgr, byte> reducedImage)
{
reducedImage = reducedImage.Rotate(
this.GetAngle(),
new Bgr(Color.Black), true);
return base.AfterReducingImage(reducedImage);
}
示例15: RotateWriteableBitmap
public static WriteableBitmap RotateWriteableBitmap(WriteableBitmap writeableBitmap, double degrees)
{
Bitmap normalBitmap = BitmapFromWriteableBitmap(writeableBitmap);
var cvImage = new Image<Gray, byte>(new Bitmap(normalBitmap));
cvImage = cvImage.Rotate(degrees, new Gray(0), false);
BitmapSource bitmapSource = ToBitmapSource(cvImage);
var rotatedWriteableBitmap = new WriteableBitmap(bitmapSource);
return rotatedWriteableBitmap;
}