ConvertTo() private method

private ConvertTo ( IntPtr src, IntPtr dst, double scale, double shift, IntPtr stream ) : void
src System.IntPtr
dst System.IntPtr
scale double
shift double
stream System.IntPtr
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Convert this GpuMat to different depth
        /// </summary>
        /// <typeparam name="TOtherDepth">The depth type to convert to</typeparam>
        /// <param name="stream">Use a Stream to call the function asynchronously (non-blocking) or null to call the function synchronously (blocking).</param>
        /// <returns>GpuMat of different depth</returns>
        public GpuMat <TOtherDepth> Convert <TOtherDepth>(Stream stream)
            where TOtherDepth : new()
        {
            GpuMat <TOtherDepth> res = new GpuMat <TOtherDepth>(Size, NumberOfChannels);

            GpuInvoke.ConvertTo(Ptr, res.Ptr, 1.0, 0.0, stream);
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert the source image to the current image, if the size are different, the current image will be a resized version of the srcImage.
        /// </summary>
        /// <typeparam name="TSrcColor">The color type of the source image</typeparam>
        /// <typeparam name="TSrcDepth">The color depth of the source image</typeparam>
        /// <param name="srcImage">The sourceImage</param>
        public void ConvertFrom <TSrcColor, TSrcDepth>(GpuImage <TSrcColor, TSrcDepth> srcImage)
            where TSrcColor : struct, IColor
            where TSrcDepth : new()
        {
            if (!Size.Equals(srcImage.Size))
            { //if the size of the source image do not match the size of the current image
                using (GpuImage <TSrcColor, TSrcDepth> tmp = srcImage.Resize(Size, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, null))
                {
                    ConvertFrom(tmp);
                    return;
                }
            }

            if (typeof(TColor) == typeof(TSrcColor))
            {
                #region same color
                if (typeof(TDepth) == typeof(TSrcDepth)) //same depth
                {
                    GpuInvoke.Copy(srcImage.Ptr, Ptr, IntPtr.Zero);
                }
                else //different depth
                {
                    if (typeof(TDepth) == typeof(Byte) && typeof(TSrcDepth) != typeof(Byte))
                    {
                        double[] minVal, maxVal;
                        Point[]  minLoc, maxLoc;
                        srcImage.MinMax(out minVal, out maxVal, out minLoc, out maxLoc);
                        double min = minVal[0];
                        double max = maxVal[0];
                        for (int i = 1; i < minVal.Length; i++)
                        {
                            min = Math.Min(min, minVal[i]);
                            max = Math.Max(max, maxVal[i]);
                        }
                        double scale = 1.0, shift = 0.0;
                        if (max > 255.0 || min < 0)
                        {
                            scale = (max == min) ? 0.0 : 255.0 / (max - min);
                            shift = (scale == 0) ? min : -min * scale;
                        }

                        GpuInvoke.ConvertTo(srcImage.Ptr, Ptr, scale, shift);
                    }
                    else
                    {
                        GpuInvoke.ConvertTo(srcImage.Ptr, Ptr, 1.0, 0.0);
                    }
                }
                #endregion
            }
            else
            {
                #region different color
                if (typeof(TDepth) == typeof(TSrcDepth))
                { //same depth
                    ConvertColor(srcImage.Ptr, Ptr, typeof(TSrcColor), typeof(TColor), Size, null);
                }
                else
                {                                                                                     //different depth
                    using (GpuImage <TSrcColor, TDepth> tmp = srcImage.Convert <TSrcColor, TDepth>()) //convert depth
                        ConvertColor(tmp.Ptr, Ptr, typeof(TSrcColor), typeof(TColor), Size, null);
                }
                #endregion
            }
        }