本文整理汇总了C#中OpenCvSharp.Mat.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Get方法的具体用法?C# Mat.Get怎么用?C# Mat.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.Mat
的用法示例。
在下文中一共展示了Mat.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
Console.WriteLine("===== FlannTest =====");
// creates data set
using (var features = new Mat(10000, 2, MatType.CV_32FC1))
{
var rand = new Random();
for (int i = 0; i < features.Rows; i++)
{
features.Set<float>(i, 0, rand.Next(10000));
features.Set<float>(i, 1, rand.Next(10000));
}
// query
var queryPoint = new Point2f(7777, 7777);
var queries = new Mat(1, 2, MatType.CV_32FC1);
queries.Set<float>(0, 0, queryPoint.X);
queries.Set<float>(0, 1, queryPoint.Y);
Console.WriteLine("query:({0}, {1})", queryPoint.X, queryPoint.Y);
Console.WriteLine("-----");
// knnSearch
using (var nnIndex = new Index(features, new KDTreeIndexParams(4)))
{
const int Knn = 1;
int[] indices;
float[] dists;
nnIndex.KnnSearch(queries, out indices, out dists, Knn, new SearchParams(32));
for (int i = 0; i < Knn; i++)
{
int index = indices[i];
float dist = dists[i];
var pt = new Point2f(features.Get<float>(index, 0), features.Get<float>(index, 1));
Console.Write("No.{0}\t", i);
Console.Write("index:{0}", index);
Console.Write(" distance:{0}", dist);
Console.Write(" data:({0}, {1})", pt.X, pt.Y);
Console.WriteLine();
}
}
}
Console.Read();
}
示例2: Run
public void Run()
{
Mat src = Cv2.ImRead(FilePath.Image.Lenna, ImreadModes.GrayScale);
// Histogram view
const int Width = 260, Height = 200;
Mat render = new Mat(new Size(Width, Height), MatType.CV_8UC3, Scalar.All(255));
// Calculate histogram
Mat hist = new Mat();
int[] hdims = {256}; // Histogram size for each dimension
Rangef[] ranges = { new Rangef(0,256), }; // min/max
Cv2.CalcHist(
new Mat[]{src},
new int[]{0},
null,
hist,
1,
hdims,
ranges);
// Get the max value of histogram
double minVal, maxVal;
Cv2.MinMaxLoc(hist, out minVal, out maxVal);
Scalar color = Scalar.All(100);
// Scales and draws histogram
hist = hist * (maxVal != 0 ? Height / maxVal : 0.0);
for (int j = 0; j < hdims[0]; ++j)
{
int binW = (int)((double)Width / hdims[0]);
render.Rectangle(
new Point(j * binW, render.Rows),
new Point((j + 1) * binW, render.Rows - (int)(hist.Get<float>(j))),
color,
-1);
}
using (new Window("Image", WindowMode.AutoSize | WindowMode.FreeRatio, src))
using (new Window("Histogram", WindowMode.AutoSize | WindowMode.FreeRatio, render))
{
Cv2.WaitKey();
}
}
示例3: Run
/// <summary>
/// Classical Multidimensional Scaling
/// </summary>
public void Run()
{
// creates distance matrix
int size = CityDistance.GetLength(0);
Mat t = new Mat(size, size, MatType.CV_64FC1, CityDistance);
// adds Torgerson's additive constant to t
double torgarson = Torgerson(t);
t += torgarson;
// squares all elements of t
t = t.Mul(t);
// centering matrix G
Mat g = CenteringMatrix(size);
// calculates inner product matrix B
Mat b = g * t * g.T() * -0.5;
// calculates eigenvalues and eigenvectors of B
Mat values = new Mat();
Mat vectors = new Mat();
Cv2.Eigen(b, values, vectors);
for (int r = 0; r < values.Rows; r++)
{
if (values.Get<double>(r) < 0)
values.Set<double>(r, 0);
}
//Console.WriteLine(values.Dump());
// multiplies sqrt(eigenvalue) by eigenvector
Mat result = vectors.RowRange(0, 2);
{
var at = result.GetGenericIndexer<double>();
for (int r = 0; r < result.Rows; r++)
{
for (int c = 0; c < result.Cols; c++)
{
at[r, c] *= Math.Sqrt(values.Get<double>(r));
}
}
}
// scaling
Cv2.Normalize(result, result, 0, 800, NormTypes.MinMax);
// opens a window
using (Mat img = Mat.Zeros(600, 800, MatType.CV_8UC3))
using (Window window = new Window("City Location Estimation"))
{
var at = result.GetGenericIndexer<double>();
for (int c = 0; c < size; c++)
{
double x = at[0, c];
double y = at[1, c];
x = x * 0.7 + img.Width * 0.1;
y = y * 0.7 + img.Height * 0.1;
img.Circle((int)x, (int)y, 5, Scalar.Red, -1);
Point textPos = new Point(x + 5, y + 10);
img.PutText(CityNames[c], textPos, HersheyFonts.HersheySimplex, 0.5, Scalar.White);
}
window.Image = img;
Cv2.WaitKey();
}
}