Created
February 16, 2023 02:36
-
-
Save deepcoder/3d9ae7041e2bc40221e37fb2061b2969 to your computer and use it in GitHub Desktop.
python3 skimage program to look at noise level of most recent .jpg file in directory and do action based on noise level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env -S python3 -u | |
# python3 routine using scikit image library to determine of foscam camera has had been blinded at night | |
# and switched to day mode due to car headlights | |
# program looks at most recent still image captured from camera and check image noise level using scikit image measure | |
# 202109071212 | |
# | |
# example output: | |
# runtime : 1.42 , adjusting camera, response : <Response [200]>, noise level : 3.3104319013 | |
# | |
PROGRAM_NAME = "check_image_noise" | |
VERSION_MAJOR = "1" | |
VERSION_MINOR = "1" | |
WORKING_DIRECTORY = "/home/user/image_noise" | |
import syslog | |
import time | |
import requests | |
import glob | |
import os | |
import cv2 | |
from skimage.restoration import estimate_sigma | |
def estimate_noise(image_path): | |
img = cv2.imread(image_path) | |
# https://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.estimate_sigma | |
return estimate_sigma(img, multichannel=True, average_sigmas=True) | |
# get routine start time in seconds | |
start_time = time.time() | |
# image_dir = "/webcam-videos/foscam/stills/" | |
image_dir = "./" | |
list_of_files = glob.glob(image_dir + "*.jpg") | |
latest_file = max(list_of_files, key=os.path.getctime) | |
latest_noise = estimate_noise(latest_file) | |
print(latest_file, '{0:.10f}'.format(latest_noise)) | |
# TODO: noise level hardcode, should make it configurable or better dynamic | |
if latest_noise > 1.0 : | |
# response = requests.get("http://192.168.1.99:88/cgi-bin/CGIProxy.fcgi?cmd=setMainVideoStreamType&streamType=0&usr=aaaaaa&pwd=bbbbbb") | |
# adjust_message = "adjusting camera, response : " + str(response) + ", noise level : " | |
adjust_message = "adjustment made, noise level : " | |
else : | |
adjust_message = "no adjustment made, noise level : " | |
# get routine end time in seconds | |
end_time = time.time() | |
run_time = '{0:.2f}'.format(end_time - start_time) | |
adjust_message = "runtime : " + run_time +" , " + adjust_message | |
print(adjust_message + '{0:.10f}'.format(latest_noise)) | |
syslog.syslog(adjust_message + '{0:.10f}'.format(latest_noise)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment