在 PHP 中自动检测 360 度自然图像
Auto Detect Image for 360 nature in PHP
我正在呈现如下所示的 属性 详细信息页面(可以访问 Here)
我有一个图像滑块和一个 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 度图像,并使用某种检测算法检测图像的性质,然后在我用于 static/plain 图像的同一图像滑块中显示图像。
研究
我阅读了 this thread on Whosebug which made a little sense about reading the meta data of the file using EXIF 工具,但这使得这个过程非常手动。
问题
我想自动读取图像,在我的 php 图像上传代码中使用它,或者在函数中编写检测算法,该函数获取图像名称作为参数,return 图像类型为普通或360. 基于此 return 我可以轻松渲染视图。所以我的问题是如何在 php?
中进行检测
There isn't yet a standard for tagging a photo as containing 360 content.
建议您寻找EXIF标签
Projection Type : equirectangular
您还可以寻找
Use Panorama Viewer : True
我的 LG 360 拍摄的照片上有这两个标签。
我在 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;
}
我正在呈现如下所示的 属性 详细信息页面(可以访问 Here)
我有一个图像滑块和一个 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 度图像,并使用某种检测算法检测图像的性质,然后在我用于 static/plain 图像的同一图像滑块中显示图像。
研究
我阅读了 this thread on Whosebug which made a little sense about reading the meta data of the file using EXIF 工具,但这使得这个过程非常手动。
问题
我想自动读取图像,在我的 php 图像上传代码中使用它,或者在函数中编写检测算法,该函数获取图像名称作为参数,return 图像类型为普通或360. 基于此 return 我可以轻松渲染视图。所以我的问题是如何在 php?
中进行检测There isn't yet a standard for tagging a photo as containing 360 content.
建议您寻找EXIF标签
Projection Type : equirectangular
您还可以寻找
Use Panorama Viewer : True
我的 LG 360 拍摄的照片上有这两个标签。
我在 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;
}