Exemple #1
0
        /// <summary>
        /// Saves an image for every point in the Route using a Firefox window
        /// </summary>
        /// <param name="folder">The folder to save the images to</param>
        /// <param name="res">The output resolution of each image</param>
        /// <param name="maxWindows">The maximum amount of windows to open at once. Higher uses more memory but will complete faster</param>
        /// <param name="pitch">The pitch in angles for each image to face</param>
        /// <param name="format">The format of the output images</param>
        /// <returns>The folder where all the images were saved</returns>
        public ImageFolder DownloadAllScreenshots(ImageFolder folder, Resolution res, int maxWindows = 1, double pitch = 0, ImageFileFormat format = ImageFileFormat.Jpeg)
        {
            if (!File.Exists(Setup.GeckodriverPath))
            {
                Setup.DownloadGeckodriver();
            }

            string geckoExe = Path.GetFileName(Setup.GeckodriverPath);
            string geckoDir = Path.GetDirectoryName(Setup.GeckodriverPath);

            FirefoxDriver[] drivers    = new FirefoxDriver[maxWindows];
            double          scaling    = Display.ScalingFactor();
            Size            windowSize = new Size(
                (int)Math.Round(res.Width / scaling) + 12,
                (int)Math.Round(res.Height / scaling) + 80
                );

            Route rt = RemoveThirdPartyPanoramas();

            Parallel.For(0, maxWindows, a =>
            {
                FirefoxOptions options       = new FirefoxOptions();
                options.LogLevel             = FirefoxDriverLogLevel.Fatal;
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(geckoDir, geckoExe);
                drivers[a] = new FirefoxDriver(service, options);
                drivers[a].Manage().Window.Size = windowSize;

                for (int b = a; b < rt.Length; b += maxWindows)
                {
                    drivers[a].Navigate().GoToUrl(rt.Points[b].StreetviewURL(pitch));

                    Wait(drivers[a]);

                    RemoveElementsByClassName(drivers[a], ElementsToRemove);

                    drivers[a].GetScreenshot().SaveAsFile(Path.Combine(folder.Path, "image" + b + "." + format.ToString().ToLower()), (ScreenshotImageFormat)format);
                }

                drivers[a].Quit();
            });

            return(folder);
        }
Exemple #2
0
        /// <summary>
        /// Downloads and saves a 360 equirectangular image for every point
        /// </summary>
        /// <param name="folder">The ImageFolder where the images should be saved to</param>
        /// <param name="format">The image format to save the images as</param>
        /// <param name="res">The resolution to save the images as with an aspect ratio of 2:1</param>
        /// <param name="searchRadius">The radius in meters to search for each point</param>
        /// <param name="threads">The amount of threads to download images in parallel. Each instance uses about 1GB of RAM.</param>
        /// <returns>The ImageFolder containing all the saved images</returns>
        public ImageFolder DownloadAllPanoramas(ImageFolder folder, ImageFileFormat format, Resolution res, int instances = 1, uint searchRadius = Point.DefaultSearchRadius)
        {
            if (instances < 1)
            {
                throw new ArgumentOutOfRangeException("threads", "Must be 1 or greater.");
            }

            PanoID[]    ids  = PanoIDs(true, searchRadius);
            ImageFormat frmt = GetFormat(format);

            Parallel.For(0, instances, thread =>
            {
                for (int i = thread; i < ids.Length; i += instances)
                {
                    using (Bitmap pano = ids[i].DownloadPanorama(res))
                        pano.Save(Path.Combine(folder.Path, "image" + i + "." + format.ToString().ToLower()), frmt);
                }
            });

            return(folder);
        }
Exemple #3
0
        /// <summary>
        /// Downloads an image for every point in the Route using the Static Streetview API
        /// </summary>
        /// <param name="folder">The folder to save the images to</param>
        /// <param name="res">The desired output resolution of each image</param>
        /// <param name="fov">The field of view of each image</param>
        /// <param name="pitch">The pitch of each image</param>
        /// <param name="parallel">Whether to run the process in parallel</param>
        /// <returns>The folder where all the images were saved</returns>
        public ImageFolder DownloadAllImages(ImageFolder folder, Resolution res, int fov, double pitch, bool parallel = true)
        {
            if (Setup.DontBillMe)
            {
                throw new DontBillMeException("You attempted to use a function that will cause you to be billed by Google. Change Setup.DontBillMe to false to stop this exception.");
            }

            if (parallel)
            {
                Parallel.For(0, Length, i => {
                    using (WebClient client = new WebClient())
                        client.DownloadFile(Points[i].ImageURL(pitch, res, fov), Path.Combine(folder.Path, "image" + i + ".png"));
                });
            }
            else
            {
                for (int i = 0; i < Length; i++)
                {
                    using (WebClient client = new WebClient())
                        client.DownloadFile(Points[i].ImageURL(pitch, res, fov), Path.Combine(folder.Path, "image" + i + ".png"));
                }
            }
            return(folder);
        }