Commit e4977e1e authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. docs 2. tested

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