当前位置: 首页>>代码示例>>C#>>正文


C# Scalar.GetValueOrDefault方法代码示例

本文整理汇总了C#中Scalar.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Scalar.GetValueOrDefault方法的具体用法?C# Scalar.GetValueOrDefault怎么用?C# Scalar.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scalar的用法示例。


在下文中一共展示了Scalar.GetValueOrDefault方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyMakeBorder

 /// <summary>
 /// Forms a border around the image
 /// </summary>
 /// <param name="src">The source image</param>
 /// <param name="dst">The destination image; will have the same type as src and 
 /// the size Size(src.cols+left+right, src.rows+top+bottom)</param>
 /// <param name="top">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param>
 /// <param name="bottom">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param>
 /// <param name="left">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param>
 /// <param name="right">Specify how much pixels in each direction from the source image rectangle one needs to extrapolate</param>
 /// <param name="borderType">The border type</param>
 /// <param name="value">The border value if borderType == Constant</param>
 public static void CopyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, BorderType borderType, Scalar? value = null)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     Scalar value0 = value.GetValueOrDefault(new Scalar());
     NativeMethods.imgproc_copyMakeBorder(src.CvPtr, dst.CvPtr, top, bottom, left, right, (int)borderType, value0);
     dst.Fix();
 }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:24,代码来源:Cv2_imgproc.cs

示例2: DrawKeypoints

        /// <summary>
        /// Draw keypoints.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="keypoints"></param>
        /// <param name="outImage"></param>
        /// <param name="color"></param>
        /// <param name="flags"></param>
        public static void DrawKeypoints(Mat image, IEnumerable<KeyPoint> keypoints, Mat outImage,
            Scalar? color = null, DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            if (outImage == null)
                throw new ArgumentNullException("outImage");
            if (keypoints == null)
                throw new ArgumentNullException("keypoints");
            image.ThrowIfDisposed();
            outImage.ThrowIfDisposed();

            KeyPoint[] keypointsArray = EnumerableEx.ToArray(keypoints);
            Scalar color0 = color.GetValueOrDefault(Scalar.All(-1));
            NativeMethods.features2d_drawKeypoints(image.CvPtr, keypointsArray, keypointsArray.Length,
                outImage.CvPtr, color0, (int)flags);
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:25,代码来源:Cv2_features2d.cs

示例3: SetIdentity

 /// <summary>
 /// initializes scaled identity matrix
 /// </summary>
 /// <param name="mtx">The matrix to initialize (not necessarily square)</param>
 /// <param name="s">The value to assign to the diagonal elements</param>
 public static void SetIdentity(InputOutputArray mtx, Scalar? s = null)
 {
     if (mtx == null)
         throw new ArgumentNullException("mtx");
     mtx.ThrowIfNotReady();
     Scalar s0 = s.GetValueOrDefault(new Scalar(1));
     NativeMethods.core_setIdentity(mtx.CvPtr, s0);
     mtx.Fix();
 }
开发者ID:fdncred,项目名称:opencvsharp,代码行数:14,代码来源:Cv2_core.cs

示例4: WarpPerspective

        /// <summary>
        /// 画像の透視変換を行います.
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">サイズが dsize で src と同じタイプの出力画像</param>
        /// <param name="m">3x3 の変換行列</param>
        /// <param name="dsize">出力画像のサイズ</param>
        /// <param name="flags">補間手法</param>
        /// <param name="borderMode">ピクセル外挿手法.
        /// borderMode=BORDER_TRANSPARENT の場合,入力画像中の「はずれ値」に対応する
        /// 出力画像中のピクセルが,この関数では変更されないことを意味します</param>
        /// <param name="borderValue">定数境界モードで利用されるピクセル値.</param>
#else
        /// <summary>
        /// Applies a perspective transformation to an image.
        /// </summary>
        /// <param name="src">input image.</param>
        /// <param name="dst">output image that has the size dsize and the same type as src.</param>
        /// <param name="m">3x3 transformation matrix.</param>
        /// <param name="dsize">size of the output image.</param>
        /// <param name="flags">combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) 
        /// and the optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (dst -> src).</param>
        /// <param name="borderMode">pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).</param>
        /// <param name="borderValue">value used in case of a constant border; by default, it equals 0.</param>
#endif
        public static void WarpPerspective(InputArray src, OutputArray dst, float[,] m, Size dsize,
            Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant,
            Scalar? borderValue = null)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");
            if (m == null)
                throw new ArgumentNullException("m");
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            CvScalar borderValue0 = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0));
            int mRow = m.GetLength(0);
            int mCol = m.GetLength(1);
            NativeMethods.imgproc_warpPerspective_MisArray(
                src.CvPtr, dst.CvPtr, m, mRow, mCol, dsize, (int)flags, (int)borderMode, borderValue0);
            dst.Fix();
        }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:44,代码来源:Cv2_imgproc.cs

