5

我正在呈现如下所示的属性详细信息页面(可以在此处访问) 在此处输入图像描述

我有一个图像滑块和一个 360 度图像查看器。目前,用户手动上传两种类型的图像,即来自一个界面的普通图像和来自另一个界面的 360 度图像。我检查该物业是否有 360 度图像并使用全景查看器显示它们。

我使用以下控制器来上传 360 度图像,类似于上传普通图像。

public function upload_360_images()
{
    if($this->session->userdata['id'] && $this->session->userdata['type']=='user')
    {
        if($_FILES)
        {
            if(isset($_FILES['files'])){
                $data['errors']= array();
                $extensions = array("jpeg","jpg","png");

                foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){

                    $file_name = $key.$_FILES['files']['name'][$key];
                    $file_size =$_FILES['files']['size'][$key];
                    $file_tmp =$_FILES['files']['tmp_name'][$key];
                    $file_type=$_FILES['files']['type'][$key];
                    /*$file_ext=explode('.',$_FILES['image']['name'][$key]) ;
                    $file_ext=end($file_ext);*/
                    $i=1;
                    if($file_size > 7097152){
                        $data['errors'][$i]='File '.$i.' size must be less than 7 MB';
                        $i++;
                    }

                    $desired_dir="uploads";
                    if(empty($data['errors'])==true){
                        if(is_dir($desired_dir)==false){
                            mkdir("$desired_dir", 0700);        // Create directory if it does not exist
                        }
                        if(is_dir("$desired_dir/".$file_name)==false){
                            move_uploaded_file($file_tmp,"uploads/".$file_name);
                            $this->post_model->add360Image('property_360_images',$file_name,$this->uri->segment(3));
                        }else{                                  //rename the file if another one exist
                            $new_dir="uploads/".$file_name.time();
                            rename($file_tmp,$new_dir) ;
                        }

                    }else{
                        $data['contact']=$this->admin_model->getContactDetails();
                        $data['images']=$this->post_model->getProperty360Images($this->uri->segment(3));
                        $data['title']='My Profile Image';
                        $this->load->view('site/static/head',$data);
                        $this->load->view('site/static/header');
                        $this->load->view('site/content/upload_360_images');
                        $this->load->view('site/static/footer');
                        $this->load->view('site/static/footer_links');
                    }
                }
                if(empty($data['errors']))
                {
                    redirect(base_url().'dashboard');
                }
                else
                {
                    $data['contact']=$this->admin_model->getContactDetails();
                    $data['images']=$this->post_model->getProperty360Images($this->uri->segment(3));
                    $data['title']='My Profile Image';
                    $this->load->view('site/static/head',$data);
                    $this->load->view('site/static/header');
                    $this->load->view('site/content/upload_360_images');
                    $this->load->view('site/static/footer');
                    $this->load->view('site/static/footer_links');
                }
            }

        }
        else
        {
            $data['contact']=$this->admin_model->getContactDetails();
            $data['images']=$this->post_model->getProperty360Images($this->uri->segment(3));
            $data['title']='My Profile Image';
            $this->load->view('site/static/head',$data);
            $this->load->view('site/static/header');
            $this->load->view('site/content/upload_360_images');
            $this->load->view('site/static/footer');
            $this->load->view('site/static/footer_links');
        }

    }
    else
    {
        redirect(base_url().'user/login');
    }

}

请忽略长代码,此代码来自生产,因此我必须进行大量检查和条件。

问题 现在我的雇主希望我使用单一界面上传普通图像和 360 度图像,并使用某种检测算法检测图像的性质,然后在我用于静态/普通图像的同一图像滑块中显示图像。

研究

我在 Stackoverflow 上阅读了这个线程,它对使用EXIF工具读取文件的元数据有点意义,但这使得这个过程非常手动。

问题

我想在我的 php 图像上传代码中使用它来自动读取图像,或者在一个函数中编写检测算法,该函数将图像名称作为参数并将图像类型返回为普通或 360。基于该返回,我可以轻松地呈现视图。所以我的问题是如何在 php 中进行检测?

4

2 回答 2

3

根据Facebook 360 集团

尚无将照片标记为包含 360 度内容的标准。

它建议您寻找 EXIF 标签

Projection Type : equirectangular

你也可以找

Use Panorama Viewer : True

这两个标签出现在我用 LG 360 拍摄的照片上。

于 2017-08-07T20:19:32.203 回答
2

我在 Unity3D 平台上遇到了类似的问题,但考虑到 Equirectangular 图像通常具有 2:1 的比例,我想到了这一点。

可能宽度为 2000 像素,高度为 1000 像素(我已经看到软件生成的高度略高)。

这是伪代码,请记住,此代码从左下角开始考虑 posX 和 posY:

//this is how much the image should be close the 2:1 proportion, or 0.5-proportionThreshold.
proportionThreshold = 0.01;

//images smaller than this should not have resolution enough to be a panorama.
//it is important here to 
minimumWidth = 2000;
minimumHeight = 1080;

//in case of the image is not a panorama, this variable determines the maximum size it could be projected
maxFill = 0.65;

//what is the amount of the view the pamorama should view:
scaleX = 1;
scaleY = 1;

//where the panorama should be positioned in the view:
posX = 0;
posY = 0;

currentWidth = source.width;
currentHeight = source.height;

if(isFullPanorama()){
    Log("Full Panorama");
    //the variables are already set for that
}else if(isPartialPanorama()){
    Log("Partial Panorama");
    scale = currentHeight/currentWidth * 2f;
    scaleX = 1;
    scaleY = scale;
    posX = 0;
    posY = 0.5-scale/2;
}else{
    Debug.Log("Not Panorama");
    proportion = currentHeight/currentWidth;
    w = currentWidth > minimumWidth*maxFill ? minimumWidth*maxFill : currentWidth;
    scaleX = w / minimumWidth / 2;
    scaleY = scaleX * proportion * 2;
    if(scaleY>1) {
        h = currentHeight > minimumHeight*maxFill ? minimumHeight*maxFill : currentHeight;
        scaleY = h / minimumHeight / 2;
        scaleX = scaleY * proportion / 2;
    }
    posX = 0.5-scaleX/2;
    posY = 0.5-scaleY/2;
}

bool isFullPanorama(){
    proportion = currentHeight/currentWidth;
    return proportion>=0.5-proportionThreshold &&
    proportion<=0.5+proportionThreshold &&
    source.height >= minimumHeight;
}

bool isPartialPanorama(){
    return currentHeight/currentWidth<=0.5 &&
    source.width >= minimumWidth;
}
于 2017-09-14T15:11:13.740 回答