mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
use clahe for contrast improvement (#6835)
* use clahe for contrast improvement * update tests
This commit is contained in:
parent
09cc4251f0
commit
7c1568fcb9
@ -187,7 +187,7 @@ class RecordConfig(FrigateBaseModel):
|
|||||||
|
|
||||||
class MotionConfig(FrigateBaseModel):
|
class MotionConfig(FrigateBaseModel):
|
||||||
threshold: int = Field(
|
threshold: int = Field(
|
||||||
default=40,
|
default=30,
|
||||||
title="Motion detection threshold (1-255).",
|
title="Motion detection threshold (1-255).",
|
||||||
ge=1,
|
ge=1,
|
||||||
le=255,
|
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
|
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")
|
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")
|
delta_alpha: float = Field(default=0.2, title="Delta Alpha")
|
||||||
frame_alpha: float = Field(default=0.02, title="Frame 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(
|
mask: Union[str, List[str]] = Field(
|
||||||
default="", title="Coordinates polygon for the motion mask."
|
default="", title="Coordinates polygon for the motion mask."
|
||||||
)
|
)
|
||||||
|
@ -38,6 +38,7 @@ class ImprovedMotionDetector(MotionDetector):
|
|||||||
self.improve_contrast = improve_contrast
|
self.improve_contrast = improve_contrast
|
||||||
self.threshold = threshold
|
self.threshold = threshold
|
||||||
self.contour_area = contour_area
|
self.contour_area = contour_area
|
||||||
|
self.clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
|
||||||
|
|
||||||
def detect(self, frame):
|
def detect(self, frame):
|
||||||
motion_boxes = []
|
motion_boxes = []
|
||||||
@ -55,7 +56,7 @@ class ImprovedMotionDetector(MotionDetector):
|
|||||||
|
|
||||||
# Improve contrast
|
# Improve contrast
|
||||||
if self.improve_contrast.value:
|
if self.improve_contrast.value:
|
||||||
resized_frame = cv2.equalizeHist(resized_frame)
|
resized_frame = self.clahe.apply(resized_frame)
|
||||||
|
|
||||||
# mask frame
|
# mask frame
|
||||||
resized_frame[self.mask] = [255]
|
resized_frame[self.mask] = [255]
|
||||||
|
@ -730,7 +730,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert config == frigate_config.dict(exclude_unset=True)
|
assert config == frigate_config.dict(exclude_unset=True)
|
||||||
|
|
||||||
runtime_config = frigate_config.runtime_config()
|
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):
|
def test_motion_contour_area_dynamic(self):
|
||||||
config = {
|
config = {
|
||||||
@ -758,7 +758,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert config == frigate_config.dict(exclude_unset=True)
|
assert config == frigate_config.dict(exclude_unset=True)
|
||||||
|
|
||||||
runtime_config = frigate_config.runtime_config()
|
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):
|
def test_merge_labelmap(self):
|
||||||
config = {
|
config = {
|
||||||
|
Loading…
Reference in New Issue
Block a user