Skip to content

Instantly share code, notes, and snippets.

@tuanpembual
Created July 10, 2015 12:17
Show Gist options
  • Save tuanpembual/943999db418d260736b7 to your computer and use it in GitHub Desktop.
Save tuanpembual/943999db418d260736b7 to your computer and use it in GitHub Desktop.
script check new image
#!/usr/bin/php
<?php
$gambar0 = 'gambar0.jpg';
$gambar1 = 'gambar1.jpg';
$alamatipcam = 'http://192.168.1.100/jpg/image.jpg';
$dirsimpan = 'simpan';
$threshold = 0.025;
$tidur = 2;
if (!is_dir($dirsimpan)) mkdir($dirsimpan);
$n = 0;
while (true) {
$comm = "wget -O $gambar1 $alamatipcam > /dev/null 2>&1";
exec($comm, $o, $s);
if ($s == 0 && file_exists($gambar0) && file_exists($gambar1)) {
$o = array();
$comm = "compare -verbose -metric MAE $gambar0 $gambar1 null: 2>&1";
exec($comm, $o, $s);
if ($s < 2) {
foreach ($o as $baris) {
if (strpos($baris, "all:") !== false) {
$kk = explode(" ", trim($baris));
$j = sizeof($kk);
$skor = $kk[$j - 1];
$skor = str_replace("(", "", $skor);
$skor = str_replace(")", "", $skor);
if ($skor > $threshold) {
echo date("Y-m-d H:i:s") . " $skor\n";
$nama = $dirsimpan . "/img-" . str_pad($n, 5, "0", STR_PAD_LEFT) . ".jpg";
copy($gambar1, $nama);
$n++;
}
}
}
} else {
die("$s Gagal eksekusi $comm\n");
}
} elseif ($s != 0) {
die("Gagal eksekusi $comm\n");
}
if (file_exists($gambar1)) rename($gambar1, $gambar0);
sleep($tidur);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment