Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bashshell脚本在两个jpg上运行imgcmp并存储';不同的';一个_Bash_File_Shell_Variables - Fatal编程技术网

bashshell脚本在两个jpg上运行imgcmp并存储';不同的';一个

bashshell脚本在两个jpg上运行imgcmp并存储';不同的';一个,bash,file,shell,variables,Bash,File,Shell,Variables,我有一个IP摄像头,可以将文件ftps到我的SuSE服务器上的一个目录中 我正在尝试编写一个shell脚本来执行以下操作: for every file in a directory; use image compare to check this file against the next one store the output in a file or variable. if the next file is different then co

我有一个IP摄像头,可以将文件ftps到我的SuSE服务器上的一个目录中

我正在尝试编写一个shell脚本来执行以下操作:

for every file in a directory;
    use image compare to check this file against the next one
    store the output in a file or variable.
    if the next file is different then  
        copy the original to another folder
    else 
        delete the original
end for
在提示符处运行以下命令将生成以下命令:

myserver:/uploads # imgcmp -f img_01.jpg -F img_02.jpg -m rmse > value.txt
myserver:/uploads # cat value.txt
5.559730
5.276747
6.256132
myserver:/uploads #
我知道代码中存在加载错误,我遇到的主要问题是从脚本中执行imgcmp并从中提取值,因此请指出明显的问题,因为我可能不这么认为

FILES=/uploads/img*
declare -i value
declare -i result
value = 10
shopt -s nullglob
# no idea what the above even does #
# IFS=.
# attempt to read the floating point number from imgcmp & make it an integer
for f in $FILES
do
  echo "doing stuff w/ $f"
  imgcmp -f 4f -F 4f+1 -m rmse > value.txt
  # doesn't seem to find the files from the variables #
  result= ( $(<value.txt) )
  if [ $result > $value ] ; then
    echo 'different';
    # and copy it off to another directory #
  else
    echo 'same'
    # and delete it #
  fi
  if $f+1 = null; then
    break;
  fi
done
FILES=/uploads/img*
声明-i值
声明-i结果
值=10
shopt-s nullglob
#根本不知道上面这些是怎么回事#
#如果=。
#尝试从imgcmp读取浮点数并将其设置为整数
对于f,在$FILES中
做
echo“做事情w/$f”
imgcmp-f4f-f4f+1-m rmse>value.txt
#似乎无法从变量中找到文件#
结果=($($值];然后
呼应“不同”;
#并将其复制到另一个目录#
其他的
回声“相同”
#然后删除它#
fi
如果$f+1=null,则
打破
fi
完成
运行上述命令时,我收到一个错误
无法打开/上载/img_023.jpg+1
执行cat of value.txt不会显示任何内容,因此所有文件都显示为相同

我知道问题在哪里,但我不知道我应该做什么来提取imgcmp的输出(从脚本中运行),然后将其放入一个变量中,以便与之进行比较。

FILES=/uploads/*
FILES=/uploads/*

current=
for f in $FILES; do
  if [ -z "$current" ]; then
    current="$f"
    continue
  fi
  next="$f"
  echo "<> Comparing $current against $next"
  ## imgcmp will return non-0 if images cannot be compared
  ## and print an explanation message to stderr;
  if result=$(imgcmp -f $current -F $next -m rmse); then
    echo "comparison result: " $result
    ## Checking whether the first value returned
    ## is greater than 10
    if [ "$(echo "$result" | awk '$1 > 10 {print "different"}')" = "different" ]; then
      echo 'different';
      # cp -v $current /some/other/folder/
    else
      echo 'same'
      # rm -v $current
    fi
  else
    ## images cannot be compared... different dimensions / components / ...
    echo 'wholly different'
    # cp -v $current /some/other/folder/
  fi
  current="$next"
done
当前= 对于$FILES中的f;do 如果[-z“$current”];则 当前“$f” 持续 fi next=“$f” echo“将当前美元与下一个美元进行比较” ##如果无法比较图像,imgcmp将返回非0 ##并将解释消息打印到stderr; 如果结果=$(imgcmp-f$current-f$next-m rmse);则 echo“比较结果:$result” ##检查第一个值是否返回 ##大于10 如果[“$(echo“$result”| awk'$1>10{print“different”}')”=“different”];则 呼应“不同”; #cp-v$current/some/other/文件夹/ 其他的 回声“相同” #rm-v$current fi 其他的 ##无法比较图像…不同的维度/组件/。。。 回声“完全不同” #cp-v$current/some/other/文件夹/ fi current=“$next” 完成
您有一些打字错误(4f而不是$f)。您是否尝试使用basename提取文件名,使用sed提取名称的数字部分,然后重新组合?
如果[$result>$value]
不起作用。对于“大于”,请使用
-gt
而不是
比较。
用于标准输出重定向;它将创建一个名为
$value
内容的文件,并且
if
测试将始终成功。谢谢Costi,我会尝试一下,然后再回来。我之前在那里尝试过-gt,因为我读到了它想要的,但它给了我一个错误,说它期望其他东西?所以rry记不起是什么了,但我会试着发一些有用的回复,比如“嘿,它现在可以工作了”,或者“我不知道我在做什么,因为它说X”。真的很感谢你的帮助。Richard
-gt
只对整数有效;你可以用
bc
来代替。谢谢Costi,你是个明星。我整个上午都在玩w/sed awk,还剪了一段d要么是语法错误,要么是完全相同的字符(即,输出三行浮点数)。午饭后我会试一试,然后再回来找你。我想这些天我一定是个傻瓜,我知道我要做的事情的逻辑,但我的老脑子就是解释不了;€)Hi Costi,这是一个很好的逻辑,但是…我没有说明“不同”是什么意思。当imgcmp比较两张在两个不同时间拍摄的同一事物的照片时,它倾向于给出3.something到6.something的三个值,所以我想将$result的第一个值与10/10.0进行比较,以确定它是否为“int”我之前试着这么做,但我似乎太迟钝了。谢谢你的帮助和你的智慧,真的很感激。嗨,科斯蒂,很抱歉没有早点回来-只是在为一些人清理房间的过程中(未成年人)地震修复。我已经对一批图像进行了分析,看起来它正在进行。周五我将有更多的戏要演,等我把所有书架都卸下来,把墙壁上的东西和其他所有东西都清理进车库。非常有趣:€感谢你在这方面所做的一切:€)