Requesting Google Street View panorama tiles from an origin location

♀尐吖头ヾ 提交于 2020-01-02 14:33:24

问题


I am trying to request Google Street View images so that I can render the full panorama onto a sphere in 3D.

Unfortunately, this API only allows requesting up to 120° FoV. Ideally I need an equirectangular image that I can project onto this sphere.

I then checked what requests Google Maps made when requesting panorama images for insight, and found that it makes requests similar to this:

https://geo0.ggpht.com/cbk?cb_client=maps_sv.tactile&panoid=${panorama_id}&output=tile&x=${tile_x}&y=${tile_y}&zoom=${zoom_level}&nbt&fover=2 where each zoom level splits the image up into more tiles, giving higher resolution. (Explained visually here)

This was perfect for what I was doing -- however I discovered that it did not return a response from every panorama id I got through the Metadata API.

Looking into it more, I found that Google Maps sometimes makes requests to different endpoints with different parameters, some even returning images in completely different file formats.

I've now been left quite unsure as to how to approach this issue from here. I cannot embed the Street View Javascript API, because I need to render this in an already 3D world, and I cannot use the static panorama API as I cannot get a full panoramic image from that.

Any ideas appreciated, thanks. :)


回答1:


You can download every image and save it in a multidimensional image array. You can then draw each individual tile on to a blank bitmap. This article explains how to download all the tiles.

Here is my c# code that takes a panorama ID and returns a equirectangular 13312x6656 bitmap which can be saved in any image format:

public static Bitmap Panorama(string panoID)
    {
        ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 12;
        Image[,] images = new Image[26, 13];
        Parallel.For(0, 26, x =>
        {
            Parallel.For(0, 13, y =>
            {
                using (WebClient client = new WebClient())
                    images[x, y] = Image.FromStream(new MemoryStream(client.DownloadData(Get.TileURL(panoID, x, y)))); //converts downloaded byte array to image
            });
        });

        Bitmap result = new Bitmap(26 * 512, 13 * 512);
        for (int x = 0; x < 26; x++)
             for (int y = 0; y < 13; y++)
                 using (Graphics g = Graphics.FromImage(result))
                     g.DrawImage(images[x, y], x * 512, y * 512);
        return result;
    }

To get the url you can also use cbk0.google.com. Get.TileURL:

public static string TileURL(string panoID, int x, int y, int zoomLevel = 5)
    {
        return "http://cbk0.google.com/cbk?output=tile&panoid=" + panoID + "&zoom=" + zoomLevel + "&x=" + x + "&y=" + y;
    }

The Parallel.For loops are just to speed things up and can be substituted for normal for loops.

The only issue with this method is that it doesn't work with panos that start with CAoSLEFGMVFpcE. I'm currently trying to find a fix for that and will update this answer if I find a solution.

Note: by doing this you will be breaking Google's terms of service



来源:https://stackoverflow.com/questions/51800326/requesting-google-street-view-panorama-tiles-from-an-origin-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!