Ejemplo n.º 1
0
        /// <summary>
        /// The load providers.
        /// </summary>
        /// <exception cref="ProviderException">
        /// </exception>
        private static void LoadProviders()
        {
            if (_provider == null)
            {
                lock (Lock)
                {
                    var section = AppConfig.Instance.Photos;

                    _providers = new PhotoProviderCollection();
                    ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(PhotoProvider));
                    _provider = _providers[section.DefaultProvider];

                    _photoResize = new Dictionary <string, PhotoResize>();

                    foreach (PhotoResizeElement photoResize in section.PhotoResizes)
                    {
                        _photoResize.Add(photoResize.Name, new PhotoResize(photoResize));
                    }

                    if (_provider == null)
                    {
                        throw new ProviderException("Unable to load default FileSystemProvider");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadImages(string dir, Size csize, List <string> filenames = null, List <string> badfiles = null)
        {
            images.Clear();
            PhotoProvider prov = new PhotoProvider(dir);

            List <Task>   allTasks  = new List <Task>();
            SemaphoreSlim throttler = new SemaphoreSlim(8); //max 8 threads

            Action <Object> findCornerAction = o => {
                String imageFile = (String)o;
                var    im        = new CalibImage(imageFile);
                int    scale     = 1;
                while (scale <= 4)
                {
                    try {
                        Size imSize;
                        var  pic        = PhotoProvider.getSingleImage(im.Path, out imSize, scale);
                        var  chessBoard = FindChessboardCorners(pic, csize);
                        Console.WriteLine(string.Format("found {0} at scale 1/{1}", im.Filename, scale));
                        im.ImagePoints = chessBoard.Select(f => new PointF(f.X * scale, f.Y * scale)).ToArray();
                        im.imageSize   = imSize;
                        images.Add(im);
                        throttler.Release();
                        return;
                    }
                    catch {
                        if (badfiles != null)
                        {
                            images.Add(null);
                            badfiles.Add(imageFile);
                            break;
                        }
                        Console.WriteLine(string.Format("no chessboard found: {0} at scale 1/{1}", im.Filename, scale));
                        scale *= 2;
                        continue;
                    }
                }

                throttler.Release();
            };

            var files = filenames ?? prov.getImageFiles().ToList();

            foreach (var imageFile in files)
            {
                throttler.Wait();
                Log.WriteLine(string.Format("searching pattern in {0}", imageFile));
                Task t = new Task(findCornerAction, imageFile);
                t.Start();
                allTasks.Add(t);
            }
            Task.WhenAll(allTasks).Wait();
        }
Ejemplo n.º 3
0
        public void CreateProductServiceAndPhotoProviderInSameDatabase()
        {
            var builder = new DbContextOptionsBuilder();

            builder.UseNpgsql("Host=192.168.1.103; Database=ECommerceTest; Username=postgres; Password=password");

            PhotoProviderContext photoProviderContext = new PhotoProviderContext(builder.Options);
            PhotoProvider        photoProvider        = new PhotoProvider(photoProviderContext, "images/");

            Task.Run(async() =>
            {
                await photoProvider.Initialise();
            }).GetAwaiter().GetResult();
            ProductsContext productsContext =
                new ProductsContext(builder.Options);

            var productService = new ProductService(productsContext);

            Task.Run(async() => { await productService.Initialise(); }).GetAwaiter().GetResult();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The load providers.
        /// </summary>
        /// <exception cref="ProviderException">
        /// </exception>
        private static void LoadProviders()
        {
            if (_provider == null)
            {
                lock (Lock)
                {
                    var section = AppConfig.Instance.Photos;

                    _providers = new PhotoProviderCollection();
                    ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(PhotoProvider));
                    _provider = _providers[section.DefaultProvider];

                    _photoResize = new Dictionary<string, PhotoResize>();

                    foreach (PhotoResizeElement photoResize in section.PhotoResizes)
                    {
                        _photoResize.Add(photoResize.Name, new PhotoResize(photoResize));
                    }

                    if (_provider == null)
                    {
                        throw new ProviderException("Unable to load default FileSystemProvider");
                    }
                }
            }
        }