Commit 4e88a04b authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

initial

parent 6d05d0ae
Loading
Loading
Loading
Loading

copy_all.php

0 → 100644
+59 −0
Original line number Diff line number Diff line
<?php
/*!*******************************************************************************
*! FILE NAME   : copy_all.php
*! DESCRIPTION : copies all the files to a specified destination
*! REVISION    : 1.00
*! AUTHOR      : Oleg Dzhimiev <oleg@elphel.com>
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  The four essential freedoms with GNU GPL software:
*!  * the freedom to run the program for any purpose
*!  * the freedom to study how the program works and change it to make it do what you wish
*!  * the freedom to redistribute copies so you can help your neighbor
*!  * the freedom to distribute copies of your modified versions to others
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*/

$folder = $_GET["src"];
$dest_folder = $_GET["dest"];
$imagej = $_GET["imagej"];
$ext = "jp4";

if (substr($dest_folder,-1,1)!="/") $dest_folder = $dest_folder."/";
if (substr($folder,-1,1)!="/") $folder = $folder."/";
if (substr($imagej,-1,1)!="/") $imagej = $imagej."/";

if (!is_dir($dest_folder)){
  $old = umask(0);
  @mkdir($dest_folder);
  umask($old);
}

if (!is_dir($imagej)){
  $old = umask(0);
  @mkdir($imagej);
  umask($old);
}

$subs = scandir($folder);

foreach($subs as $sub){
    if (is_dir($folder.$sub)&&($sub!="trash")) {
	exec("cp {$folder}{$sub}/*.$ext {$dest_folder}");
    }
}

?>

exif2kml.php

0 → 100755
+202 −0
Original line number Diff line number Diff line
<?php
/*!*******************************************************************************
*! FILE NAME   : exif2kml.php
*! DESCRIPTION : exracts location information into a KML file from images
*! REVISION    : 1.00
*! AUTHOR      : Oleg Dzhimiev <oleg@elphel.com>
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  The four essential freedoms with GNU GPL software:
*!  * the freedom to run the program for any purpose
*!  * the freedom to study how the program works and change it to make it do what you wish
*!  * the freedom to redistribute copies so you can help your neighbor
*!  * the freedom to distribute copies of your modified versions to others
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*/

require "pano.inc";

$LEFTFOV   = -180;
$RIGHTFOV  = +180;
$BOTTOMFOV = -90;
$TOPFOV    = +90;
$NEAR      = 10000; //meters?


if (isset($_GET['path'])) $path = $_GET['path'];
else if (isset($argv[1])) $path = $argv[1];

if (isset($_GET['ext']))  $ext = $_GET['ext'];
else if (isset($argv[2])) $ext = $argv[2];

if (isset($_GET['dest'])) $some_dir = $_GET['dest'];
else if (isset($argv[3])) $some_dir = $argv[3];

if (isset($_GET['index'])) $some_index =  $_GET['index'];
else if (isset($argv[4])) $some_index = $argv[4];

if (isset($_GET['visibility'])) $visibility = $_GET['visibility'];
else if (isset($argv[5])) $visibility = $argv[5];

$directory = $path;
$filename ="../results/for_wpe/map.kml";

echo "directory=$directory\n";
echo "filename= $filename\n";

chdir($directory);
$files=glob("*_1.$ext");
  
$numNodes=count($files);
echo "nNodes= $numNodes\n";

$world=array();
$i=0;
for ($j=0;$j<$numNodes;$j++) {
    if (strpos($files[$j],"_1")) {
	//echo strpos($files[$j],"_1")." $i\n";
	$world[$i]['href']=$files[$j];
	$exif_data = exif_read_data($files[$j]);
	$world[$i]['longitude']=(($exif_data['GPSLongitudeRef']=="W")?-1:1)*array2degrees($exif_data['GPSLongitude']);
	$world[$i]['latitude']= (($exif_data['GPSLatitudeRef'] =="S")?-1:1)*array2degrees($exif_data['GPSLatitude']);
	$world[$i]['altitude']= (($exif_data['GPSAltitudeRef'] =="1")?-1:1)*parseAlt($exif_data['GPSAltitude']);

	$world[$i]['DateTimeOriginal']= $exif_data['DateTimeOriginal'];
	$world[$i]['SubSecTimeOriginal']= $exif_data['SubSecTimeOriginal'];

	if (isset($exif_data['GPSImgDirection'])) {
	  $world[$i]['heading']=  parseAlt($exif_data['GPSImgDirection']); // add correction  from magnetic?
	  $world[$i]['tilt']= (($exif_data['GPSDestLatitudeRef'] =="S")?-1:1)*array2degrees($exif_data['GPSDestLatitude'])+90.0;
	  if ($world[$i]['tilt']<0) $world[$i]['tilt']==0;
	  else if ($world[$i]['tilt']>180) $world[$i]['tilt']=180;
	  $world[$i]['roll']=(($exif_data['GPSDestLongitudeRef']=="W")?-1:1)*array2degrees($exif_data['GPSDestLongitude']);
	}
	else{
	  $world[$i]['heading']=0;
	  $world[$i]['tilt']=90;
	  $world[$i]['roll']=0;
	}
	$i++;
    }
}

$numNodes = count($world);

// $file=fopen ($filename,'w');
// fwrite($file,generateKML());
// fclose($file);

// works by a couple microseconds slower
file_put_contents($filename,generateKML());

chmod($filename,0666);

  function array2degrees($dms) {
    $round=1000000;
    $d=explode('/',$dms[0]);
    $m=explode('/',$dms[1]);
    $s=explode('/',$dms[2]);
    $rslt= $d[0]/$d[1]+($m[0]/$m[1])/60.0+($s[0]/$s[1])/3600.0;
    return round($round*$rslt)/$round;
  } 
  function parseAlt($alt) {
    $round=1000000;
    $a=explode('/',$alt);
    $rslt=  $a[0]/$a[1];
    return round($round*$rslt)/$round;
  } 

  function generateKML($index=-1) {

    global $LEFTFOV;
    global $RIGHTFOV;
    global $BOTTOMFOV;
    global $TOPFOV;
    global $NEAR;

    global $world, $map, $numNodes;

    global $some_dir;
    global $some_index;
    global $visibility;

    if ($index<0) $indices=range(0,$numNodes-1);
    else $indices=array_merge(array(0=>$index),$map[$index]);

    $kml=<<<HEADER
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
HEADER;
    foreach ($indices as $i) {

      $dataTime = convert_to_some_time_format($world[$i]['DateTimeOriginal'],$world[$i]['SubSecTimeOriginal']);
      $href = modify_href($world[$i]['href']);

      $kml.= "<PhotoOverlay>\n";
      $kml.= "\t<name>".($i+$some_index)."</name>\n";
      $kml.= "\t<visibility>$visibility</visibility>\n";
      $kml.= "\t<shape>rectangle</shape>\n";
      $kml.= "\t<TimeStamp>\n";
      $kml.= "\t\t<when>".$dataTime."</when>\n";
      $kml.= "\t</TimeStamp>\n";
      $kml.= "\t<Camera>\n";
      $kml.= "\t\t<longitude>".$world[$i]['longitude']."</longitude>\n";
      $kml.= "\t\t<latitude>".$world[$i]['latitude']."</latitude>\n";
      $kml.= "\t\t<altitude>".$world[$i]['altitude']."</altitude>\n";
      $kml.= "\t\t<heading>".$world[$i]['heading']."</heading>\n";
      $kml.= "\t\t<tilt>".$world[$i]['tilt']."</tilt>\n";
      $kml.= "\t\t<roll>".$world[$i]['roll']."</roll>\n";
      $kml.= "\t</Camera>\n";
      $kml.= "\t<Icon>\n";
      $kml.= "\t\t<href>$some_dir/".$href."</href>\n";
      $kml.= "\t</Icon>\n";
      $kml.= "\t<ExtendedData>\n";
      $kml.= "\t\t<OriginalData>\n";
      $kml.= "\t\t\t<longitude>".$world[$i]['longitude']."</longitude>\n";
      $kml.= "\t\t\t<latitude>".$world[$i]['latitude']."</latitude>\n";
      $kml.= "\t\t\t<altitude>".$world[$i]['altitude']."</altitude>\n";
      $kml.= "\t\t\t<heading>".$world[$i]['heading']."</heading>\n";
      $kml.= "\t\t\t<tilt>".$world[$i]['tilt']."</tilt>\n";
      $kml.= "\t\t\t<roll>".$world[$i]['roll']."</roll>\n";
      $kml.= "\t\t</OriginalData>\n";
      $kml.= "\t</ExtendedData>\n";
      $kml.= "</PhotoOverlay>\n";
    }
    $kml.=<<<TRAILER
</Document>
</kml>
TRAILER;
    return ($kml);   

  }

