Exemplo n.º 1
0
        /// <summary>
        /// This function is an extended version of cvInitUndistortMap. That is, in addition to the correction of lens distortion, the function can also apply arbitrary perspective transformation R and finally it can scale and shift the image according to the new camera matrix
        /// </summary>
        /// <param name="cameraMatrix">The camera matrix A=[fx 0 cx; 0 fy cy; 0 0 1]</param>
        /// <param name="distCoeffs">The vector of distortion coefficients, 4x1, 1x4, 5x1 or 1x5</param>
        /// <param name="R">The rectification transformation in object space (3x3 matrix). R1 or R2, computed by cvStereoRectify can be passed here. If the parameter is IntPtr.Zero, the identity matrix is used</param>
        /// <param name="newCameraMatrix">The new camera matrix A'=[fx' 0 cx'; 0 fy' cy'; 0 0 1]</param>
        /// <param name="depthType">Depth type of the first output map that can be CV_32FC1 or CV_16SC2 .</param>
        /// <param name="map1">The first output map.</param>
        /// <param name="map2">The second output map.</param>
        /// <param name="size">Undistorted image size.</param>
        public static void InitUndistortRectifyMap(
            IInputArray cameraMatrix,
            IInputArray distCoeffs,
            IInputArray R,
            IInputArray newCameraMatrix,
            Size size,
            CvEnum.DepthType depthType,
            IOutputArray map1,
            IOutputArray map2 = null)
        {
            int channels = map2 == null ? 2 : 1;

            using (InputArray iaCameraMatrix = cameraMatrix.GetInputArray())
                using (InputArray iaDistCoeffs = distCoeffs.GetInputArray())
                    using (InputArray iaR = R == null ? InputArray.GetEmpty() : R.GetInputArray())
                        using (InputArray iaNewCameraMatrix = newCameraMatrix.GetInputArray())
                            using (OutputArray oaMap1 = map1.GetOutputArray())
                                using (OutputArray oaMap2 = map2 == null ? OutputArray.GetEmpty() : map2.GetOutputArray())
                                    cveInitUndistortRectifyMap(
                                        iaCameraMatrix,
                                        iaDistCoeffs,
                                        iaR,
                                        iaNewCameraMatrix,
                                        ref size,
                                        CvInvoke.MakeType(depthType, channels),
                                        oaMap1, oaMap2);
        }
