Пример #1
0
 public static Image<Gray, byte> ToScaledSmoothedCanny(this Image<Bgr,byte> image)
 {
     Image<Gray, Byte> grayFrame = image.Convert<Gray, Byte>();
     Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown();
     Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp();
     Image<Gray, Byte> cannyFrame = smoothedGrayFrame.Canny(new Gray(100), new Gray(60));
     return cannyFrame;
 }
        /// <summary>
        /// Extends Convert so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// decoder.Convert(bytes, chars, charIndex, charCount, flush, bytesUsed, charsUsed, completed);
        /// </example>
        /// </summary>
        public static void Convert(this Decoder decoder, Byte[] bytes, Char[] chars, Int32 charIndex, Int32 charCount, Boolean flush, out Int32 bytesUsed, out Int32 charsUsed, out Boolean completed)
        {
            if(decoder == null) throw new ArgumentNullException("decoder");

            if(bytes == null) throw new ArgumentNullException("bytes");

            decoder.Convert(bytes, 0, bytes.Length, chars, charIndex, charCount, flush, out bytesUsed, out charsUsed, out completed);
        }
        /// <summary>
        /// Extends Convert so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// encoder.Convert(chars, bytes, byteIndex, byteCount, flush, charsUsed, bytesUsed, completed);
        /// </example>
        /// </summary>
        public static void Convert(this Encoder encoder, Char[] chars, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, out Int32 charsUsed, out Int32 bytesUsed, out Boolean completed)
        {
            if(encoder == null) throw new ArgumentNullException("encoder");

            if(chars == null) throw new ArgumentNullException("chars");

            encoder.Convert(chars, 0, chars.Length, bytes, byteIndex, byteCount, flush, out charsUsed, out bytesUsed, out completed);
        }
        /// <summary>
        /// Converts a value and handles typical bugs of Toolkit and official IValueConverters.
        /// </summary>
        /// <param name="vc"></param>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public static object ConvertSafe(this IValueConverter vc, object value, Type targetType, object parameter, CultureInfo culture) 
        {
            // WP7 Toolkit's time converters have a bug where dates of different time zones are not properly
            // converted, and also crash the app. This fixes it.
            // See https://github.com/WFoundation/WF.Player.WinPhone/issues/23
            
            if (value is DateTime)
            {
                DateTime dtValue = (DateTime)value;

                // Lets the converter try converting the raw value.
                try
                {
                    vc.Convert(dtValue, targetType, parameter, culture);
                }
                catch (NotSupportedException)
                {
                    // Fix the value date time by converting it to local time.
                    DateTime fixedValue = dtValue.ToLocalTime();

                    // The conversion should be fine now.
                    try
                    {
                        return vc.Convert(fixedValue, targetType, parameter, culture);
                    }
                    catch (NotSupportedException)
                    {
                        // Despite all precautions, if the conversion still doesn't work, this probably means that 
                        // the date is still considered to be "in the future". Let's assume it's not too far from the present...
                        try
                        {
                            return vc.Convert(DateTime.Now, targetType, parameter, culture);
                        }
                        catch (Exception)
                        {
                            // Great despair, and nothing much to be done...
                            return null;
                        }
                    }    
                }   
            }

            // Let the wrapper converter handle other values.
            return vc.Convert(value, targetType, parameter, culture);
        }
 /// <summary>
 /// Converts persistence objects to immutable statistics objects
 /// </summary>
 /// <param name="dataArray">The persistence data objects.</param>
 /// <returns>array of statistics objects</returns>
 public static ExecutionStatistics[] FromPersistence(this ExecutionData[] dataArray)
 {
     return dataArray.Convert(
         d => new ExecutionStatistics(
             d.Name,
             d.OpenCount,
             d.CloseCount,
             d.Counters,
             d.RunningTime));
 }
Пример #6
0
 public static Image<Bgr, Byte> ColorLevel(this Image<Gray, Byte> src, ConnectLevel conn)
 {
     var dst = src.Convert<Bgr, Byte>();
     var color = new Bgr(0, 0, 255);
     foreach (var domain in conn.Domains) {
         foreach (var p in domain.Points) {
             dst[p.Y, p.X] = color;
         }
     }
     return dst;
 }
 /// <summary>
 /// Converts immutable statistics objects to the persistence objects
 /// </summary>
 /// <param name="statisticsArray">The immutable statistics objects.</param>
 /// <returns>array of persistence objects</returns>
 public static ExecutionData[] ToPersistence(this ExecutionStatistics[] statisticsArray)
 {
     return statisticsArray.Convert(es => new ExecutionData
         {
             CloseCount = es.CloseCount,
             Counters = es.Counters,
             Name = es.Name,
             OpenCount = es.OpenCount,
             RunningTime = es.RunningTime
         });
 }
Пример #8
0
        public static ListViewGroupedModel<ConsignDetail> ToListViewGroupData(this ConsignDto dto)
        {
            var lst = dto.Convert();
            var a = lst.ToLookup(l => l.Group)
                .Select(l => new ListViewGroup<ConsignDetail>(l) {
                    Title = l.Key,
                    ShortTitle = l.Key,

                });

            return new ListViewGroupedModel<ConsignDetail>() {
                Groups = new ObservableCollection<ListViewGroup<ConsignDetail>>(a)
            };
        }
		public static IEnsuring Enumerable(this IBooleanCondition<Type> condition)
		{
			var concreteCondition = condition.Convert<ConditionTree<Type>>();

			var isEnumerable = concreteCondition.Value.IsEnumerable();

			if (!concreteCondition.IsNegated)
			{
				if (!isEnumerable)
				{
					if (concreteCondition.IsArgument)
					{
						var defaultException = new ArgumentException("The type is not enumerable.", concreteCondition.ArgumentName);

						ConditionalException
							.Throw(defaultException, concreteCondition.Exception);
					}

					ConditionalException
						.Throw(new TypeIsNotEnumerableException(), concreteCondition.Exception);
				}
			}
			else
			{
				if (isEnumerable)
				{
					if (concreteCondition.IsArgument)
					{
						var defaultException = new ArgumentException("The type is enumerable.", concreteCondition.ArgumentName);

						ConditionalException
							.Throw(defaultException, concreteCondition.Exception);
					}

					ConditionalException
						.Throw(new TypeIsEnumerableException(), concreteCondition.Exception);
				}
			}

			return EnsuringWrapper.Create();
		}
Пример #10
0
		public static global::Cairo.Color ToCairo(this IColor me)
		{
			Color.Bgra bgra = me.Convert<Color.Bgra>();
			return new global::Cairo.Color(bgra.Red / 255.0, bgra.Green / 255.0, bgra.Blue / 255.0, bgra.Alpha / 255.0);
		}
Пример #11
0
 /// <summary>
 /// Convert the specified time duration in the given unit to the
 /// nanoseconds units.
 /// </summary>
 public static double ToNanos(this TimeUnit @from, long duration) {
   return @from.Convert(duration, TimeUnit.Nanoseconds);
 }
 public static object Convert(this IStepArgumentTypeConverter converter, object value, Type typeToConvertTo, CultureInfo cultureInfo)
 {
     return converter.Convert(value, new RuntimeBindingType(typeToConvertTo), cultureInfo);
 }
Пример #13
0
 public static Pen AddColor(this Pen pen, Color addColor, float percent)
 {
     return pen.Convert(pen.Color.AddColor(addColor, percent));
 }
Пример #14
0
 public static Pen ToBlueGrayScale(this Pen pen)
 {
     return pen.Convert(pen.Color.ToBlueGrayScale());
 }