function convert_to_some_time_format($date,$usec){
    $date[4] = "-";
    $date[7] = "-";
    $date[10] = "T";
    $date .= ".{$usec}Z";
    return $date;
}

function modify_href($name) {
    //$name = substr_replace($name,"",strpos($name,"_1-"),2);
    $name = "result_".substr($name,0,-6).".jpeg";
    return $name;
}


?>
 No newline at end of file

exif2kml_local.php

0 → 100644
+164 −0
Original line number Diff line number Diff line
<?php
/*!*******************************************************************************
*! FILE NAME   : exif2kml_local.php
*! DESCRIPTION : exracts location information into a KML file from images for Panorama Previewer
*! REVISION    : 1.00
*! AUTHOR      : Oleg Dzhimiev <oleg@elphel.com>
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  The four essential freedoms with GNU GPL software:
*!  * the freedom to run the program for any purpose
*!  * the freedom to study how the program works and change it to make it do what you wish
*!  * the freedom to redistribute copies so you can help your neighbor
*!  * the freedom to distribute copies of your modified versions to others
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*/

require "pano.inc";

if (isset($_GET['path'])) $path = $_GET['path'];
else if (isset($argv[1])) $path = $argv[1];
else                      $path = "test";

if (isset($_GET['ext']))  $ext = $_GET['ext'];
else if (isset($argv[2])) $ext = $argv[2];
else                      $ext = "jp4";

$filename="map_points.kml";

echo "<pre>";
echo "directory=$path\n";
echo "filename= $filename\n";

chdir("/data/footage/$path");

$list = scandir(".");
//ascending sort
asort($list);

$files = array();

foreach ($list as $value) {
    //echo $value."\n";
    if ($value!="trash") $files = array_merge($files,process_folder($value,"jp4"));
}
  
$numNodes=count($files);
echo "nNodes= $numNodes\n";

$world=array();
for ($i=0;$i<$numNodes;$i++) {
    $world[$i]['href']="http://127.0.0.1/footage/$path/".$files[$i];
    print("Reading: ".$files[$i]);
    print_r($exif_data_0);
    $exif_data = exif_read_data($files[$i]);
    print_r($exif_data);
    $world[$i]['longitude']=(($exif_data['GPSLongitudeRef']=="W")?-1:1)*array2degrees($exif_data['GPSLongitude']);
    $world[$i]['latitude']= (($exif_data['GPSLatitudeRef'] =="S")?-1:1)*array2degrees($exif_data['GPSLatitude']);
    $world[$i]['altitude']= (($exif_data['GPSAltitudeRef'] =="1")?-1:1)*parseAlt($exif_data['GPSAltitude']);
    if (isset($exif_data['GPSImgDirection'])) {
	$world[$i]['heading']=  parseAlt($exif_data['GPSImgDirection']); // add correction  from magnetic?
	$world[$i]['tilt']= (($exif_data['GPSDestLatitudeRef'] =="S")?-1:1)*array2degrees($exif_data['GPSDestLatitude'])+90.0;
	if ($world[$i]['tilt']<0) $world[$i]['tilt']==0;
	else if ($world[$i]['tilt']>180) $world[$i]['tilt']=180;
	$world[$i]['roll']=(($exif_data['GPSDestLongitudeRef']=="W")?-1:1)*array2degrees($exif_data['GPSDestLongitude']);
    }else{
      $world[$i]['heading']=0;
      $world[$i]['tilt']=90;
      $world[$i]['roll']=0;
    }
}