Exemplo n.º 2
0
 /// <summary>
 /// By retaining only the gradients at edge locations, before integrating with the Poisson solver, one washes out the texture of the selected region, giving its contents a flat aspect. Here Canny Edge Detector is used.
 /// </summary>
 /// <param name="src">Input 8-bit 3-channel image.</param>
 /// <param name="mask">Input 8-bit 1 or 3-channel image.</param>
 /// <param name="dst">Output image with the same size and type as src.</param>
 /// <param name="lowThreshold">Range from 0 to 100.</param>
 /// <param name="highThreshold">Value &gt; 100</param>
 /// <param name="kernelSize">The size of the Sobel kernel to be used.</param>
 public static void TextureFlattening(IInputArray src, IInputArray mask, IOutputArray dst, float lowThreshold = 30, float highThreshold = 45, int kernelSize = 3)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                 cveTextureFlattening(iaSrc, iaMask, oaDst, lowThreshold, highThreshold, kernelSize);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Applying an appropriate non-linear transformation to the gradient field inside the selection and then integrating back with a Poisson solver, modifies locally the apparent illumination of an image.
 /// </summary>
 /// <param name="src">Input 8-bit 3-channel image.</param>
 /// <param name="mask">Input 8-bit 1 or 3-channel image.</param>
 /// <param name="dst">Output image with the same size and type as src.</param>
 /// <param name="alpha">Value ranges between 0-2.</param>
 /// <param name="beta">Value ranges between 0-2.</param>
 public static void IlluminationChange(IInputArray src, IInputArray mask, IOutputArray dst, float alpha = 0.2f, float beta = 0.4f)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                 cveIlluminationChange(iaSrc, iaMask, oaDst, alpha, beta);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Given an original color image, two differently colored versions of this image can be mixed seamlessly.
 /// </summary>
 /// <param name="src">Input 8-bit 3-channel image.</param>
 /// <param name="mask">Input 8-bit 1 or 3-channel image.</param>
 /// <param name="dst">Output image with the same size and type as src .</param>
 /// <param name="redMul">R-channel multiply factor. Multiplication factor is between .5 to 2.5.</param>
 /// <param name="greenMul">G-channel multiply factor. Multiplication factor is between .5 to 2.5.</param>
 /// <param name="blueMul">B-channel multiply factor. Multiplication factor is between .5 to 2.5.</param>
 public static void ColorChange(IInputArray src, IInputArray mask, IOutputArray dst, float redMul = 1.0f, float greenMul = 1.0f, float blueMul = 1.0f)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                 cveColorChange(iaSrc, iaMask, oaDst, redMul, greenMul, blueMul);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Copy this Input array to another.
 /// </summary>
 /// <param name="arr">The destination array.</param>
 /// <param name="mask">The optional mask.</param>
 public void CopyTo(IOutputArray arr, IInputArray mask = null)
 {
     using (OutputArray oaArr = arr.GetOutputArray())
         using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
         {
             CvInvoke.cveInputArrayCopyTo(_ptr, oaArr, iaMask);
         }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Write point cloud to file
 /// </summary>
 /// <param name="file">The point cloud file name</param>
 /// <param name="cloud">The point cloud</param>
 /// <param name="colors">The color</param>
 /// <param name="normals">The normals</param>
 public static void WriteCloud(String file, IInputArray cloud, IInputArray colors = null, IInputArray normals = null)
 {
     using (CvString cs = new CvString(file))
         using (InputArray iaCloud = cloud.GetInputArray())
             using (InputArray iaColors = colors == null ? InputArray.GetEmpty() : colors.GetInputArray())
                 using (InputArray iaNormals = normals == null ? InputArray.GetEmpty() : normals.GetInputArray())
                 {
                     cveWriteCloud(cs, iaCloud, iaColors, iaNormals);
                 }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Merges images.
 /// </summary>
 /// <param name="src">Vector of input images</param>
 /// <param name="dst">Result image</param>
 public void Process(IInputArray src, IOutputArray dst)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaTimes = InputArray.GetEmpty())
                 using (InputArray iaResponse = InputArray.GetEmpty())
                 {
                     CvInvoke.cveMergeExposuresProcess(_mergeExposuresPtr, iaSrc, oaDst, iaTimes, iaResponse);
                 }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Transforms an image to compensate for fisheye lens distortion. The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap (with bilinear interpolation).
 /// </summary>
 /// <param name="distorted">Image with fisheye lens distortion.</param>
 /// <param name="undistored">Output image with compensated fisheye lens distortion.</param>
 /// <param name="K">Camera matrix </param>
 /// <param name="D">Input vector of distortion coefficients (k1,k2,k3,k4).</param>
 /// <param name="Knew">Camera matrix of the distorted image. By default, it is the identity matrix but you may additionally scale and shift the result by using a different matrix.</param>
 /// <param name="newSize">The function transforms an image to compensate radial and tangential lens distortion.</param>
 public static void UndistortImage(IInputArray distorted, IOutputArray undistored, IInputArray K, IInputArray D,
                                   IInputArray Knew = null, Size newSize = new Size())
 {
     using (InputArray iaDistorted = distorted.GetInputArray())
         using (OutputArray oaUndistorted = undistored.GetOutputArray())
             using (InputArray iaK = K.GetInputArray())
                 using (InputArray iaD = D.GetInputArray())
                     using (InputArray iaKnew = Knew == null ? InputArray.GetEmpty() : Knew.GetInputArray())
                     {
                         CvInvoke.cveFisheyeUndistortImage(iaDistorted, oaUndistorted, iaK, iaD, iaKnew, ref newSize);
                     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Transforms an image to compensate for fisheye lens distortion.
 /// </summary>
 /// <param name="distorted">Array of object points, 1xN/Nx1 2-channel (or vector&lt;Point2f&gt; ), where N is the number of points in the view.</param>
 /// <param name="undistorted">Output array of image points, 1xN/Nx1 2-channel, or vector&lt;Point2f&gt;.</param>
 /// <param name="K">Camera matrix</param>
 /// <param name="D">Input vector of distortion coefficients (k1,k2,k3,k4).</param>
 /// <param name="R">Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 1-channel or 1x1 3-channel</param>
 /// <param name="P">New camera matrix (3x3) or new projection matrix (3x4)</param>
 public static void UndistortPoints(IInputArray distorted, IOutputArray undistorted, IInputArray K, IInputArray D,
                                    IInputArray R = null, IInputArray P = null)
 {
     using (InputArray iaDistorted = distorted.GetInputArray())
         using (OutputArray oaUndistorted = undistorted.GetOutputArray())
             using (InputArray iaK = K.GetInputArray())
                 using (InputArray iaD = D.GetInputArray())
                     using (InputArray iaR = R == null ? InputArray.GetEmpty() : R.GetInputArray())
                         using (InputArray iaP = P == null ? InputArray.GetEmpty() : P.GetInputArray())
                         {
                             CvInvoke.cveFisheyeUndistortPoints(iaDistorted, oaUndistorted, iaK, iaD, iaR, iaP);
                         }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Finds the global minimum and maximum in an array
        /// </summary>
        /// <param name="src">Input single-channel array.</param>
        /// <param name="minVal">The returned minimum value</param>
        /// <param name="maxVal">The returned maximum value</param>
        /// <param name="minIdx">The returned minimum location</param>
        /// <param name="maxIdx">The returned maximum location</param>
        /// <param name="mask">The extremums are searched across the whole array if mask is IntPtr.Zert. Otherwise, search is performed in the specified array region.</param>
        public static void MinMaxIdx(IInputArray src, out double minVal, out double maxVal, int[] minIdx, int[] maxIdx, IInputArray mask = null)
        {
            GCHandle minHandle = GCHandle.Alloc(minIdx, GCHandleType.Pinned);
            GCHandle maxHandle = GCHandle.Alloc(maxIdx, GCHandleType.Pinned);

            minVal = 0;
            maxVal = 0;
            using (InputArray iaSrc = src.GetInputArray())
                using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                    cveMinMaxIdx(iaSrc, ref minVal, ref maxVal, minHandle.AddrOfPinnedObject(), maxHandle.AddrOfPinnedObject(), iaMask);
            minHandle.Free();
            maxHandle.Free();
        }
Exemplo n.º 11
0
 /// <summary>
 /// Finds the geometric transform (warp) between two images in terms of the ECC criterion
 /// </summary>
 /// <param name="templateImage">single-channel template image; CV_8U or CV_32F array.</param>
 /// <param name="inputImage">single-channel input image which should be warped with the final warpMatrix in order to provide an image similar to templateImage, same type as temlateImage.</param>
 /// <param name="warpMatrix">floating-point 2×3 or 3×3 mapping matrix (warp).</param>
 /// <param name="motionType">Specifying the type of motion. Use Affine for default</param>
 /// <param name="criteria">specifying the termination criteria of the ECC algorithm; criteria.epsilon defines the threshold of the increment in the correlation coefficient between two iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). Default values can use 50 iteration and 0.001 eps.</param>
 /// <param name="inputMask">An optional mask to indicate valid values of inputImage.</param>
 /// <returns>The final enhanced correlation coefficient, that is the correlation coefficient between the template image and the final warped input image.</returns>
 public static double FindTransformECC(
     IInputArray templateImage, IInputArray inputImage,
     IInputOutputArray warpMatrix, CvEnum.MotionType motionType,
     MCvTermCriteria criteria,
     IInputArray inputMask = null)
 {
     using (InputArray iaTemplateImage = templateImage.GetInputArray())
         using (InputArray iaInputImage = inputImage.GetInputArray())
             using (InputOutputArray ioaWarpMatrix = warpMatrix.GetInputOutputArray())
                 using (InputArray iaInputMask = inputMask == null ? InputArray.GetEmpty() : inputMask.GetInputArray())
                 {
                     return(cveFindTransformECC(iaTemplateImage, iaInputImage, ioaWarpMatrix, motionType, ref criteria, iaInputMask));
                 }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Specify custom features of input image.
 /// </summary>
 /// <param name="nonEdge">Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are {0, 1}.</param>
 /// <param name="gradientDirection">Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: x^2 + y^2 == 1</param>
 /// <param name="gradientMagnitude">Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range [0, 1].</param>
 /// <param name="image">Optional parameter. Must be specified if subset of features is specified (non-specified features are calculated internally)</param>
 public void ApplyImageFeatures(
     IInputArray nonEdge,
     IInputArray gradientDirection,
     IInputArray gradientMagnitude,
     IInputArray image = null)
 {
     using (InputArray iaNonEdge = nonEdge.GetInputArray())
         using (InputArray iaGradientDirection = gradientDirection.GetInputArray())
             using (InputArray iaGradientMagnitude = gradientMagnitude.GetInputArray())
                 using (InputArray iaImage = image == null ? InputArray.GetEmpty() : image.GetInputArray())
                 {
                     CvInvoke.cveIntelligentScissorsMBApplyImageFeatures(
                         _ptr,
                         iaNonEdge,
                         iaGradientDirection,
                         iaGradientMagnitude,
                         iaImage);
                 }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Similar to cvInitUndistortRectifyMap and is opposite to it at the same time.
 /// The functions are similar in that they both are used to correct lens distortion and to perform the optional perspective (rectification) transformation.
 /// They are opposite because the function cvInitUndistortRectifyMap does actually perform the reverse transformation in order to initialize the maps properly, while this function does the forward transformation.
 /// </summary>
 /// <param name="src">The observed point coordinates</param>
 /// <param name="dst">The ideal point coordinates, after undistortion and reverse perspective transformation. </param>
 /// <param name="cameraMatrix">The camera matrix A=[fx 0 cx; 0 fy cy; 0 0 1]</param>
 /// <param name="distCoeffs">The vector of distortion coefficients, 4x1, 1x4, 5x1 or 1x5. </param>
 /// <param name="R">The rectification transformation in object space (3x3 matrix). R1 or R2, computed by cvStereoRectify can be passed here. If the parameter is IntPtr.Zero, the identity matrix is used.</param>
 /// <param name="P">The new camera matrix (3x3) or the new projection matrix (3x4). P1 or P2, computed by cvStereoRectify can be passed here. If the parameter is IntPtr.Zero, the identity matrix is used.</param>
 public static void UndistortPoints(
     IInputArray src,
     IOutputArray dst,
     IInputArray cameraMatrix,
     IInputArray distCoeffs,
     IInputArray R = null,
     IInputArray P = null)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaCameraMatrix = cameraMatrix.GetInputArray())
                 using (InputArray iaDistCoeffs = distCoeffs.GetInputArray())
                     using (InputArray iaR = R == null ? InputArray.GetEmpty() : R.GetInputArray())
                         using (InputArray iaP = P == null ? InputArray.GetEmpty() : P.GetInputArray())
                             cveUndistortPoints(
                                 iaSrc,
                                 oaDst,
                                 iaCameraMatrix,
                                 iaDistCoeffs,
                                 iaR,
                                 iaP);
 }
Exemplo n.º 14
0
        /*
         * /// <summary>
         * /// Copies the values of the UMat to <paramref name="data"/>.
         * /// </summary>
         * /// <param name="data">The data storage, must match the size of the UMat</param>
         * public void CopyTo(Array data)
         * {
         * if (IsEmpty)
         * {
         *    throw new Exception("The UMat is empty");
         * }
         *
         * using (Mat.MatWithHandle m = Mat.PrepareArrayForCopy(Depth, Size, NumberOfChannels, data))
         *    CopyTo(m);
         * }*/

        /// <summary>
        /// Sets all or some of the array elements to the specified value.
        /// </summary>
        /// <param name="value">Assigned scalar converted to the actual array type.</param>
        /// <param name="mask">Operation mask of the same size as the umat.</param>
        public void SetTo(IInputArray value, IInputArray mask = null)
        {
            using (InputArray iaValue = value.GetInputArray())
                using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
                    UMatInvoke.cveUMatSetTo(Ptr, iaValue, iaMask);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Copy the data in this umat to the other mat
 /// </summary>
 /// <param name="mask">Operation mask. Its non-zero elements indicate which matrix elements need to be copied.</param>
 /// <param name="m">The input array to copy to</param>
 public void CopyTo(IOutputArray m, IInputArray mask = null)
 {
     using (OutputArray oaM = m.GetOutputArray())
         using (InputArray iaMask = mask == null ? InputArray.GetEmpty() : mask.GetInputArray())
             UMatInvoke.cveUMatCopyTo(this, oaM, iaMask);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Transforms the image to compensate radial and tangential lens distortion.
 /// </summary>
 /// <param name="src">The input (distorted) image</param>
 /// <param name="dst">The output (corrected) image</param>
 /// <param name="cameraMatrix">The camera matrix (A) [fx 0 cx; 0 fy cy; 0 0 1].</param>
 /// <param name="distortionCoeffs">The vector of distortion coefficients, 4x1 or 1x4 [k1, k2, p1, p2].</param>
 /// <param name="newCameraMatrix">Camera matrix of the distorted image. By default it is the same as cameraMatrix, but you may additionally scale and shift the result by using some different matrix</param>
 public static void Undistort(
     IInputArray src,
     IOutputArray dst,
     IInputArray cameraMatrix,
     IInputArray distortionCoeffs,
     IInputArray newCameraMatrix = null)
 {
     using (InputArray iaSrc = src.GetInputArray())
         using (OutputArray oaDst = dst.GetOutputArray())
             using (InputArray iaCameraMatrix = cameraMatrix.GetInputArray())
                 using (InputArray iaDistortionCoeffs = distortionCoeffs.GetInputArray())
                     using (InputArray iaNewCameraMatrix = newCameraMatrix == null ? InputArray.GetEmpty() : newCameraMatrix.GetInputArray())
                         cveUndistort(iaSrc, oaDst, iaCameraMatrix, iaDistortionCoeffs, iaNewCameraMatrix);
 }