use clahe for contrast improvement (#6835)

* use clahe for contrast improvement

* update tests
This commit is contained in:
Blake Blackshear 2023-06-18 11:56:41 -05:00 committed by GitHub
parent 09cc4251f0
commit 7c1568fcb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View File

@ -187,7 +187,7 @@ class RecordConfig(FrigateBaseModel):
class MotionConfig(FrigateBaseModel):
threshold: int = Field(
default=40,
default=30,
title="Motion detection threshold (1-255).",
ge=1,
le=255,
@ -196,10 +196,10 @@ class MotionConfig(FrigateBaseModel):
default=0.8, title="Lightning detection threshold (0.3-1.0).", ge=0.3, le=1.0
)
improve_contrast: bool = Field(default=True, title="Improve Contrast")
contour_area: Optional[int] = Field(default=15, title="Contour Area")
contour_area: Optional[int] = Field(default=10, title="Contour Area")
delta_alpha: float = Field(default=0.2, title="Delta Alpha")
frame_alpha: float = Field(default=0.02, title="Frame Alpha")
frame_height: Optional[int] = Field(default=50, title="Frame Height")
frame_height: Optional[int] = Field(default=100, title="Frame Height")
mask: Union[str, List[str]] = Field(
default="", title="Coordinates polygon for the motion mask."
)

View File

@ -38,6 +38,7 @@ class ImprovedMotionDetector(MotionDetector):
self.improve_contrast = improve_contrast
self.threshold = threshold
self.contour_area = contour_area
self.clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
def detect(self, frame):
motion_boxes = []
@ -55,7 +56,7 @@ class ImprovedMotionDetector(MotionDetector):
# Improve contrast
if self.improve_contrast.value:
resized_frame = cv2.equalizeHist(resized_frame)
resized_frame = self.clahe.apply(resized_frame)
# mask frame
resized_frame[self.mask] = [255]

View File

@ -730,7 +730,7 @@ class TestConfig(unittest.TestCase):
assert config == frigate_config.dict(exclude_unset=True)
runtime_config = frigate_config.runtime_config()
assert runtime_config.cameras["back"].motion.frame_height == 50
assert runtime_config.cameras["back"].motion.frame_height == 100
def test_motion_contour_area_dynamic(self):
config = {
@ -758,7 +758,7 @@ class TestConfig(unittest.TestCase):
assert config == frigate_config.dict(exclude_unset=True)
runtime_config = frigate_config.runtime_config()
assert round(runtime_config.cameras["back"].motion.contour_area) == 15
assert round(runtime_config.cameras["back"].motion.contour_area) == 10
def test_merge_labelmap(self):
config = {