// $file=fopen ($filename,'w');
// fwrite($file,generateKML());
// fclose($file);

// works by a couple microseconds slower
file_put_contents($filename,generateKML());

chmod($filename,0666);


function array2degrees($dms) {
    $round=1000000;
    $d=explode('/',$dms[0]);
    $m=explode('/',$dms[1]);
    $s=explode('/',$dms[2]);
    $rslt= $d[0]/$d[1]+($m[0]/$m[1])/60.0+($s[0]/$s[1])/3600.0;
    return round($round*$rslt)/$round;
} 

function parseAlt($alt) {
    $round=1000000;
    $a=explode('/',$alt);
    $rslt=  $a[0]/$a[1];
    return round($round*$rslt)/$round;
} 

function generateKML($index=-1) {
    global $world, $map, $numNodes;
    if ($index<0) $indices=range(0,$numNodes-1);
    else $indices=array_merge(array(0=>$index),$map[$index]);
    $kml=<<<HEADER
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
HEADER;
    foreach ($indices as $i) {
      $kml.= "<PhotoOverlay>\n";
      $kml.= "  <Camera>\n";
      $kml.=sprintf("   <longitude>%s</longitude>\n",$world[$i]['longitude']);
      $kml.=sprintf("   <latitude>%s</latitude>\n",$world[$i]['latitude']);
      $kml.=sprintf("   <altitude>%s</altitude>\n",$world[$i]['altitude']);
      $kml.=sprintf("   <heading>%s</heading>\n",$world[$i]['heading']);
      $kml.=sprintf("   <tilt>%s</tilt>\n",$world[$i]['tilt']);
      $kml.=sprintf("   <roll>%s</roll>\n",$world[$i]['roll']);
      $kml.= "  </Camera>\n";
      $kml.= "  <Icon>\n";
      $kml.=sprintf("   <href>%s</href>\n",$world[$i]['href']);
      $kml.= "  </Icon>\n";
      $kml.= "</PhotoOverlay>\n";
    }
    $kml.=<<<TRAILER
</Document>
</kml>
TRAILER;
    return ($kml);   
}

function process_folder($file,$type) {

	$arr = array();
	$ext=get_file_extension($file);

	if (substr($file,0,1)!=".") {
		if ($ext=="") {
		    if (is_dir($file)) {
			$arr = glob("$file/*_1.jp4");
		    }
		}
	}

	return $arr;

}

function get_file_extension($filename) {
	//return substr(strrchr($filename, '.'), 1);
	return pathinfo($filename, PATHINFO_EXTENSION);
}

?>
 No newline at end of file

filesystem.php

0 → 100644
+51 −0
Original line number Diff line number Diff line
<?php

//echo "<pre>";
//echo update_subsubdir("footage/folder2",0,0);

function check_subdir($path,$subdir){
    if (is_dir("$path")) {
	if (is_writable("$path")) {
	    if (is_dir("$path/$subdir")) {
		if (is_writable("$path/$subdir")) 
		    return 0;
		else
		    return -2;
	    }else{
		$old = umask(0);
		mkdir("$path/$subdir",0777);
		umask($old);

		if (!is_dir("$path/$subdir")) return -3;
		else                          return 0;
	    }
	}
    }else{
	return -1;
    }
}