Пример #15
0
 public static object Call(this IValueConverter converter, object value)
 {
     return converter.Convert(value, null, null, null);
 }
 /// <summary>
 /// Encodes the individual route values to be lower-case and containing hypens
 /// instead of spaces.
 /// It does not alter the controller and action route values
 /// </summary>
 /// <param name="route">Route value dictionary containing the route data</param>
 public static RouteValueDictionary Encode(this RouteValueDictionary route)
 {
     return route.Convert(@" ", @"-", true);
 }
 /// <summary>
 /// Decodes the individual route values to replace the hypens with spaces.
 /// It does not alter the case of the value and does not alter the controller 
 /// and action route values
 /// </summary>
 /// <param name="route">Route value dictionary containing the route data</param>
 public static RouteValueDictionary Decode(this RouteValueDictionary route)
 {
     return route.Convert(@"-", @" ", false);
 }
Пример #18
0
 public static string[] GetNames(this IList<INamable> namables)
 {
     return namables.Convert(namableToName);
 }
Пример #19
0
 /// <summary>
 /// Convert the specified time duration in the given unit to the
 /// seconds units.
 /// </summary>
 /// <returns></returns>
 public static double ToMilliseconds(this TimeUnit @from, double duration) {
   return @from.Convert(duration, TimeUnit.Milliseconds);
 }
 /// <summary>
 /// Calculates magnitude of the specified complex image.
 /// </summary>
 /// <param name="image">Image.</param>
 /// <param name="area">The specified working area.</param>
 /// <returns>Magnitude image.</returns>
 public static Gray<float>[,] Magnitude(this ComplexF[,] image, Rectangle area)
 {
     return image.Convert<ComplexF, Gray<float>>(convertComplexToMagnitude, area);
 }
Пример #21
0
 public static Pen Darker(this Pen pen, int div)
 {
     return pen.Convert(pen.Color.Darker(div));
 }
Пример #22
0
 /// <summary>
 /// Convert the specified time duration in the given unit to the
 /// nanoseconds units.
 /// </summary>
 /// <returns></returns>
 public static long ToTicks(this TimeUnit @from, double duration) {
   return (long) @from.Convert(duration, TimeUnit.Ticks);
 }
Пример #23
0
 public static Pen Brighter(this Pen pen, int div)
 {
     return pen.Convert(pen.Color.Brighter(div));
 }
Пример #24
0
 public static float ToPixels(this Quantity Q)
 {
     return (float)Q.Convert(Game.SI.px).Amount;
 }
Пример #25
0
 public static Pen ToNegative(this Pen pen)
 {
     return pen.Convert(pen.Color.ToNegative());
 }
Пример #26
0
 public static Image<Gray, byte> ToGray(this Image<Bgr, byte> image)
 {
     return image.Convert<Gray, byte>();
 }
Пример #27
0
		/// <summary>
		/// Cast the value to another type.
		/// </summary>
		/// <param name="unit">Source unit.</param>
		/// <param name="destinationType">Destination value type.</param>
		/// <param name="security">Information about the instrument. Required when using <see cref="UnitTypes.Point"/> и <see cref="UnitTypes.Step"/>.</param>
		/// <returns>Converted value.</returns>
		public static Unit Convert(this Unit unit, UnitTypes destinationType, Security security)
		{
			return unit.Convert(destinationType, type => GetTypeValue(security, type));
		}
 public static object Convert(this IConverterStrategy strategy, string text)
 {
     return strategy.Convert(new ConversionRequest(text));
 }
Пример #29
0
 public static float ToMeters(this Quantity Q)
 {
     return (float)Q.Convert(Game.SI.m).Amount;
 }
 /// <summary>
 /// Converts the grayscale image to a complex image where the specified image is taken as a real part.
 /// </summary>
 /// <param name="image">Real part of a complex image.</param>
 /// <returns>Complex image.</returns>
 public static ComplexF[,] ToComplex(this Gray<float>[,] image)
 {
     return image.Convert<Gray<float>, ComplexF>(convertGrayToComplex);
 }