示例5: WarpAffine

 /// <summary>
 /// Applies an affine transformation to an image.
 /// </summary>
 /// <param name="src">input image.</param>
 /// <param name="dst">output image that has the size dsize and the same type as src.</param>
 /// <param name="m">2x3 transformation matrix.</param>
 /// <param name="dsize">size of the output image.</param>
 /// <param name="flags">combination of interpolation methods and the optional flag 
 /// WARP_INVERSE_MAP that means that M is the inverse transformation (dst -> src) .</param>
 /// <param name="borderMode">pixel extrapolation method; when borderMode=BORDER_TRANSPARENT, 
 /// it means that the pixels in the destination image corresponding 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>
 public static void WarpAffine(InputArray src, OutputArray dst, InputArray m, Size dsize,
     Interpolation flags = Interpolation.Linear, BorderType borderMode = BorderType.Constant, Scalar? borderValue = null)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     if (m == null)
         throw new ArgumentNullException("m");
     src.ThrowIfDisposed();
     dst.ThrowIfDisposed();
     m.ThrowIfDisposed();
     CvScalar borderValue0 = borderValue.GetValueOrDefault(CvScalar.ScalarAll(0));
     NativeMethods.imgproc_warpAffine(src.CvPtr, dst.CvPtr, m.CvPtr, dsize, (int)flags, (int)borderMode, borderValue0);
     dst.Fix();
 }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:29,代码来源:Cv2_imgproc.cs

示例6: Dilate

        /// <summary>
        /// 指定の構造要素を用いて画像の膨張を行います.
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">src と同じサイズ,同じ型の出力画像</param>
        /// <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>
#else
        /// <summary>
        /// Dilates an image by using a specific structuring element.
        /// </summary>
        /// <param name="src">The source image</param>
        /// <param name="dst">The destination image. It will have the same size and the same type as src</param>
        /// <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 dilation is 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>
#endif
        public static void Dilate(InputArray src, OutputArray dst, InputArray element,
            Point? anchor = null, int iterations = 1, BorderType borderType = BorderType.Constant, Scalar? borderValue = null)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));
            Scalar borderValue0 = borderValue.GetValueOrDefault(MorphologyDefaultBorderValue());
            IntPtr elementPtr = ToPtr(element);
            NativeMethods.imgproc_dilate(src.CvPtr, dst.CvPtr, elementPtr, anchor0, iterations, (int)borderType, borderValue0);
            dst.Fix();
        }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:38,代码来源:Cv2_imgproc.cs

