From 6bc8012e048ff6119f995e8d61743af1f76499c3 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Mon, 9 Mar 2020 15:56:34 -0400 Subject: [PATCH 1/3] add support to render gif image that may be created by object detection --- web/views/image.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/views/image.php b/web/views/image.php index b05cc79d9..ecf24c93d 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -57,6 +57,7 @@ $filename = ''; $Frame = null; $Event = null; $path = null; +$image_type='image/jpeg'; if ( empty($_REQUEST['path']) ) { @@ -76,7 +77,16 @@ if ( empty($_REQUEST['path']) ) { return; } - if ( $_REQUEST['fid'] == 'objdetect' ) { + if ( $_REQUEST['fid'] == 'objdetectgif' ) { + $path = $Event->Path().'/objdetect.gif'; + if ( !file_exists($path) ) { + header('HTTP/1.0 404 Not Found'); + ZM\Fatal("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config"); + } + $Frame = new ZM\Frame(); + $Frame->Id('objdetect'); + $image_type = 'image/gif'; + } else if ( $_REQUEST['fid'] == 'objdetect' ) { $path = $Event->Path().'/objdetect.jpg'; if ( !file_exists($path) ) { header('HTTP/1.0 404 Not Found'); @@ -281,7 +291,7 @@ if ( !empty($_REQUEST['height']) ) { if ( $errorText ) { ZM\Error($errorText); } else { - header('Content-type: image/jpeg'); + header("Content-type: $image_type"); if ( ( $scale==0 || $scale==100 ) && ($width==0) && ($height==0) ) { # This is so that Save Image As give a useful filename if ( $Event ) { From 38b519c8a6681e51eec4f2a68026f1f5258a5ce9 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Mon, 9 Mar 2020 15:58:57 -0400 Subject: [PATCH 2/3] better error log --- web/views/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/views/image.php b/web/views/image.php index ecf24c93d..ef971c3f4 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -81,7 +81,7 @@ if ( empty($_REQUEST['path']) ) { $path = $Event->Path().'/objdetect.gif'; if ( !file_exists($path) ) { header('HTTP/1.0 404 Not Found'); - ZM\Fatal("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config"); + ZM\Fatal("File $path does not exist. You might not have enabled GIF creation in objectconfig.ini. If you have, inspect debug logs for errors during creation"); } $Frame = new ZM\Frame(); $Frame->Id('objdetect'); From 49f23cb35be16c93d14f12477e69c2735e8593fe Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Tue, 10 Mar 2020 13:51:55 -0400 Subject: [PATCH 3/3] Added options to render objdetect, objdetectanim and objdetectimage --- web/views/image.php | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/web/views/image.php b/web/views/image.php index ef971c3f4..27afb7580 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -77,16 +77,36 @@ if ( empty($_REQUEST['path']) ) { return; } - if ( $_REQUEST['fid'] == 'objdetectgif' ) { - $path = $Event->Path().'/objdetect.gif'; - if ( !file_exists($path) ) { - header('HTTP/1.0 404 Not Found'); - ZM\Fatal("File $path does not exist. You might not have enabled GIF creation in objectconfig.ini. If you have, inspect debug logs for errors during creation"); - } - $Frame = new ZM\Frame(); - $Frame->Id('objdetect'); - $image_type = 'image/gif'; - } else if ( $_REQUEST['fid'] == 'objdetect' ) { + if ( $_REQUEST['fid'] == 'objdetect' ) { + // if animation file is found, return that, else return image + $path_anim = $Event->Path().'/objdetect.gif'; + $path_image = $Event->Path().'/objdetect.jpg'; + if ( file_exists($path_anim)) { + // we found the animation/gif file + $path = $path_anim; + ZM\Logger::Debug("Animation file found at $path"); + $image_type = 'image/gif'; + } else if (file_exists($path_image)) { + // animation/gif not found, but image found + ZM\Logger::Debug("Image file found at $path"); + $path = $path_image; + } else { + // neither animation/gif nor image found + header('HTTP/1.0 404 Not Found'); + ZM\Fatal("Object detection animation and image not found for this event"); + } + $Frame = new ZM\Frame(); + $Frame->Id('objdetect'); + } else if ( $_REQUEST['fid'] == 'objdetectanim' ) { + $path = $Event->Path().'/objdetect.gif'; + if ( !file_exists($path) ) { + header('HTTP/1.0 404 Not Found'); + ZM\Fatal("File $path does not exist. You might not have enabled GIF creation in objectconfig.ini. If you have, inspect debug logs for errors during creation"); + } + $Frame = new ZM\Frame(); + $Frame->Id('objdetect'); + $image_type = 'image/gif'; + } else if ( $_REQUEST['fid'] == 'objdetectimage' ) { $path = $Event->Path().'/objdetect.jpg'; if ( !file_exists($path) ) { header('HTTP/1.0 404 Not Found');