Api 使用自定义全景和大等长文件的怪异投影

Api 使用自定义全景和大等长文件的怪异投影,api,google-street-view,panoramas,Api,Google Street View,Panoramas,我将尝试解释我的问题: 我正在用街景API创建一个自定义全景图,我用512px瓷砖切割我的全景图图像(我的全景图总是512px的倍数) 在大多数情况下,渲染效果良好: 但是,当我使用大型全景时,它的渲染方式如下: 当我放大时,这种效果消失了 在移动设备上,无论全景大小如何,它的渲染都是相同的(必须放大到3或4缩放值才能正确显示) 这是我的代码(size.w和size.h是全景尺寸): 这是getCustomePanoramaTileURL this.getCustomPanoramaTil

我将尝试解释我的问题:

我正在用街景API创建一个自定义全景图,我用512px瓷砖切割我的全景图图像(我的全景图总是512px的倍数)

在大多数情况下,渲染效果良好:

但是,当我使用大型全景时,它的渲染方式如下:

当我放大时,这种效果消失了

在移动设备上,无论全景大小如何,它的渲染都是相同的(必须放大到3或4缩放值才能正确显示)

这是我的代码(size.w和size.h是全景尺寸):

这是getCustomePanoramaTileURL

 this.getCustomPanoramaTileUrl = function(panoID, zoom, tileX, tileY) {
    // Return a pano image given the panoID.

    return "/the/directory/" + panoID + '/' + 0 + '_' + tileX + '_' + tileY + '.jpg';
}
“/the/directory/panoID”包含我的互动程序


任何潜在客户都将不胜感激:)

我想,我也遇到了同样的问题。我花了几个小时才解决它

所以,问题是,您只创建一个图像并将其拆分为平铺

谷歌需要多幅图像,分为多个图像块——每个缩放级别对应一幅图像

您需要为连续的1/2高1/2宽尺寸创建每个版本的全景,直到全景适合一个平铺

例如,如果您拥有6000*3000像素的全景图,并且使用512*512瓷砖大小,则需要创建:

  • 全景6000*3000(12*6瓷砖)
  • 全景3000*1500(6*3瓷砖)
  • 全景1500*750(3*2瓷砖)
  • 全景750*375(2*1瓷砖)
  • 全景375*187(1*1瓷砖)
这是我用来生成平铺的小PHP脚本:

// util function used below
function resize_image($old_src, $new_src, $new_width, $new_height=null)
{
    $src=imagecreatefromjpeg($old_src);
    list($width, $height)=getimagesize($old_src);
    $new_height = $new_height ? $new_height : round(($height/$width)*$new_width);
    $tmp=imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    if (file_exists($new_src))
        unlink($new_src);

    imagejpeg($tmp, $new_src, 85);
}

$pano="/path/to/your/panorama.jpg";
$tiles_dir="/directory/where/you/want/to/place/tiles";
$crop_width=$crop_height=500; // your tiles size

$zooms=array(8000, 4000, 2000, 1000, 500); // I have 8000*4000 image, so I set sizes manually
$zooms=array_reverse($zooms);