示例7: FloodFill

 /// <summary>
 /// Fills a connected component with the given color.
 /// </summary>
 /// <param name="image">Input/output 1- or 3-channel, 8-bit, or floating-point image. 
 /// It is modified by the function unless the FLOODFILL_MASK_ONLY flag is set in the 
 /// second variant of the function. See the details below.</param>
 /// <param name="mask">(For the second function only) Operation mask that should be a single-channel 8-bit image, 
 /// 2 pixels wider and 2 pixels taller. The function uses and updates the mask, so you take responsibility of 
 /// initializing the mask content. Flood-filling cannot go across non-zero pixels in the mask. For example, 
 /// an edge detector output can be used as a mask to stop filling at edges. It is possible to use the same mask 
 /// in multiple calls to the function to make sure the filled area does not overlap.</param>
 /// <param name="seedPoint">Starting point.</param>
 /// <param name="newVal">New value of the repainted domain pixels.</param>
 /// <param name="rect">Optional output parameter set by the function to the 
 /// minimum bounding rectangle of the repainted domain.</param>
 /// <param name="loDiff">Maximal lower brightness/color difference between the currently 
 /// observed pixel and one of its neighbors belonging to the component, or a seed pixel 
 /// being added to the component.</param>
 /// <param name="upDiff">Maximal upper brightness/color difference between the currently 
 /// observed pixel and one of its neighbors belonging to the component, or a seed pixel 
 /// being added to the component.</param>
 /// <param name="flags">Operation flags. Lower bits contain a connectivity value, 
 /// 4 (default) or 8, used within the function. Connectivity determines which 
 /// neighbors of a pixel are considered. </param>
 /// <returns></returns>
 public static int FloodFill(InputOutputArray image, InputOutputArray mask,
                             Point seedPoint, Scalar newVal, out Rect rect,
                             Scalar? loDiff = null, Scalar? upDiff = null,
                             FloodFillFlag flags = FloodFillFlag.Link4)
 {
     if (image == null)
         throw new ArgumentNullException("image");
     if (mask == null)
         throw new ArgumentNullException("mask");
     image.ThrowIfNotReady();
     mask.ThrowIfNotReady();
     Scalar loDiff0 = loDiff.GetValueOrDefault(new Scalar());
     Scalar upDiff0 = upDiff.GetValueOrDefault(new Scalar());
     CvRect rect0;
     int ret = NativeMethods.imgproc_floodFill(image.CvPtr, mask.CvPtr, seedPoint, 
         newVal, out rect0, loDiff0, upDiff0, (int)flags);
     rect = rect0;
     image.Fix();
     mask.Fix();
     return ret;
 }
开发者ID:josephgodwinkimani,项目名称:opencvsharp,代码行数:46,代码来源:Cv2_imgproc.cs

示例8: DrawMatches

        /// <summary>
        /// Draws matches of keypints from two images on output image.
        /// </summary>
        /// <param name="img1"></param>
        /// <param name="keypoints1"></param>
        /// <param name="img2"></param>
        /// <param name="keypoints2"></param>
        /// <param name="matches1To2"></param>
        /// <param name="outImg"></param>
        /// <param name="matchColor"></param>
        /// <param name="singlePointColor"></param>
        /// <param name="matchesMask"></param>
        /// <param name="flags"></param>
        public static void DrawMatches(Mat img1, IEnumerable<KeyPoint> keypoints1,
            Mat img2, IEnumerable<KeyPoint> keypoints2,
            IEnumerable<IEnumerable<DMatch>> matches1To2, Mat outImg,
            Scalar? matchColor = null, Scalar? singlePointColor = null,
            IEnumerable<IEnumerable<byte>> matchesMask = null,
            DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (img1 == null)
                throw new ArgumentNullException(nameof(img1));
            if (img2 == null)
                throw new ArgumentNullException(nameof(img2));
            if (outImg == null)
                throw new ArgumentNullException(nameof(outImg));
            if (keypoints1 == null)
                throw new ArgumentNullException(nameof(keypoints1));
            if (keypoints2 == null)
                throw new ArgumentNullException(nameof(keypoints2));
            if (matches1To2 == null)
                throw new ArgumentNullException(nameof(matches1To2));
            img1.ThrowIfDisposed();
            img2.ThrowIfDisposed();
            outImg.ThrowIfDisposed();

            KeyPoint[] keypoints1Array = EnumerableEx.ToArray(keypoints1);
            KeyPoint[] keypoints2Array = EnumerableEx.ToArray(keypoints2);
            DMatch[][] matches1To2Array = EnumerableEx.SelectToArray(matches1To2, EnumerableEx.ToArray);
            int matches1To2Size1 = matches1To2Array.Length;
            int[] matches1To2Size2 = EnumerableEx.SelectToArray(matches1To2Array, dm => dm.Length);
            Scalar matchColor0 = matchColor.GetValueOrDefault(Scalar.All(-1));
            Scalar singlePointColor0 = singlePointColor.GetValueOrDefault(Scalar.All(-1));

            using (var matches1To2Ptr = new ArrayAddress2<DMatch>(matches1To2Array))
            {
                if (matchesMask == null)
                {
                    NativeMethods.features2d_drawMatches2(img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                        img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                        matches1To2Ptr, matches1To2Size1, matches1To2Size2,
                        outImg.CvPtr, matchColor0, singlePointColor0, 
                        null, 0, null, (int)flags);
                }
                else
                {
                    byte[][] matchesMaskArray = EnumerableEx.SelectToArray(matchesMask, EnumerableEx.ToArray);
                    int matchesMaskSize1 = matches1To2Array.Length;
                    int[] matchesMaskSize2 = EnumerableEx.SelectToArray(matchesMaskArray, dm => dm.Length);
                    using (var matchesMaskPtr = new ArrayAddress2<byte>(matchesMaskArray))
                    {
                        NativeMethods.features2d_drawMatches2(img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                            img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                            matches1To2Ptr.Pointer, matches1To2Size1, matches1To2Size2,
                            outImg.CvPtr, matchColor0, singlePointColor0,
                            matchesMaskPtr, matchesMaskSize1, matchesMaskSize2, (int)flags);
                    }
                }
            }
        }
