public CvMatProxy(CvScalar[,] data, int rows, int cols, int elemChannels) { Data = data; Rows = rows; Cols = cols; ElemChannels = elemChannels; }
private IEnumerator Capture() { while (true) { var width = _webCamTexture.width; var height = _webCamTexture.height; var pixels = _webCamTexture.GetPixels(); Parallel.For(0, height, i => { for (var j = 0; j < width; j++) { var pixel = pixels[j + i * width]; var col = new CvScalar { Val0 = (double)pixel.b * 255, Val1 = (double)pixel.g * 255, Val2 = (double)pixel.r * 255 }; _iplImage.Set2D(i, j, col); } }); if (OnFrameReady != null) OnFrameReady.Invoke(_iplImage); yield return null; } }
/// <summary> /// 配列の要素と定数との差の絶対値を計算する. /// dst(I) = abs(src(I) - value). /// </summary> /// <param name="src">1番目の入力画像</param> /// <param name="dst">出力画像</param> /// <param name="value">スカラー</param> #else /// <summary> /// Calculates absolute difference between array and scalar /// </summary> /// <param name="src">The source array. </param> /// <param name="dst">The destination array. </param> /// <param name="value">The scalar. </param> #endif public static void AbsDiffS(CvArr src, CvArr dst, CvScalar value) { if (src == null) throw new ArgumentNullException("src"); if (dst == null) throw new ArgumentNullException("dst"); NativeMethods.cvAbsDiffS(src.CvPtr, dst.CvPtr, value); }
public void color1() { Double H1 = decimal.ToDouble(numericUpDown1.Value); Double S1 = decimal.ToDouble(numericUpDown2.Value); Double V1 = decimal.ToDouble(numericUpDown3.Value); int[] rgb1 = HSVtoRGB((int)H1, (int)S1, (int)V1); CvScalar hsv1 = new CvScalar(rgb1[2], rgb1[1], rgb1[0]); IplImage ipl1 = fnc(mat1, hsv1); Bitmap bmp1 = BitmapConverter.ToBitmap(ipl1); pictureBox1.Image = bmp1; }
public void color2() { Double H2 = decimal.ToDouble(numericUpDown4.Value); Double S2 = decimal.ToDouble(numericUpDown5.Value); Double V2 = decimal.ToDouble(numericUpDown6.Value); int[] rgb2 = HSVtoRGB((int)H2, (int)S2, (int)V2); CvScalar hsv2 = new CvScalar(rgb2[2], rgb2[1], rgb2[0]); IplImage ipl2 = fnc(mat2, hsv2); Bitmap bmp2 = BitmapConverter.ToBitmap(ipl2); pictureBox2.Image = bmp2; }
public void Awake() { UnityCvBase.Init(WebCamTexture.devices[0].name, RequestedWidth, RequestedHeight, RequestedFps, ImagesDepth); TargetRenderer.sharedMaterial.mainTexture = UnityCvBase.WebCamTexture; Camera.main.orthographicSize = Screen.height / 2f; var tr = TargetRenderer.transform; tr.localScale = new Vector3(Screen.width, Screen.height); _cvScalarFrom = UnityCvUtils.ColorToBGRScalar(ThreshFromColor); _cvScalarTo = UnityCvUtils.ColorToBGRScalar(ThreshToColor); if (FollowerPrefab) _dummyTransform = ((GameObject)Instantiate(FollowerPrefab)).transform; if (ShowThresholdedImage) Cv.NamedWindow("Threshold", WindowMode.FreeRatio); WebCamTextureProxy.OnFrameReady += Process; }
/// <summary> /// /// </summary> /// <param name="subdiv"></param> /// <param name="fp"></param> /// <param name="img"></param> /// <param name="active_color"></param> private void LocatePoint(CvSubdiv2D subdiv, CvPoint2D32f fp, IplImage img, CvScalar active_color) { CvSubdiv2DEdge e; CvSubdiv2DEdge e0 = 0; subdiv.Locate(fp, out e0); if (e0 != 0) { e = e0; do { //Console.WriteLine(e); DrawSubdivEdge(img, e, active_color); e = e.GetEdge(CvNextEdgeType.NextAroundLeft); } while (e != e0); } DrawSubdivPoint(img, fp, active_color); }
void FromTextureToIplImage(IplImage imageIpl) { int imH = imHeight; for (int v = 0; v < imHeight; ++v) { for (int u = 0; u < imWidth; ++u) { CvScalar col = new CvScalar(); col.Val0 = (double)webcamTexture.GetPixel(u, v).b * 255; col.Val1 = (double)webcamTexture.GetPixel(u, v).g * 255; col.Val2 = (double)webcamTexture.GetPixel(u, v).r * 255; imH = imHeight - v - 1; imageIpl.Set2D(imH, u, col); } } }
public void Process(IplImage frame) { if (UpdateColorsEachFrame) { _cvScalarFrom = UnityCvUtils.ColorToBGRScalar(ThreshFromColor); _cvScalarTo = UnityCvUtils.ColorToBGRScalar(ThreshToColor); } var imgThresh = GetThresholdedImage(frame, _cvScalarFrom, _cvScalarTo); CvMoments moments; Cv.Moments(imgThresh, out moments, true); var moment10 = Cv.GetSpatialMoment(moments, 1, 0); var moment01 = Cv.GetSpatialMoment(moments, 0, 1); var area = Cv.GetSpatialMoment(moments, 0, 0); ColorPosition = new Vector2((float)(moment10 / area), (float)(moment01 / area)); ColorPosition.Scale(new Vector2((float)Screen.width / frame.Width, (float)Screen.height / frame.Height)); ColorPosition -= new Vector2(Screen.width, Screen.height) * .5f; Cv.ReleaseImage(imgThresh); }
/// <summary> /// Draw a polygon. /// </summary> /// <param name="contour">Polygon contour.</param> /// <param name="img">Image to draw on.</param> /// <param name="color">Color to draw (default, white).</param> public static void RenderContourPolygon(CvContourPolygon contour, IplImage img, CvScalar color) { if (contour == null) { throw new ArgumentNullException(nameof(contour)); } contour.Render(img, color); }
public static extern void GpuMat_setTo(IntPtr obj, CvScalar s, IntPtr mask, IntPtr dst);
public static extern void GpuMat_opBinaryMinus(IntPtr src1, CvScalar scalar, IntPtr dst);
public static extern IntPtr GpuMat_new11(CvSize size, [MarshalAs(UnmanagedType.I4)] MatrixType type, CvScalar s);
/// <summary> /// 枠だけの楕円,楕円弧,もしくは塗りつぶされた扇形の楕円を描画する /// </summary> /// <param name="img">楕円が描画される画像</param> /// <param name="center">楕円の中心</param> /// <param name="axes">楕円の軸の長さ</param> /// <param name="angle">回転角度</param> /// <param name="start_angle">楕円弧の開始角度</param> /// <param name="end_angle">楕円弧の終了角度</param> /// <param name="color">楕円の色</param> /// <param name="thickness">楕円弧の線の幅</param> /// <param name="line_type">楕円弧の線の種類</param> /// <param name="shift">中心座標と軸の長さの小数点以下の桁を表すビット数</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="center">Center of the ellipse. </param> /// <param name="axes">Length of the ellipse axes. </param> /// <param name="angle">Rotation angle. </param> /// <param name="start_angle">Starting angle of the elliptic arc. </param> /// <param name="end_angle">Ending angle of the elliptic arc. </param> /// <param name="color">Ellipse color. </param> /// <param name="thickness">Thickness of the ellipse arc. </param> /// <param name="line_type">Type of the ellipse boundary.</param> /// <param name="shift">Number of fractional bits in the center coordinates and axes' values. </param> #endif public static void DrawEllipse(CvArr img, CvPoint center, CvSize axes, double angle, double start_angle, double end_angle, CvScalar color, int thickness, LineType line_type, int shift) { Ellipse(img, center, axes, angle, start_angle, end_angle, color, thickness, line_type, shift); }
// Draw Thesholded Image void DrawThresholdImage(CvMat _img) { // The HSV (hue, saturation, and value) range for thresholding // Hue, Saturation, Value or HSV is a color model that describes colors (hue or tint) // in terms of their shade (saturation or amount of gray) // and their brightness (value or luminance). // In openCV, the ranges for HSV are: // Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255] // CvScalar(H, S, V) CvScalar _cvScalarFrom = new CvScalar(_hueLow, _satLow, 0), _cvScalarTo = new CvScalar(_hueHigh, _satHigh, 255); Cv.ShowImage("HSV Thresholded Image", GetThresholdedImage(_img, _cvScalarFrom, _cvScalarTo)); }
public static extern void core_randn_Scalar(IntPtr dst, CvScalar mean, CvScalar stddev);
public static extern void core_line(IntPtr img, Point pt1, Point pt2, CvScalar color, int thickness, int lineType, int shift);
public static extern void core_setIdentity(IntPtr mtx, CvScalar s);
public static extern void core_randu_Scalar(IntPtr dst, CvScalar low, CvScalar high);
public static extern void core_inRange(IntPtr src, CvScalar lowerb, CvScalar upperb, IntPtr dst);
public static extern void core_meanStdDev_Scalar( IntPtr src, out CvScalar mean, out CvScalar stddev, IntPtr mask);
/// <summary> /// Write a contour to a SVG file. /// </summary> /// <param name="polygon">Polygon contour.</param> /// <param name="fileName">File name.</param> /// <param name="stroke">Stroke color (black by default).</param> /// <param name="fill">Fill color (white by default).</param> public static void WriteContourPolygonSvg(CvContourPolygon polygon, string fileName, CvScalar stroke, CvScalar fill) { if (polygon == null) { throw new ArgumentNullException(nameof(polygon)); } polygon.WriteAsSvg(fileName, stroke, fill); }
public static extern void gpu_Stream_enqueueMemSet(IntPtr obj, IntPtr src, CvScalar val);
public static extern void core_rectangle(IntPtr img, Rect rect, CvScalar color, int thickness, int lineType, int shift);
/// <summary> /// 枠だけの楕円,楕円弧,もしくは塗りつぶされた扇形の楕円を描画する /// </summary> /// <param name="img">楕円が描画される画像</param> /// <param name="center">楕円の中心</param> /// <param name="axes">楕円の軸の長さ</param> /// <param name="angle">回転角度</param> /// <param name="start_angle">楕円弧の開始角度</param> /// <param name="end_angle">楕円弧の終了角度</param> /// <param name="color">楕円の色</param> /// <param name="thickness">楕円弧の線の幅</param> /// <param name="line_type">楕円弧の線の種類</param> /// <param name="shift">中心座標と軸の長さの小数点以下の桁を表すビット数</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="center">Center of the ellipse. </param> /// <param name="axes">Length of the ellipse axes. </param> /// <param name="angle">Rotation angle. </param> /// <param name="start_angle">Starting angle of the elliptic arc. </param> /// <param name="end_angle">Ending angle of the elliptic arc. </param> /// <param name="color">Ellipse color. </param> /// <param name="thickness">Thickness of the ellipse arc. </param> /// <param name="line_type">Type of the ellipse boundary.</param> /// <param name="shift">Number of fractional bits in the center coordinates and axes' values. </param> #endif public static void Ellipse(CvArr img, CvPoint center, CvSize axes, double angle, double start_angle, double end_angle, CvScalar color, int thickness, LineType line_type, int shift) { if (img == null) { throw new ArgumentNullException("img"); } CvInvoke.cvEllipse(img.CvPtr, center, axes, angle, start_angle, end_angle, color, thickness, line_type, shift); }
public static extern void core_circle(IntPtr img, Point center, int radius, CvScalar color, int thickness, int lineType, int shift);
/// <summary> /// 枠だけの楕円,もしくは塗りつぶされた楕円を描画する /// </summary> /// <param name="img">楕円が描かれる画像.</param> /// <param name="box">描画したい楕円を囲む矩形領域.</param> /// <param name="color">楕円の色.</param> /// <param name="thickness">楕円境界線の幅.</param> /// <param name="line_type">楕円境界線の種類.</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="box">The enclosing box of the ellipse drawn </param> /// <param name="color">Ellipse color. </param> /// <param name="thickness">Thickness of the ellipse boundary. </param> /// <param name="line_type">Type of the ellipse boundary</param> #endif public static void EllipseBox(CvArr img, CvBox2D box, CvScalar color, int thickness, LineType line_type) { EllipseBox(img, box, color, thickness, line_type, 0); }
/// <summary> /// Draws or prints information about a blob. /// </summary> /// <param name="labels">Label data.</param> /// <param name="blob">Blob.</param> /// <param name="imgSource">Input image (depth=IPL_DEPTH_8U and num. channels=3).</param> /// <param name="imgDest">Output image (depth=IPL_DEPTH_8U and num. channels=3).</param> /// <param name="mode">Render mode. By default is CV_BLOB_RENDER_COLOR|CV_BLOB_RENDER_CENTROID|CV_BLOB_RENDER_BOUNDING_BOX|CV_BLOB_RENDER_ANGLE.</param> /// <param name="color">Color to render (if CV_BLOB_RENDER_COLOR is used).</param> public static void RenderBlob(LabelData labels, CvBlob blob, IplImage imgSource, IplImage imgDest, RenderBlobsMode mode, CvScalar color) { RenderBlob(labels, blob, imgSource, imgDest, mode, color, 1.0); }
// Convert the Texture2D type of Unity to OpenCV's CvMat // This uses Adcock's parallel C# code to parallelize the conversion and make it faster // I found the code execution dropped from 180 msec per frame to 70 msec per frame with parallelization void Texture2DToMat(Texture2D tex, Mat m) { //float startTime = Time.realtimeSinceStartup; Color[] pixels = tex.GetPixels(); // Parallel for loop Parallel.For(0, imHeight, i => { for (var j = 0; j < imWidth; j++) { var pixel = pixels[j + i * imWidth]; var col = new CvScalar { Val0 = (double)pixel.b * 255, Val1 = (double)pixel.g * 255, Val2 = (double)pixel.r * 255 }; m.Set(i, j, col); } }); // CvScalar col; // Color pixel; // int i, j; // // // Non-parallelized code // for (i = 0; i < imHeight; i++) { // for (j = 0; j < imWidth; j++) { // pixel = pixels [j + i * imWidth]; // // col = new CvScalar // { // Val0 = (double)pixel.b * 255, // Val1 = (double)pixel.g * 255, // Val2 = (double)pixel.r * 255 // }; // // videoSourceImage.Set2D (i, j, col); // } // // } // Flip up/down dimension and right/left dimension if (!FlipUpDownAxis && FlipLeftRightAxis) m.Flip(FlipMode.XY); else if (!FlipUpDownAxis) m.Flip(FlipMode.X); else if (FlipLeftRightAxis) m.Flip(FlipMode.Y); // Test difference in time between parallel and non-parallel code //Debug.Log (Time.realtimeSinceStartup - startTime); }
public static extern void cvSetIdentity(IntPtr mat, CvScalar value);
public static extern void imgproc_remap(IntPtr src, IntPtr dst, IntPtr map1, IntPtr map2, int interpolation, int borderMode, CvScalar borderValue);
/// <summary> /// 指定の構造要素を用いて画像の収縮を行います. /// </summary> /// <param name="element">収縮に用いられる構造要素. element=new Mat() の場合, 3x3 の矩形の構造要素が用いられます</param> /// <param name="anchor">構造要素内のアンカー位置.デフォルト値の (-1, -1) は,アンカーが構造要素の中心にあることを意味します</param> /// <param name="iterations">収縮が行われる回数. [既定値は1]</param> /// <param name="borderType">ピクセル外挿手法.[既定値はBorderType.Constant]</param> /// <param name="borderValue">定数境界モードで利用されるピクセル値.デフォルト値は特別な意味を持ちます.[既定値はCvCpp.MorphologyDefaultBorderValue()]</param> /// <returns>src と同じサイズ,同じ型の出力画像</returns> #else /// <summary> /// Erodes an image by using a specific structuring element. /// </summary> /// <param name="element">The structuring element used for dilation. If element=new Mat(), a 3x3 rectangular structuring element is used</param> /// <param name="anchor">Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center</param> /// <param name="iterations">The number of times erosion is applied</param> /// <param name="borderType">The pixel extrapolation method</param> /// <param name="borderValue">The border value in case of a constant border. The default value has a special meaning. [By default this is CvCpp.MorphologyDefaultBorderValue()]</param> /// <returns>The destination image. It will have the same size and the same type as src</returns> #endif public Mat Erode(InputArray element, CvPoint? anchor = null, int iterations = 1, BorderType borderType = BorderType.Constant, CvScalar? borderValue = null) { var dst = new Mat(); Cv2.Erode(this, dst, element, anchor, iterations, borderType, borderValue); return dst; }
public static extern IntPtr GpuMat_new8(int rows, int cols, [MarshalAs(UnmanagedType.I4)] MatrixType type, CvScalar s);
/// <summary> /// Applies a generic geometrical transformation to an image. /// </summary> /// <param name="map1">The first map of either (x,y) points or just x values having the type CV_16SC2, CV_32FC1, or CV_32FC2.</param> /// <param name="map2">The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively.</param> /// <param name="interpolation">Interpolation method. The method INTER_AREA is not supported by this function.</param> /// <param name="borderMode">Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, /// it means that the pixels in the destination image that corresponds to the "outliers" in /// the source image are not modified by the function.</param> /// <param name="borderValue">Value used in case of a constant border. By default, it is 0.</param> /// <returns>Destination image. It has the same size as map1 and the same type as src</returns> public Mat Remap(InputArray map1, InputArray map2, Interpolation interpolation = Interpolation.Linear, BorderType borderMode = BorderType.Constant, CvScalar? borderValue = null) { var dst = new Mat(); Cv2.Remap(this, dst, map1, map2, interpolation, borderMode, borderValue); return dst; }
public static extern void core_Mat_resize2(IntPtr obj, IntPtr sz, CvScalar s);
/// <summary> /// 画像上にテキストを描画する際に利用されるフォントを作成します. /// </summary> /// <param name="nameFont">フォント名. 指定のフォントが見つからなければ,デフォルトフォントが利用されます.</param> /// <param name="pointSize">ォントサイズ.これが,未指定,または0以下の値の場合,フォンとのポイントサイズはシステム依存のデフォルト値にセットされます.通常は,12ポイントです.</param> /// <param name="color">BGRA で表現されるフォントカラー.</param> /// <param name="weight">フォントの太さ</param> /// <param name="style">処理フラグ</param> /// <param name="spacing">文字間のスペース.正負の値が利用できます.</param> #else /// <summary> /// Create the font to be used to draw text on an image /// </summary> /// <param name="nameFont">Name of the font. The name should match the name of a system font (such as ``Times’‘). If the font is not found, a default one will be used.</param> /// <param name="pointSize">Size of the font. If not specified, equal zero or negative, the point size of the font is set to a system-dependent default value. Generally, this is 12 points.</param> /// <param name="color">Color of the font in BGRA – A = 255 is fully transparent. Use the macro CV _ RGB for simplicity.</param> /// <param name="weight">The operation flags</param> /// <param name="style">The operation flags</param> /// <param name="spacing">Spacing between characters. Can be negative or positive.</param> #endif public CvFontQt(string nameFont, int pointSize, CvScalar color, FontWeight weight, FontStyle style, int spacing) { if (nameFont == null) throw new ArgumentNullException("nameFont"); ptr = base.AllocMemory(SizeOf); WCvFont font = CvInvoke.cvFontQt(nameFont, pointSize, color, weight, style, spacing); using (ScopedGCHandle gch = new ScopedGCHandle(font, GCHandleType.Pinned)) { Util.CopyMemory(ptr, gch.AddrOfPinnedObject(), SizeOf); } }
public static extern void core_ellipse(IntPtr img, Point center, Size axes, double angle, double startAngle, double endAngle, CvScalar color, int thickness, int lineType, int shift);
/// <summary> /// Draws or prints information about a blob. /// </summary> /// <param name="labels">Label data.</param> /// <param name="blob">Blob.</param> /// <param name="imgSource">Input image (depth=IPL_DEPTH_8U and num. channels=3).</param> /// <param name="imgDest">Output image (depth=IPL_DEPTH_8U and num. channels=3).</param> /// <param name="mode">Render mode. By default is CV_BLOB_RENDER_COLOR|CV_BLOB_RENDER_CENTROID|CV_BLOB_RENDER_BOUNDING_BOX|CV_BLOB_RENDER_ANGLE.</param> /// <param name="color">Color to render (if CV_BLOB_RENDER_COLOR is used).</param> /// <param name="alpha">If mode CV_BLOB_RENDER_COLOR is used. 1.0 indicates opaque and 0.0 translucent (1.0 by default).</param> public static void RenderBlob(LabelData labels, CvBlob blob, IplImage imgSource, IplImage imgDest, RenderBlobsMode mode, CvScalar color, double alpha) { if (labels == null) { throw new ArgumentNullException(nameof(labels)); } if (blob == null) { throw new ArgumentNullException(nameof(blob)); } if (imgSource == null) { throw new ArgumentNullException(nameof(imgSource)); } if (imgDest == null) { throw new ArgumentNullException(nameof(imgDest)); } BlobRenderer.PerformOne(labels, blob, imgSource, imgDest, mode, color, alpha); }
public static extern void cvSetND(IntPtr arr, int[] idx, CvScalar value);
public static extern void core_ellipse(IntPtr img, RotatedRect box, CvScalar color, int thickness, int lineType);
public static extern void cvSubRS(IntPtr src, CvScalar value, IntPtr dst, IntPtr mask);
public static extern void core_fillConvexPoly(IntPtr img, Point[] pts, int npts, CvScalar color, int lineType, int shift);
/// <summary> /// 高度なモルフォロジー変換を行います. /// </summary> /// <param name="op">モルフォロジー演算の種類</param> /// <param name="element">構造要素</param> /// <param name="anchor">構造要素内のアンカー位置.デフォルト値の (-1, -1) は,アンカーが構造要素の中心にあることを意味します.</param> /// <param name="iterations">収縮と膨張が適用される回数. [既定値は1]</param> /// <param name="borderType">ピクセル外挿手法. [既定値はBorderType.Constant]</param> /// <param name="borderValue">定数境界モードで利用されるピクセル値.デフォルト値は特別な意味を持ちます. [既定値は CvCpp.MorphologyDefaultBorderValue()]</param> /// <returns>src と同じサイズ,同じ型の出力画像</returns> #else /// <summary> /// Performs advanced morphological transformations /// </summary> /// <param name="op">Type of morphological operation</param> /// <param name="element">Structuring element</param> /// <param name="anchor">Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center</param> /// <param name="iterations">Number of times erosion and dilation are applied. [By default this is 1]</param> /// <param name="borderType">The pixel extrapolation method. [By default this is BorderType.Constant]</param> /// <param name="borderValue">The border value in case of a constant border. The default value has a special meaning. [By default this is CvCpp.MorphologyDefaultBorderValue()]</param> /// <returns>Destination image. It will have the same size and the same type as src</returns> #endif public Mat MorphologyEx(MorphologyOperation op, InputArray element, CvPoint? anchor = null, int iterations = 1, BorderType borderType = BorderType.Constant, CvScalar? borderValue = null) { var dst = new Mat(); Cv2.MorphologyEx(this, dst, op, element, anchor, iterations, borderType, borderValue); return dst; }
public static extern void core_fillPoly(IntPtr img, IntPtr[] pts, int[] npts, int ncontours, CvScalar color, int lineType, int shift, Point offset);
/// <summary> /// 2点を結ぶ線分を画像上に描画する. /// </summary> /// <param name="pt1X">線分の1番目の端点x</param> /// <param name="pt1Y">線分の1番目の端点y</param> /// <param name="pt2X">線分の2番目の端点x</param> /// <param name="pt2Y">線分の2番目の端点y</param> /// <param name="color">線分の色</param> /// <param name="thickness">線分の太さ. [既定値は1]</param> /// <param name="lineType">線分の種類. [既定値はLineType.Link8]</param> /// <param name="shift">座標の小数点以下の桁を表すビット数. [既定値は0]</param> #else /// <summary> /// Draws a line segment connecting two points /// </summary> /// <param name="pt1X">First point's x-coordinate of the line segment. </param> /// <param name="pt1Y">First point's y-coordinate of the line segment. </param> /// <param name="pt2X">Second point's x-coordinate of the line segment. </param> /// <param name="pt2Y">Second point's y-coordinate of the line segment. </param> /// <param name="color">Line color. </param> /// <param name="thickness">Line thickness. [By default this is 1]</param> /// <param name="lineType">Type of the line. [By default this is LineType.Link8]</param> /// <param name="shift">Number of fractional bits in the point coordinates. [By default this is 0]</param> #endif public void Line(int pt1X, int pt1Y, int pt2X, int pt2Y, CvScalar color, int thickness = 1, LineType lineType = LineType.Link8, int shift = 0) { Cv2.Line(this, pt1X, pt1Y, pt2X, pt2Y, color, thickness, lineType, shift); }
public static extern void core_polylines(IntPtr img, IntPtr[] pts, int[] npts, int ncontours, int isClosed, CvScalar color, int thickness, int lineType, int shift);
/// <summary> /// 画像上にテキストを描画する際に利用されるフォントを作成します. /// </summary> /// <param name="nameFont">フォント名. 指定のフォントが見つからなければ,デフォルトフォントが利用されます.</param> /// <param name="pointSize">ォントサイズ.これが,未指定,または0以下の値の場合,フォンとのポイントサイズはシステム依存のデフォルト値にセットされます.通常は,12ポイントです.</param> /// <param name="color">BGRA で表現されるフォントカラー.</param> /// <param name="weight">フォントの太さ</param> #else /// <summary> /// Create the font to be used to draw text on an image /// </summary> /// <param name="nameFont">Name of the font. The name should match the name of a system font (such as ``Times’‘). If the font is not found, a default one will be used.</param> /// <param name="pointSize">Size of the font. If not specified, equal zero or negative, the point size of the font is set to a system-dependent default value. Generally, this is 12 points.</param> /// <param name="color">Color of the font in BGRA – A = 255 is fully transparent. Use the macro CV _ RGB for simplicity.</param> /// <param name="weight">The operation flags</param> #endif public CvFontQt(string nameFont, int pointSize, CvScalar color, FontWeight weight) : this(nameFont, pointSize, color, weight, FontStyle.Normal, 0) { }
public static extern void core_putText(IntPtr img, [MarshalAs(UnmanagedType.LPStr)] string text, CvPoint org, int fontFace, double fontScale, CvScalar color, int thickness, int lineType, int bottomLeftOrigin);
public static extern void gpu_Stream_enqueueMemSet_WithMask(IntPtr obj, IntPtr src, CvScalar val, IntPtr mask);
public static extern void features2d_drawKeypoints(IntPtr image, KeyPoint[] keypoints, int keypointsLength, IntPtr outImage, CvScalar color, int flags);
/// <summary> /// 枠だけの楕円,楕円弧,もしくは塗りつぶされた扇形の楕円を描画する /// </summary> /// <param name="img">楕円が描画される画像</param> /// <param name="center">楕円の中心</param> /// <param name="axes">楕円の軸の長さ</param> /// <param name="angle">回転角度</param> /// <param name="start_angle">楕円弧の開始角度</param> /// <param name="end_angle">楕円弧の終了角度</param> /// <param name="color">楕円の色</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="center">Center of the ellipse. </param> /// <param name="axes">Length of the ellipse axes. </param> /// <param name="angle">Rotation angle. </param> /// <param name="start_angle">Starting angle of the elliptic arc. </param> /// <param name="end_angle">Ending angle of the elliptic arc. </param> /// <param name="color">Ellipse color. </param> #endif public static void DrawEllipse(CvArr img, CvPoint center, CvSize axes, double angle, double start_angle, double end_angle, CvScalar color) { Ellipse(img, center, axes, angle, start_angle, end_angle, color, 1, LineType.Link8, 0); }
public static extern void features2d_drawMatches2(IntPtr img1, KeyPoint[] keypoints1, int keypoints1Length, IntPtr img2, KeyPoint[] keypoints2, int keypoints2Length, IntPtr[] matches1to2, int matches1to2Size1, int[] matches1to2Size2, IntPtr outImg, CvScalar matchColor, CvScalar singlePointColor, IntPtr[] matchesMask, int matchesMaskSize1, int[] matchesMaskSize2, int flags);
/// <summary> /// 枠だけの楕円,もしくは塗りつぶされた楕円を描画する /// </summary> /// <param name="img">楕円が描かれる画像.</param> /// <param name="box">描画したい楕円を囲む矩形領域.</param> /// <param name="color">楕円の色.</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="box">The enclosing box of the ellipse drawn </param> /// <param name="color">Ellipse color. </param> #endif public static void EllipseBox(CvArr img, CvBox2D box, CvScalar color) { EllipseBox(img, box, color, 1, LineType.Link8, 0); }
public Affine() { // cvGetAffineTransform + cvWarpAffine using (IplImage srcImg = new IplImage(FilePath.Image.Goryokaku, LoadMode.AnyDepth | LoadMode.AnyColor)) using (IplImage dstImg = srcImg.Clone()) { CvPoint2D32f[] srcPnt = new CvPoint2D32f[3]; CvPoint2D32f[] dstPnt = new CvPoint2D32f[3]; srcPnt[0] = new CvPoint2D32f(200.0f, 200.0f); srcPnt[1] = new CvPoint2D32f(250.0f, 200.0f); srcPnt[2] = new CvPoint2D32f(200.0f, 100.0f); dstPnt[0] = new CvPoint2D32f(300.0f, 100.0f); dstPnt[1] = new CvPoint2D32f(300.0f, 50.0f); dstPnt[2] = new CvPoint2D32f(200.0f, 100.0f); using (CvMat mapMatrix = Cv.GetAffineTransform(srcPnt, dstPnt)) { Cv.WarpAffine(srcImg, dstImg, mapMatrix, Interpolation.Linear | Interpolation.FillOutliers, CvScalar.ScalarAll(0)); using (new CvWindow("src", srcImg)) using (new CvWindow("dst", dstImg)) { Cv.WaitKey(0); } } } }
/// <summary> /// 枠だけの楕円,もしくは塗りつぶされた楕円を描画する /// </summary> /// <param name="img">楕円が描かれる画像.</param> /// <param name="box">描画したい楕円を囲む矩形領域.</param> /// <param name="color">楕円の色.</param> /// <param name="thickness">楕円境界線の幅.</param> /// <param name="line_type">楕円境界線の種類.</param> /// <param name="shift">矩形領域の頂点座標の小数点以下の桁を表すビット数.</param> #else /// <summary> /// Draws simple or thick elliptic arc or fills ellipse sector /// </summary> /// <param name="img">Image. </param> /// <param name="box">The enclosing box of the ellipse drawn </param> /// <param name="color">Ellipse color. </param> /// <param name="thickness">Thickness of the ellipse boundary. </param> /// <param name="line_type">Type of the ellipse boundary</param> /// <param name="shift">Number of fractional bits in the box vertex coordinates. </param> #endif public static void EllipseBox(CvArr img, CvBox2D box, CvScalar color, int thickness, LineType line_type, int shift) { if (img == null) { throw new ArgumentNullException("img"); } CvSize axes = new CvSize { Width = (int)Math.Round(box.Size.Height * 0.5), Height = (int)Math.Round(box.Size.Width * 0.5) }; Ellipse(img, box.Center, axes, box.Angle, 0, 360, color, thickness, line_type, shift); }
public static extern void imgproc_dilate(IntPtr src, IntPtr dst, IntPtr kernel, Point anchor, int iterations, int borderType, CvScalar borderValue);
// Threshold the image based on the HSV value // From and To are CvScalars of 3 values {Hue, Saturation, and (Brightness) Value) CvMat GetThresholdedImage(CvMat img, CvScalar from, CvScalar to) { // Hue, Saturation, Value or HSV is a color model that describes colors (hue or tint) // in terms of their shade (saturation or amount of gray) // and their brightness (value or luminance). // Hue is expressed as a number from 0 to 360 degrees representing hues of red (starts at 0), // yellow (starts at 60), green (starts at 120), cyan (starts at 180), // blue (starts at 240), and magenta (starts at 300). // Saturation is the amount of gray (0% to 100%) in the color. // Value (or Brightness) works in conjunction with saturation and // describes the brightness or intensity of the color from 0% to 100%. CvMat imgHsv = ConvertToHSV(img); CvMat imgThreshed = new CvMat(img.Rows, img.Cols, MonoColorMatrix); imgHsv.InRangeS(from, to, imgThreshed); return imgThreshed; }
public static extern void imgproc_morphologyEx(IntPtr src, IntPtr dst, int op, IntPtr kernel, Point anchor, int iterations, int borderType, CvScalar borderValue);
public static extern IntPtr core_OutputArray_new_byScalar(CvScalar val);
public static extern void imgproc_warpPerspective(IntPtr src, IntPtr dst, IntPtr M, CvSize dsize, int flags, int borderMode, CvScalar borderValue);