foreach ($zooms as $zoom_level=>$zoom_width)
{
    $name=str_replace('.jpg', '', basename($pano));

    $zoom_dir=$tiles_dir.'/'.$name.'/'.$zoom_level;
    if (!is_dir($zoom_dir))
        mkdir($zoom_dir, 0777, true);

    $temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
    resize_image($pano, $temp_image_src, $zoom_width); // my own function that resizes image

    $img = new Imagick($temp_image_src);
    $imgHeight=$img->getImageHeight();
    $imgWidth=$img->getImageWidth();

    $crop_width_num_times=ceil($imgWidth/$crop_width);
    $crop_height_num_times=ceil($imgHeight/$crop_height);
    $counter_x=0;
    for ($i=0; $i<$crop_width_num_times; $i++)
    {
        $counter_y=0;
        for ($j=0; $j<$crop_height_num_times; $j++)
        {
            $img = new Imagick($temp_image_src);
            $x=($i*$crop_width);
            $y=($j*$crop_height);
            $img->cropImage($crop_width, $crop_height, $x, $y);
            $data=$img->getImageBlob();

            for ($z=0; $z<=5; $z++)
            {
                $newFileName=$zoom_dir."/".$counter_x."_".$counter_y.".jpg";
                $result=file_put_contents($newFileName, $data);
            }

            $counter_y++;
        }

        $counter_x++;
    }
}
//下面使用的util函数
函数resize_image($old_src、$new_src、$new_width、$new_height=null)
{
$src=imagecreatefromjpeg($old_src);
列表($width,$height)=getimagesize($old_src);
$new_height=$new_height?$new_height:圆形(($height/$width)*$new_width);
$tmp=ImageCreateTureColor($new\u width,$new\u height);
imagecopyresampled($tmp、$src、0、0、0、$new\u width、$new\u height、$width、$height);
如果(文件存在($new\u src))
取消链接($new_src);
imagejpeg($tmp,$new_src,85);
}
$pano=“/path/to/your/panorama.jpg”;
$tiles_dir=“/directory/where/you/want/to/place/tiles”;
$CROPT\U WITH=$CROPT\U height=500;//你的瓷砖尺寸
$zooms=数组(8000、4000、2000、1000、500);//我有8000*4000图像,所以我手动设置大小
$zooms=array\u reverse($zooms);
foreach($zoom\u level=>$zoom\u width)
{
$name=str_replace('.jpg','',basename($pano));
$zoom\u dir=$tiles\u dir.'/'.$name.'/'.$zoom\u level;
如果(!is_dir($zoom_dir))
mkdir($zoom_dir,0777,true);
$temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
调整图像大小($pano,$temp_image_src,$zoom_width);//我自己的调整图像大小的函数
$img=新图像($temp\u image\u src);
$imgHeight=$img->getImageHeight();
$imgWidth=$img->getImageWidth();
$crop\u width\u num\u times=ceil($imgWidth/$crop\u width);
$crop\u height\u num\u times=ceil($imghight/$crop\u height);
$counter_x=0;
对于($i=0;$igetImageBlob();

对于($z=0;$z我想,我遇到了完全相同的问题。我花了几个小时来解决它

所以,问题是,您只创建一个图像并将其拆分为平铺

谷歌需要多幅图像,分为多个图像块——每个缩放级别对应一幅图像

您需要为连续的1/2高1/2宽尺寸创建每个版本的全景,直到全景适合一个平铺

例如,如果您拥有6000*3000像素的全景图,并且使用512*512瓷砖大小,则需要创建:

  • 全景6000*3000(12*6瓷砖)
  • 全景3000*1500(6*3瓷砖)
  • 全景1500*750(3*2瓷砖)
  • 全景750*375(2*1瓷砖)
  • 全景375*187(1*1瓷砖)
这是我用来生成平铺的小PHP脚本:

// util function used below
function resize_image($old_src, $new_src, $new_width, $new_height=null)
{
    $src=imagecreatefromjpeg($old_src);
    list($width, $height)=getimagesize($old_src);
    $new_height = $new_height ? $new_height : round(($height/$width)*$new_width);
    $tmp=imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($tmp, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    if (file_exists($new_src))
        unlink($new_src);

    imagejpeg($tmp, $new_src, 85);
}

$pano="/path/to/your/panorama.jpg";
$tiles_dir="/directory/where/you/want/to/place/tiles";
$crop_width=$crop_height=500; // your tiles size

$zooms=array(8000, 4000, 2000, 1000, 500); // I have 8000*4000 image, so I set sizes manually
$zooms=array_reverse($zooms);

foreach ($zooms as $zoom_level=>$zoom_width)
{
    $name=str_replace('.jpg', '', basename($pano));

    $zoom_dir=$tiles_dir.'/'.$name.'/'.$zoom_level;
    if (!is_dir($zoom_dir))
        mkdir($zoom_dir, 0777, true);

    $temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
    resize_image($pano, $temp_image_src, $zoom_width); // my own function that resizes image

    $img = new Imagick($temp_image_src);
    $imgHeight=$img->getImageHeight();
    $imgWidth=$img->getImageWidth();

    $crop_width_num_times=ceil($imgWidth/$crop_width);
    $crop_height_num_times=ceil($imgHeight/$crop_height);
    $counter_x=0;
    for ($i=0; $i<$crop_width_num_times; $i++)
    {
        $counter_y=0;
        for ($j=0; $j<$crop_height_num_times; $j++)
        {
            $img = new Imagick($temp_image_src);
            $x=($i*$crop_width);
            $y=($j*$crop_height);
            $img->cropImage($crop_width, $crop_height, $x, $y);
            $data=$img->getImageBlob();

            for ($z=0; $z<=5; $z++)
            {
                $newFileName=$zoom_dir."/".$counter_x."_".$counter_y.".jpg";
                $result=file_put_contents($newFileName, $data);
            }

            $counter_y++;
        }

        $counter_x++;
    }
}
//下面使用的util函数
函数resize_image($old_src、$new_src、$new_width、$new_height=null)
{
$src=imagecreatefromjpeg($old_src);
列表($width,$height)=getimagesize($old_src);
$new_height=$new_height?$new_height:圆形(($height/$width)*$new_width);
$tmp=ImageCreateTureColor($new\u width,$new\u height);
imagecopyresampled($tmp、$src、0、0、0、$new\u width、$new\u height、$width、$height);
如果(文件存在($new\u src))
取消链接($new_src);
imagejpeg($tmp,$new_src,85);
}
$pano=“/path/to/your/panorama.jpg”;
$tiles_dir=“/directory/where/you/want/to/place/tiles”;
$crop\u width=$crop\u height=500;//瓷砖大小
$zooms=array(8000,4000,2000,1000,500);//我有8000*4000个图像,所以我手动设置大小
$zooms=array\u reverse($zooms);
foreach($zoom\u level=>$zoom\u width)
{
$name=str_replace('.jpg','',basename($pano));
$zoom\u dir=$tiles\u dir.'/'.$name.'/'.$zoom\u level;
如果(!is_dir($zoom_dir))
mkdir($zoom_dir,0777,true);
$temp_image_src=sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid();
调整图像大小($pano,$temp_image_src,$zoom_width);//我自己的调整图像大小的函数
$img=新图像($temp\u image\u src);
$imgHeight=$img->getImageHeight();
$imgWidth=$img->getImageWidth();
$crop\u width\u num\u times=ceil($imgWidth/$crop\u width);
$crop\u height\u num\u times=ceil($imghight/$crop\u height);
$counter_x=0;
对于($i=0;$igetImageBlob();

对于($z=0;$zto complete,对于较小的全景,如果我减小浏览器大小,则会出现奇怪的投影。它看起来像一个“迷你行星”投影,但缺少像素…对于较小的全景,如果我减小浏览器大小,则会出现奇怪的投影。它看起来像一个“迷你行星”投影但缺少像素…谢谢你的消息。由于我的帖子我也找到了它,我正在使用Image Magick创建瓷砖并执行:-在原始文件中裁剪512px瓷砖-在原始文件中裁剪1024px瓷砖,然后将其收缩为512px-在原始文件中裁剪2048px瓷砖,然后将其收缩为512px-裁剪4096px瓷砖。。。。因此,处理需要花费大量的时间(8000*4000图像需要4分钟)