开发者ID:shimat,项目名称:opencvsharp,代码行数:70,代码来源:Cv2_features2d.cs

示例9: WarpPerspective

        /// <summary>
        /// 画像の透視変換を行います.
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">サイズが dsize で src と同じタイプの出力画像</param>
        /// <param name="m">3x3 の変換行列</param>
        /// <param name="dsize">出力画像のサイズ</param>
        /// <param name="flags">補間手法</param>
        /// <param name="borderMode">ピクセル外挿手法.
        /// borderMode=BORDER_TRANSPARENT の場合,入力画像中の「はずれ値」に対応する
        /// 出力画像中のピクセルが,この関数では変更されないことを意味します</param>
        /// <param name="borderValue">定数境界モードで利用されるピクセル値.</param>
#else
        /// <summary>
        /// Applies a perspective transformation to an image.
        /// </summary>
        /// <param name="src">input image.</param>
        /// <param name="dst">output image that has the size dsize and the same type as src.</param>
        /// <param name="m">3x3 transformation matrix.</param>
        /// <param name="dsize">size of the output image.</param>
        /// <param name="flags">combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) 
        /// and the optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (dst -> src).</param>
        /// <param name="borderMode">pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).</param>
        /// <param name="borderValue">value used in case of a constant border; by default, it equals 0.</param>
#endif
        public static void WarpPerspective(
            InputArray src, OutputArray dst, InputArray m, Size dsize,
            InterpolationFlags flags = InterpolationFlags.Linear, 
            BorderTypes borderMode = BorderTypes.Constant, 
            Scalar? borderValue = null)
        {
            if (src == null)
                throw new ArgumentNullException(nameof(src));
            if (dst == null)
                throw new ArgumentNullException(nameof(dst));
            if (m == null)
                throw new ArgumentNullException(nameof(m));
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            m.ThrowIfDisposed();
            Scalar borderValue0 = borderValue.GetValueOrDefault(Scalar.All(0));
            NativeMethods.imgproc_warpPerspective_MisInputArray(
                src.CvPtr, dst.CvPtr, m.CvPtr, dsize, (int)flags, (int)borderMode, borderValue0);
            GC.KeepAlive(src);
            dst.Fix();
        }
开发者ID:shimat,项目名称:opencvsharp,代码行数:46,代码来源:Cv2_imgproc.cs

示例10: Remap

 /// <summary>
 /// Applies a generic geometrical transformation to an image.
 /// </summary>
 /// <param name="src">Source image.</param>
 /// <param name="dst">Destination image. It has the same size as map1 and the same type as src</param>
 /// <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>
 public static void Remap(
     InputArray src, OutputArray dst, InputArray map1, InputArray map2,
     InterpolationFlags interpolation = InterpolationFlags.Linear, 
     BorderTypes borderMode = BorderTypes.Constant, Scalar? borderValue = null)
 {
     if (src == null)
         throw new ArgumentNullException(nameof(src));
     if (dst == null)
         throw new ArgumentNullException(nameof(dst));
     if (map1 == null)
         throw new ArgumentNullException(nameof(map1));
     if (map2 == null)
         throw new ArgumentNullException(nameof(map2));
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     map1.ThrowIfDisposed();
     map2.ThrowIfDisposed();
     Scalar borderValue0 = borderValue.GetValueOrDefault(Scalar.All(0));
     NativeMethods.imgproc_remap(src.CvPtr, dst.CvPtr, map1.CvPtr, map2.CvPtr, (int)interpolation, (int)borderMode, borderValue0);
     GC.KeepAlive(src);
     dst.Fix();
 }
开发者ID:shimat,项目名称:opencvsharp,代码行数:34,代码来源:Cv2_imgproc.cs


注:本文中的Scalar.GetValueOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。