本文整理汇总了C#中Mat.get方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.get方法的具体用法?C# Mat.get怎么用?C# Mat.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getRotationVec
// stores rotation values from SRT Matrix to Vector
Vector3 getRotationVec(Mat srtMat)
{
Vector3 rotVec;
rotVec.x = (float)srtMat.get (1, 0) [0];
rotVec.y = (float)srtMat.get (1, 1) [0];
rotVec.z = (float)srtMat.get (1, 2) [0];
return rotVec;
}
示例2: getScaleVec
// stores scale values from SRT Matrix to Vector
Vector3 getScaleVec(Mat srtMat)
{
Vector3 scaleVec;
scaleVec.x = (float)srtMat.get (2, 0) [0];
scaleVec.y = (float)srtMat.get (2, 1) [0];
scaleVec.z = (float)srtMat.get (2, 2) [0];
return scaleVec;
}
示例3: calc_shape
public Point[] calc_shape ()
{
using (Mat s = new Mat ()) {
Core.gemm (V, p, 1, new Mat (), 0, s);
int n = s.rows () / 2;
Point[] pts = new Point[n];
for (int i = 0; i < n; i++) {
pts [i] = new Point (s.get (2 * i, 0) [0], s.get (2 * i + 1, 0) [0]);
}
return pts;
}
}
示例4: hammDistMarker
/// <summary>
/// Hamms the dist marker.
/// </summary>
/// <returns>The dist marker.</returns>
/// <param name="bits">Bits.</param>
public static int hammDistMarker (Mat bits, byte[,] markerDesign)
{
int dist = 0;
int size = markerDesign.GetLength(0);
byte[] b = new byte[size * size];
bits.get (0, 0, b);
for (int y=0; y<size; y++) {
int sum = 0;
for (int x=0; x<size; x++) {
sum += (b [y*size + x] == markerDesign [y,x]) ? 0 : 1;
}
dist += sum;
}
return dist;
}
示例5: Start
// Use this for initialization
void Start()
{
Texture2D imgTexture = Resources.Load ("chessboard") as Texture2D;
Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC3);
Utils.texture2DToMat (imgTexture, imgMat);
Debug.Log ("imgMat dst ToString " + imgMat.ToString ());
Mat grayMat = new Mat ();
Imgproc.cvtColor (imgMat, grayMat, Imgproc.COLOR_RGB2GRAY);
Imgproc.Canny (grayMat, grayMat, 50, 200);
Mat lines = new Mat ();
Imgproc.HoughLinesP (grayMat, lines, 1, Mathf.PI / 180, 50, 50, 10);
// Debug.Log ("lines toStirng " + lines.ToString ());
// Debug.Log ("lines dump" + lines.dump ());
int[] linesArray = new int[lines.cols () * lines.rows () * lines.channels ()];
lines.get (0, 0, linesArray);
for (int i = 0; i < linesArray.Length; i=i+4) {
Core.line (imgMat, new Point (linesArray [i + 0], linesArray [i + 1]), new Point (linesArray [i + 2], linesArray [i + 3]), new Scalar (255, 0, 0), 2);
}
Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
Utils.matToTexture2D (imgMat, texture);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
}
示例6: calc_peaks
public Point[] calc_peaks (Mat im,
Point[] points,
OpenCVForUnity.Size ssize)
{
int n = points.Length;
// Debug.Log ("n == int(patches.size()) " + patches.Count);
using (Mat pt = (new MatOfPoint2f (points)).reshape (1, 2 * n))
using (Mat S = calc_simil (pt))
using (Mat Si = inv_simil (S)) {
Point[] pts = apply_simil (Si, points);
for (int i = 0; i < n; i++) {
OpenCVForUnity.Size wsize = new OpenCVForUnity.Size (ssize.width + patches [i].patch_size ().width, ssize.height + patches [i].patch_size ().height);
using (Mat A = new Mat (2, 3, CvType.CV_32F)) {
A.put (0, 0, S.get (0, 0) [0]);
A.put (0, 1, S.get (0, 1) [0]);
A.put (1, 0, S.get (1, 0) [0]);
A.put (1, 1, S.get (1, 1) [0]);
A.put (0, 2, pt.get (2 * i, 0) [0] -
(A.get (0, 0) [0] * (wsize.width - 1) / 2 + A.get (0, 1) [0] * (wsize.height - 1) / 2));
A.put (1, 2, pt.get (2 * i + 1, 0) [0] -
(A.get (1, 0) [0] * (wsize.width - 1) / 2 + A.get (1, 1) [0] * (wsize.height - 1) / 2));
using (Mat I = new Mat ()) {
Imgproc.warpAffine (im, I, A, wsize, Imgproc.INTER_LINEAR + Imgproc.WARP_INVERSE_MAP);
using (Mat R = patches [i].calc_response (I, false)) {
Core.MinMaxLocResult minMaxLocResult = Core.minMaxLoc (R);
pts [i].x = pts [i].x + minMaxLocResult.maxLoc.x - 0.5 * ssize.width;
pts [i].y = pts [i].y + minMaxLocResult.maxLoc.y - 0.5 * ssize.height;
}
}
}
}
return apply_simil (S, pts);
}
}
示例7: Start
// Use this for initialization
void Start()
{
Texture2D imgTexture = Resources.Load ("lena") as Texture2D;
Texture2D tempTexture = Resources.Load ("template") as Texture2D;
Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
Mat tempMat = new Mat (tempTexture.height, tempTexture.width, CvType.CV_8UC4);
Utils.texture2DToMat (imgTexture, imgMat);
Utils.texture2DToMat (tempTexture, tempMat);
//Create the result mat
int result_cols = imgMat.cols () - tempMat.cols () + 1;
int result_rows = imgMat.rows () - tempMat.rows () + 1;
Mat result = new Mat (result_rows, result_cols, CvType.CV_32FC1);
int match_method = Imgproc.TM_CCOEFF_NORMED;
Imgproc.matchTemplate (imgMat, tempMat, result, match_method);
Imgproc.threshold (result, result, 0.8, 1.0, Imgproc.THRESH_TOZERO);//threshold = 0.8
for (int i=0; i<result.rows(); i++) {
for (int j=0; j<result.cols(); j++) {
if (result.get (i, j) [0] > 0) {
Imgproc.rectangle (imgMat, new Point (j, i), new Point (j + tempMat.cols (), i + tempMat.rows ()), new Scalar (255, 0, 0, 255), 2);
Debug.Log ("value" + result.get (i, j) [0]);
}
}
}
Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
Utils.matToTexture2D (imgMat, texture);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
}
示例8: rotate
/// <summary>
/// Rotate the specified inMat.
/// </summary>
/// <param name="inMat">In mat.</param>
public static Mat rotate (Mat inMat)
{
byte[] b = new byte[1];
Mat outMat = new Mat ();
inMat.copyTo (outMat);
for (int i=0; i<inMat.rows(); i++) {
for (int j=0; j<inMat.cols(); j++) {
inMat.get (inMat.cols () - j - 1, i, b);
outMat.put (i, j, b);
}
}
return outMat;
}
示例9: apply_simil
Point[] apply_simil (Mat S, Point[] points)
{
int n = points.Length;
Point[] p = new Point[n];
for (int i = 0; i < n; i++) {
p [i] = new Point ();
p [i].x = S.get (0, 0) [0] * points [i].x + S.get (0, 1) [0] * points [i].y + S.get (0, 2) [0];
p [i].y = S.get (1, 0) [0] * points [i].x + S.get (1, 1) [0] * points [i].y + S.get (1, 2) [0];
}
return p;
}
示例10: calc_params
public void calc_params (Point[] pts, Mat weight, float c_factor)
{
int n = pts.Length;
// assert(V.rows == 2*n);
// Debug.Log ("V.rows == 2*n " + V.rows () + " " + 2 * n);
using (Mat s = (new MatOfPoint2f (pts)).reshape (1, 2 * n)) { //point set to vector format
if (weight.empty ()) {
Core.gemm (V.t (), s, 1, new Mat (), 0, p); //simple projection
} else { //scaled projection
if (weight.rows () != n) {
Debug.Log ("Invalid weighting matrix");
}
int K = V.cols ();
using (Mat H = Mat.zeros (K, K, CvType.CV_32F))
using (Mat g = Mat.zeros (K, 1, CvType.CV_32F)) {
for (int i = 0; i < n; i++) {
using (Mat v = new Mat (V, new OpenCVForUnity.Rect (0, 2 * i, K, 2)))
using (Mat tmpMat1 = new Mat ())
using (Mat tmpMat2 = new Mat ())
using (Mat tmpMat3 = new Mat ()) {
float w = (float)weight.get (i, 0) [0];
Core.multiply (v.t (), new Scalar (w), tmpMat1);
Core.gemm (tmpMat1, v, 1, new Mat (), 0, tmpMat2);
Core.add (H, tmpMat2, H);
Core.gemm (tmpMat1, new MatOfPoint2f (pts [i]).reshape (1, 2), 1, new Mat (), 0, tmpMat3);
Core.add (g, tmpMat3, g);
}
}
Core.solve (H, g, p, Core.DECOMP_SVD);
}
}
}
clamp (c_factor); //clamp resulting parameters
}
示例11: convertToGrabCutValues
private static void convertToGrabCutValues(Mat mask)
{
int width = mask.rows ();
int height = mask.cols ();
byte[] buffer = new byte[width * height];
mask.get (0, 0, buffer);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int value = buffer [y * width + x];
if (value >= 0 && value < 64) {
buffer [y * width + x] = Imgproc.GC_BGD; // for sure background
} else if (value >= 64 && value < 128) {
buffer [y * width + x] = Imgproc.GC_PR_BGD; // probably background
} else if (value >= 128 && value < 192) {
buffer [y * width + x] = Imgproc.GC_PR_FGD; // probably foreground
} else {
buffer [y * width + x] = Imgproc.GC_FGD; // for sure foreground
}
}
}
mask.put (0, 0, buffer);
}
示例12: convertToGrayScaleValues
private static void convertToGrayScaleValues(Mat mask)
{
int width = mask.rows ();
int height = mask.cols ();
byte[] buffer = new byte[width * height];
mask.get (0, 0, buffer);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int value = buffer [y * width + x];
if (value == Imgproc.GC_BGD) {
buffer [y * width + x] = 0; // for sure background
} else if (value == Imgproc.GC_PR_BGD) {
buffer [y * width + x] = 85; // probably background
} else if (value == Imgproc.GC_PR_FGD) {
buffer [y * width + x] = (byte)170; // probably foreground
} else {
buffer [y * width + x] = (byte)255; // for sure foreground
}
}
}
mask.put (0, 0, buffer);
}
示例13: converScalarHsv2Rgba
/// <summary>
/// Convers the scalar hsv2 rgba.
/// </summary>
/// <returns>The scalar hsv2 rgba.</returns>
/// <param name="hsvColor">Hsv color.</param>
private Scalar converScalarHsv2Rgba(Scalar hsvColor)
{
Mat pointMatRgba = new Mat ();
Mat pointMatHsv = new Mat (1, 1, CvType.CV_8UC3, hsvColor);
Imgproc.cvtColor (pointMatHsv, pointMatRgba, Imgproc.COLOR_HSV2RGB_FULL, 4);
return new Scalar (pointMatRgba.get (0, 0));
}
示例14: estimatePosition
/// <summary>
/// Estimates the position.
/// </summary>
/// <param name="detectedMarkers">Detected markers.</param>
void estimatePosition (List<Marker> detectedMarkers)
{
for (int i=0; i<detectedMarkers.Count; i++) {
Marker m = detectedMarkers [i];
Mat Rvec = new Mat ();
Mat Tvec = new Mat ();
Mat raux = new Mat ();
Mat taux = new Mat ();
Calib3d.solvePnP (m_markerCorners3d, new MatOfPoint2f (m.points.toArray ()), camMatrix, distCoeff, raux, taux);
raux.convertTo (Rvec, CvType.CV_32F);
taux.convertTo (Tvec, CvType.CV_32F);
Mat rotMat = new Mat (3, 3, CvType.CV_64FC1);
Calib3d.Rodrigues (Rvec, rotMat);
m.transformation.SetRow (0, new Vector4 ((float)rotMat.get (0, 0) [0], (float)rotMat.get (0, 1) [0], (float)rotMat.get (0, 2) [0], (float)Tvec.get (0, 0) [0]));
m.transformation.SetRow (1, new Vector4 ((float)rotMat.get (1, 0) [0], (float)rotMat.get (1, 1) [0], (float)rotMat.get (1, 2) [0], (float)Tvec.get (1, 0) [0]));
m.transformation.SetRow (2, new Vector4 ((float)rotMat.get (2, 0) [0], (float)rotMat.get (2, 1) [0], (float)rotMat.get (2, 2) [0], (float)Tvec.get (2, 0) [0]));
m.transformation.SetRow (3, new Vector4 (0, 0, 0, 1));
// Debug.Log ("m.transformation " + m.transformation.ToString ());
Rvec.Dispose ();
Tvec.Dispose ();
raux.Dispose ();
taux.Dispose ();
rotMat.Dispose ();
}
}
示例15: getTranslationVec
// stores translation values from SRT Matrix to Vector
Vector3 getTranslationVec(Mat srtMat)
{
Vector3 transVec;
transVec.x = (float)srtMat.get (0, 0) [0];
transVec.y = (float)srtMat.get (0, 1) [0];
transVec.z = (float)srtMat.get (0, 2) [0];
return transVec;
}