예제 #1
0
파일: GpuMat.cs 프로젝트: virzak/emgucv
        /// <summary>
        /// Returns the min / max location and values for the image
        /// </summary>
        /// <param name="maxLocations">The maximum locations for each channel </param>
        /// <param name="maxValues">The maximum values for each channel</param>
        /// <param name="minLocations">The minimum locations for each channel</param>
        /// <param name="minValues">The minimum values for each channel</param>
        public void MinMax(out double[] minValues, out double[] maxValues, out Point[] minLocations, out Point[] maxLocations)
        {
            minValues    = new double[NumberOfChannels];
            maxValues    = new double[NumberOfChannels];
            minLocations = new Point[NumberOfChannels];
            maxLocations = new Point[NumberOfChannels];

            double minVal = 0, maxVal = 0;
            Point  minLoc = new Point(), maxLoc = new Point();

            if (NumberOfChannels == 1)
            {
                CudaInvoke.MinMaxLoc(this, ref minVal, ref maxVal, ref minLoc, ref maxLoc, null);
                minValues[0]    = minVal; maxValues[0] = maxVal;
                minLocations[0] = minLoc; maxLocations[0] = maxLoc;
            }
            else
            {
                GpuMat[] channels = Split(null);
                try
                {
                    for (int i = 0; i < NumberOfChannels; i++)
                    {
                        CudaInvoke.MinMaxLoc(channels[i], ref minVal, ref maxVal, ref minLoc, ref maxLoc, null);
                        minValues[i]    = minVal; maxValues[i] = maxVal;
                        minLocations[i] = minLoc; maxLocations[i] = maxLoc;
                    }
                }
                finally
                {
                    foreach (GpuMat mat in channels)
                    {
                        mat.Dispose();
                    }
                }
            }
        }