Commit e4977e1e authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. docs 2. tested

parent fb3710ba
...@@ -27,6 +27,8 @@ set_time_limit(0); ...@@ -27,6 +27,8 @@ set_time_limit(0);
//CONSTANTS //CONSTANTS
$path="/data/footage/test"; // footage root $path="/data/footage/test"; // footage root
$dest_path="trash"; // folder for collecting non-matching results $dest_path="trash"; // folder for collecting non-matching results
$type = "jp4";
$N = 10;
function print_help(){ function print_help(){
global $argv; global $argv;
...@@ -34,11 +36,12 @@ function print_help(){ ...@@ -34,11 +36,12 @@ function print_help(){
echo <<<"TXT" echo <<<"TXT"
Help: Help:
* Usage: * Usage:
~$ {$argv[0]} path=[path-to-dir] dest_path=[dest-subdir] ~$ {$argv[0]} path=[path-to-dir] trash_path=[trash-subdir] n=[N]
where: where:
* path-to-dir - string - work at this path + 1 dir down * path-to-dir - string - scan for images at this path
* dest-subdir - string - save results to "path-to-dir/dest-subdir/" * trash-subdir - string - move filtered out images to this path
* N - integer - number of images in set - optional, default: 10
* Examples: * Examples:
** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash': ** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash':
...@@ -64,8 +67,12 @@ if (isset($_GET['path'])){ ...@@ -64,8 +67,12 @@ if (isset($_GET['path'])){
$path=$_GET['path']; $path=$_GET['path'];
} }
if (isset($_GET['dest_path'])){ if (isset($_GET['trash_path'])){
$dest_path = $_GET['dest_path']; $dest_path = $_GET['trash_path'];
}
if (isset($_GET['n'])){
$N = $_GET['n'];
} }
if (!is_dir($dest_path)) { if (!is_dir($dest_path)) {
...@@ -77,69 +84,48 @@ if (!is_dir($dest_path)) { ...@@ -77,69 +84,48 @@ if (!is_dir($dest_path)) {
$filelist = scandir($path); $filelist = scandir($path);
echo "<pre>\n"; $tmp_arr = Array();
$err_arr = Array();
foreach($filelist as $elem){
if (get_file_extension($path."/".$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)]++;
}
}
foreach ($filelist as $value) { if (count($tmp_arr)==0){
//echo $value."\n"; die("No images found at the path. Exit.\n");
if ($value!=$dest_path) process_folder($value,"jp4");
} }
function process_folder($file,$type) { //do actual copying
//print_r($tmp_arr);
global $path; foreach($tmp_arr as $key=>$val){
global $processing_folder; if ($val!=$N){
global $dest_path; for ($i=1;$i<=$N;$i++){
if (is_file("$path/{$key}_$i.$type")){
$tmp_arr = Array(); array_push($err_arr,"{$key}_$i.$type");
//echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n";
$url = "$pre_path/$processing_folder"; rename("$path/{$key}_$i.$type","$dest_path/{$key}_$i.$type");
}
$ext=get_file_extension($file); }
}
// exclude "." & ".." }
if (substr($file,0,1)!=".") {
if ($ext=="") { if (count($err_arr)!=0){
if (is_dir($url."/".$file)) { print("Filtered out images:\n");
//echo $url." ".$file."\n"; print_r($err_arr);
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")){
//echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n";
rename("$url/$file/{$key}_$i.$type","$url/$dest_path/{$key}_$i.$type");
}
}
}
}
}
}
}else{
//do nothing
}
}
} }
print("Number of images that were filtered out is ".count($err_arr).". Done.\n");
function get_file_extension($filename) { function get_file_extension($filename) {
//return substr(strrchr($filename, '.'), 1); //return substr(strrchr($filename, '.'), 1);
return pathinfo($filename, PATHINFO_EXTENSION); return pathinfo($filename, PATHINFO_EXTENSION);
} }
?> ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment