diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 2654e0bf6..c1b7708be 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -807,6 +807,26 @@ def changedetection_app(config=None, datastore_o=None): return output + + # render an image which contains the diff of two images + # We always compare the newest against whatever compare_date we are given + @app.route("/diff/show-image//") + def show_single_image(uuid, datestr): + + from flask import make_response + watch = datastore.data['watching'][uuid] + + if datestr == 'None' or datestr is None: + datestr = list(watch['history'].keys())[0] + + fname = watch['history'][datestr] + with open(fname, 'rb') as f: + resp = make_response(f.read()) + + # @todo assumption here about the type, re-encode? detect? + resp.headers['Content-Type'] = 'image/jpeg' + return resp + # render an image which contains the diff of two images # We always compare the newest against whatever compare_date we are given @app.route("/diff/image//") @@ -819,10 +839,10 @@ def changedetection_app(config=None, datastore_o=None): # @todo this is weird if compare_date == 'None' or compare_date is None: - second_date = list(watch['history'].keys())[0] + compare_date = list(watch['history'].keys())[0] new_img = watch['history'][newest] - prev_img = watch['history'][second_date] + prev_img = watch['history'][compare_date] img = image_diff.render_diff(new_img, prev_img) resp = make_response(img) diff --git a/changedetectionio/image_diff.py b/changedetectionio/image_diff.py index fe4e5fd46..a95441224 100644 --- a/changedetectionio/image_diff.py +++ b/changedetectionio/image_diff.py @@ -38,4 +38,4 @@ def render_diff(fpath_imageA, fpath_imageB): cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2) #return cv2.imencode('.jpg', imageB)[1].tobytes() - return cv2.imencode('.jpg', imageB)[1].tobytes() \ No newline at end of file + return cv2.imencode('.jpg', imageA)[1].tobytes() \ No newline at end of file diff --git a/changedetectionio/templates/diff-image.html b/changedetectionio/templates/diff-image.html index 19b16569b..76e35ad3e 100644 --- a/changedetectionio/templates/diff-image.html +++ b/changedetectionio/templates/diff-image.html @@ -24,6 +24,15 @@
+ +
+ + + + + + +