本文整理汇总了C#中Mat.RowRange方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.RowRange方法的具体用法?C# Mat.RowRange怎么用?C# Mat.RowRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.RowRange方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CppTest
public CppTest()
{
//PixelAccess();
using (Mat mat = new Mat(Const.ImageLenna, LoadMode.Color))
{
//CvSize s;
//CvPoint p;
//mat.LocateROI(out s, out p);
// CvMatへの変換
CvMat m = mat.ToCvMat();
Console.WriteLine(m);
// 行を一部分切り出し
Mat row = mat.RowRange(100, 200);
// IplImageへ変換し、highguiにより描画
IplImage img = row.ToIplImage();
using (new CvWindow("highgui", img))
{
Cv.WaitKey();
}
// Bitmapに変換して、WindowsFormで描画する
using (Bitmap bitmap = mat.ToBitmap())
using (Form form = new Form() { Text = "WindowsForms", ClientSize = new System.Drawing.Size(bitmap.Width, bitmap.Height) })
using (PictureBox pb = new PictureBox() { Image = bitmap, Dock = DockStyle.Fill })
{
form.Controls.Add(pb);
Application.Run(form);
}
// cv::imshowによる表示
CvCpp.NamedWindow("imshow", WindowMode.AutoSize);
CvCpp.ImShow("imshow", mat);
CvCpp.WaitKey(0);
Cv.DestroyAllWindows();
}
}
示例2: example01
/// <summary>
/// https://github.com/Itseez/opencv_extra/blob/master/learning_opencv_v2/ch13_ex13_1.cpp
/// </summary>
private static void example01()
{
using (var window = new Window("Clusters", flags: WindowMode.AutoSize | WindowMode.FreeRatio))
{
const int maxClusters = 5;
var rng = new RNG(state: (ulong)DateTime.Now.Ticks);
for (; ; )
{
var clustersCount = rng.Uniform(a: 2, b: maxClusters + 1);
var samplesCount = rng.Uniform(a: 1, b: 1001);
var points = new Mat(rows: samplesCount, cols: 1, type: MatType.CV_32FC2);
clustersCount = Math.Min(clustersCount, samplesCount);
var img = new Mat(rows: 500, cols: 500, type: MatType.CV_8UC3, s: Scalar.All(0));
// generate random sample from multi-gaussian distribution
for (var k = 0; k < clustersCount; k++)
{
var pointChunk = points.RowRange(
startRow: k * samplesCount / clustersCount,
endRow: (k == clustersCount - 1)
? samplesCount
: (k + 1) * samplesCount / clustersCount);
var center = new Point
{
X = rng.Uniform(a: 0, b: img.Cols),
Y = rng.Uniform(a: 0, b: img.Rows)
};
rng.Fill(
mat: pointChunk,
distType: DistributionType.Normal,
a: new Scalar(center.X, center.Y),
b: new Scalar(img.Cols * 0.05f, img.Rows * 0.05f));
}
Cv2.RandShuffle(dst: points, iterFactor: 1, rng: rng);
var labels = new Mat();
var centers = new Mat(rows: clustersCount, cols: 1, type: points.Type());
Cv2.Kmeans(
data: points,
k: clustersCount,
bestLabels: labels,
criteria: new TermCriteria(CriteriaType.Epsilon | CriteriaType.Iteration, 10, 1.0),
attempts: 3,
flags: KMeansFlag.PpCenters,
centers: centers);
Scalar[] colors =
{
new Scalar(0, 0, 255),
new Scalar(0, 255, 0),
new Scalar(255, 100, 100),
new Scalar(255, 0, 255),
new Scalar(0, 255, 255)
};
for (var i = 0; i < samplesCount; i++)
{
var clusterIdx = labels.At<int>(i);
Point ipt = points.At<Point2f>(i);
Cv2.Circle(
img: img,
center: ipt,
radius: 2,
color: colors[clusterIdx],
lineType: LineType.AntiAlias,
thickness: Cv.FILLED);
}
window.Image = img;
var key = (char)Cv2.WaitKey();
if (key == 27 || key == 'q' || key == 'Q') // 'ESC'
{
break;
}
}
}
}
示例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, NormType.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, CvColor.Red, -1);
Point textPos = new Point(x + 5, y + 10);
img.PutText(CityNames[c], textPos, FontFace.HersheySimplex, 0.5, CvColor.White);
}
window.Image = img;
Cv2.WaitKey();
}
}