本文整理汇总了C#中Mat.copyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.copyTo方法的具体用法?C# Mat.copyTo怎么用?C# Mat.copyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.copyTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MarkerDetector
/// <summary>
/// Initializes a new instance of the <see cref="MarkerDetector"/> class.
/// </summary>
/// <param name="camMatrix">Cam matrix.</param>
/// <param name="distCoeff">Dist coeff.</param>
public MarkerDetector(Mat camMatrix, Mat distCoeff)
{
m_minContourLengthAllowed = 100;
markerSize = new Size (100, 100);
camMatrix.copyTo (this.camMatrix);
distCoeff.copyTo (this.distCoeff);
List<Point3> m_markerCorners3dList = new List<Point3> ();
m_markerCorners3dList.Add (new Point3 (-0.5f, -0.5f, 0));
m_markerCorners3dList.Add (new Point3 (+0.5f, -0.5f, 0));
m_markerCorners3dList.Add (new Point3 (+0.5f, +0.5f, 0));
m_markerCorners3dList.Add (new Point3 (-0.5f, +0.5f, 0));
m_markerCorners3d.fromList (m_markerCorners3dList);
List<Point> m_markerCorners2dList = new List<Point> ();
m_markerCorners2dList.Add (new Point (0, 0));
m_markerCorners2dList.Add (new Point (markerSize.width - 1, 0));
m_markerCorners2dList.Add (new Point (markerSize.width - 1, markerSize.height - 1));
m_markerCorners2dList.Add (new Point (0, markerSize.height - 1));
m_markerCorners2d.fromList (m_markerCorners2dList);
}
示例2: 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;
}
示例3: Start
// Use this for initialization
void Start()
{
Texture2D imageTexture = Resources.Load ("lena") as Texture2D;
Mat image = new Mat (imageTexture.height, imageTexture.width, CvType.CV_8UC3);
Utils.texture2DToMat (imageTexture, image);
Debug.Log ("image.ToString() " + image.ToString ());
Texture2D maskTexture = Resources.Load ("lena_grabcut_mask") as Texture2D;
Mat mask = new Mat (imageTexture.height, imageTexture.width, CvType.CV_8UC1);
Utils.texture2DToMat (maskTexture, mask);
Debug.Log ("mask.ToString() " + mask.ToString ());
OpenCVForUnity.Rect rectangle = new OpenCVForUnity.Rect (10, 10, image.cols () - 20, image.rows () - 20);
Mat bgdModel = new Mat (); // extracted features for background
Mat fgdModel = new Mat (); // extracted features for foreground
convertToGrabCutValues (mask); // from grayscale values to grabcut values
int iterCount = 5;
// Imgproc.grabCut (image, mask, rectangle, bgdModel, fgdModel, iterCount, Imgproc.GC_INIT_WITH_RECT);
Imgproc.grabCut (image, mask, rectangle, bgdModel, fgdModel, iterCount, Imgproc.GC_INIT_WITH_MASK);
convertToGrayScaleValues (mask); // back to grayscale values
Imgproc.threshold (mask, mask, 128, 255, Imgproc.THRESH_TOZERO);
Mat foreground = new Mat (image.size (), CvType.CV_8UC3, new Scalar (0, 0, 0));
image.copyTo (foreground, mask);
Texture2D texture = new Texture2D (image.cols (), image.rows (), TextureFormat.RGBA32, false);
Utils.matToTexture2D (foreground, texture);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
}
示例4: MarkerDetector
/// <summary>
/// Initializes a new instance of the <see cref="MarkerDetector"/> class.
/// </summary>
/// <param name="camMatrix">Cam matrix.</param>
/// <param name="distCoeff">Dist coeff.</param>
public MarkerDetector (Mat camMatrix, Mat distCoeff, MarkerDesign markerDesign)
{
m_minContourLengthAllowed = 100;
markerSize = new Size (100, 100);
camMatrix.copyTo (this.camMatrix);
distCoeff.copyTo (this.distCoeff);
List<Point3> m_markerCorners3dList = new List<Point3> ();
m_markerCorners3dList.Add (new Point3 (-0.5f, -0.5f, 0));
m_markerCorners3dList.Add (new Point3 (+0.5f, -0.5f, 0));
m_markerCorners3dList.Add (new Point3 (+0.5f, +0.5f, 0));
m_markerCorners3dList.Add (new Point3 (-0.5f, +0.5f, 0));
m_markerCorners3d.fromList (m_markerCorners3dList);
List<Point> m_markerCorners2dList = new List<Point> ();
m_markerCorners2dList.Add (new Point (0, 0));
m_markerCorners2dList.Add (new Point (markerSize.width - 1, 0));
m_markerCorners2dList.Add (new Point (markerSize.width - 1, markerSize.height - 1));
m_markerCorners2dList.Add (new Point (0, markerSize.height - 1));
m_markerCorners2d.fromList (m_markerCorners2dList);
if (markerDesign != null) {
m_markerDesign = new byte[markerDesign.gridSize, markerDesign.gridSize];
for (int y = 0; y < m_markerDesign.GetLength(0); y++) {
for (int x = 0; x < m_markerDesign.GetLength(1); x++) {
if (markerDesign.data [y*markerDesign.gridSize + x]) {
m_markerDesign [y, x] = 0;
} else {
m_markerDesign [y, x] = 1;
}
}
}
}
}
示例5: trackFilteredObject
/// <summary>
/// Tracks the filtered object.
/// </summary>
/// <param name="theColorObject">The color object.</param>
/// <param name="threshold">Threshold.</param>
/// <param name="HSV">HS.</param>
/// <param name="cameraFeed">Camera feed.</param>
void trackFilteredObject (ColorObject theColorObject, Mat threshold, Mat HSV, Mat cameraFeed)
{
List<ColorObject> colorObjects = new List<ColorObject> ();
Mat temp = new Mat ();
threshold.copyTo (temp);
//these two vectors needed for output of findContours
List<MatOfPoint> contours = new List<MatOfPoint> ();
Mat hierarchy = new Mat ();
//find contours of filtered image using openCV findContours function
Imgproc.findContours (temp, contours, hierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);
//use moments method to find our filtered object
double refArea = 0;
bool colorObjectFound = false;
if (hierarchy.rows () > 0) {
int numObjects = hierarchy.rows ();
// Debug.Log("hierarchy " + hierarchy.ToString());
//if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
if (numObjects < MAX_NUM_OBJECTS) {
for (int index = 0; index >= 0; index = (int)hierarchy.get(0, index)[0]) {
Moments moment = Imgproc.moments (contours [index]);
double area = moment.get_m00 ();
//if the area is less than 20 px by 20px then it is probably just noise
//if the area is the same as the 3/2 of the image size, probably just a bad filter
//we only want the object with the largest area so we safe a reference area each
//iteration and compare it to the area in the next iteration.
if (area > MIN_OBJECT_AREA) {
ColorObject colorObject = new ColorObject ();
colorObject.setXPos ((int)(moment.get_m10 () / area));
colorObject.setYPos ((int)(moment.get_m01 () / area));
colorObject.setType (theColorObject.getType ());
colorObject.setColor (theColorObject.getColor ());
colorObjects.Add (colorObject);
colorObjectFound = true;
} else {
colorObjectFound = false;
}
}
//let user know you found an object
if (colorObjectFound == true) {
//draw object location on screen
drawObject (colorObjects, cameraFeed, temp, contours, hierarchy);
}
} else {
Core.putText (cameraFeed, "TOO MUCH NOISE!", new Point (5, cameraFeed.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Core.LINE_AA, false);
}
}
}
示例6: inv_simil
Mat inv_simil (Mat S)
{
Mat Si = new Mat (2, 3, CvType.CV_32F);
float d = (float)S.get (0, 0) [0] * (float)S.get (1, 1) [0] - (float)S.get (1, 0) [0] * (float)S.get (0, 1) [0];
Si.put (0, 0, S.get (1, 1) [0] / d);
Si.put (0, 1, -S.get (0, 1) [0] / d);
Si.put (1, 1, S.get (0, 0) [0] / d);
Si.put (1, 0, -S.get (1, 0) [0] / d);
Mat Ri = new Mat (Si, new OpenCVForUnity.Rect (0, 0, 2, 2));
Mat negaRi = new Mat ();
Core.multiply (Ri, new Scalar (-1), negaRi);
Mat t = new Mat ();
Core.gemm (negaRi, S.col (2), 1, new Mat (negaRi.rows (), negaRi.cols (), negaRi.type ()), 0, t);
Mat St = Si.col (2);
t.copyTo (St);
return Si;
}
示例7: Mattting
void Mattting(int index)
{
if (index > textures.Count - 1)
{
return;
}
ClearAllRendererTexture();
Texture2D imgTexture = Resources.Load(textures[index]) as Texture2D;
SetTexture(SourceTextureObject, imgTexture);
Mat imgMat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC4);
Mat thresholdImageMat = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC1);
Utils.texture2DToMat(imgTexture, imgMat);
// Threshold to make picture more clean
//
Utils.texture2DToMat(imgTexture, thresholdImageMat);
Imgproc.threshold(thresholdImageMat, thresholdImageMat, minThreshold, maxThreshold, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU);
if (ThresholdRenderObject)
{
SetTexture(ThresholdRenderObject, thresholdImageMat);
}
// find Contours
//
List<MatOfPoint> contours = new List<MatOfPoint>();
Mat hierachy = new Mat();
Imgproc.findContours(thresholdImageMat, contours, hierachy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_TC89_KCOS);
Debug.Log(contours.Count);
// sort contours by rows from large to small, first one is we wanted
//
contours.Reverse();
// made mask
//
Mat mask = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC4, new Scalar(0, 0, 0, 0));
Imgproc.drawContours(mask, contours, 0, new Scalar(255, 255, 255, 255), -1);
if (MaskRenderObject)
{
SetTexture(MaskRenderObject, mask);
}
//CopyTo
//
Mat result = new Mat(imgTexture.height, imgTexture.width, CvType.CV_8UC4);
imgMat.copyTo(result, mask);
SetTexture(gameObject, result);
}