function update_subsubdir($path,$index,$limit,$index_max=100000){
    if ($index<=$index_max) {
      if (!is_dir("$path/$index")) {
// 	if (!@mkdir("$path/$index",0777)) return -2;
// 	else                              return $index;
	$old = umask(0);
	if (!@mkdir("$path/$index",0777)) return -2;
	umask($old);
	return $index;
      }else{
	$files = scandir("$path/$index");
	if (count($files)>=$limit+2) return update_subsubdir($path,$index+1,$limit);
	else                       return $index;
      }
    }else{
      return -1;
    }
}

function get_free_space($path){
    return disk_free_space($path);
}

?>

filter_jp4s.php

0 → 100644
+117 −0
Original line number Diff line number Diff line
<?php
/*!*******************************************************************************
*! FILE NAME   : filter_jp4s.php
*! DESCRIPTION : filters out incomplete panorama sets from the footage directory
*! REVISION    : 1.02
*! AUTHOR      : Oleg Dzhimiev <oleg@elphel.com>
*! Copyright (C) 2012 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  The four essential freedoms with GNU GPL software:
*!  * the freedom to run the program for any purpose
*!  * the freedom to study how the program works and change it to make it do what you wish
*!  * the freedom to redistribute copies so you can help your neighbor
*!  * the freedom to distribute copies of your modified versions to others
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*/

//disable the default time limit for php scripts.
set_time_limit(0);

//CONSTANTS

// footage root
$pre_path="/data/footage";

// folder for collecting non-matching results
$dest_path="trash";

//folder
if      (isset($_GET['path'])) $processing_folder = $_GET['path'];
else if (isset($argv[1]))      $processing_folder = $argv[1];
else                           $processing_folder = "test";

if (!is_dir("$pre_path/$processing_folder/$dest_path")) {
  //creating a folder with access rights - 0777
  $old = umask(0);
  @mkdir("$pre_path/$processing_folder/$dest_path");
  umask($old);
}

$filelist = scandir("$pre_path/$processing_folder");

echo "<pre>\n";

foreach ($filelist as $value) {
	//echo $value."\n";
	if ($value!=$dest_path) process_folder($value,"jp4");
}

function process_folder($file,$type) {

	global $pre_path;
	global $processing_folder;
	global $dest_path;

	$tmp_arr = Array();

	$url = "$pre_path/$processing_folder";

	$ext=get_file_extension($file);

	// exclude "." & ".."
	if (substr($file,0,1)!=".") {
		if ($ext=="") {
		    if (is_dir($url."/".$file)) {
			//echo $url."  ".$file."\n";
			if ($type=="") {
			    // do nothing
			}
			else {
			    $list = scandir($url."/".$file);
			    // getting deeper into indexed subfodlers
			    foreach($list as $elem){
				if (get_file_extension($url."/".$file."/".$elem)==$type) {
				      //echo $url."/".$file."/".$elem."\n";
				      // initialize array
				      if (!isset($tmp_arr[substr($elem,0,17)])) $tmp_arr[substr($elem,0,17)] = 0;
				      // 9th and 10th images are not part of the panorama
				      //if (!strstr($elem,"_9.")&&!strstr($elem,"_10.")) 
				      $tmp_arr[substr($elem,0,17)]++;
				}
			    }
			    //do actual copying
			    print_r($tmp_arr);
			    foreach($tmp_arr as $key=>$val){
				if ($val!=10) {
				    for ($i=1;$i<11;$i++){
					if (is_file("$url/$file/{$key}_$i.$type")) rename("$url/$file/{$key}_$i.$type","$url/$dest_path/{$key}_$i.$type");
				    }
				}
			    }
			}
		    }
		}else{
		    //do nothing
		}
	}
}

function get_file_extension($filename) {
	//return substr(strrchr($filename, '.'), 1);
	return pathinfo($filename, PATHINFO_EXTENSION);
}
  
?>
 No newline at end of file
Loading