Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

docs for calculate percentage difference #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CAM2ImageArchiver/CameraHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def run(self):
frame_timestamp).strftime('%Y-%m-%d_%H-%M-%S-%f'))

if self.image_difference_percentage:
# Check the percentage difference if last frame is not None
# by calculating the pixel-by-pixel value difference between
# last frame and current frame, then divide the diff by frame size.
# Count pixel value by using numpy. Check numpy docs for np.absolute and np.count_nonzero
if frame.size != 0 and (type(camera.last_frame) == type(None) or (np.count_nonzero(np.absolute(camera.last_frame - frame)) * 100) / frame.size >= self.image_difference_percentage):
cv2.imwrite(file_name, frame)
camera.last_frame = frame
Expand Down
3 changes: 1 addition & 2 deletions CAM2ImageArchiver/test/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from CAM2ImageArchiver.CAM2ImageArchiver import CAM2ImageArchiver
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


class TestCamera(unittest.TestCase):

def setUp(self):
Expand All @@ -39,7 +38,7 @@ def setUp(self):
'camera_type': 'ip',
'ip': '207.251.86.238',
'port': '',
'image_path': '/cctv254.jpg',
'image_path': '/cctv290.jpg',
'video_path': '/axis-cgi/mjpg/video.cgi'
}
cam3 = {
Expand Down