MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / get_cv2_imwrite_params

Function get_cv2_imwrite_params

scenedetect/platform.py:97–121  ·  view source on GitHub ↗

Get OpenCV imwrite Params: Returns a dict of supported image formats and their associated quality/compression parameter index, or None if that format is not supported. Returns: Dictionary of supported image formats/extensions ('jpg', 'png', etc...) mapped to the respecti

()

Source from the content-addressed store, hash-verified

95
96# TODO: Move this into scene_manager.
97def get_cv2_imwrite_params() -> dict[str, int | None]:
98 """Get OpenCV imwrite Params: Returns a dict of supported image formats and
99 their associated quality/compression parameter index, or None if that format
100 is not supported.
101
102 Returns:
103 Dictionary of supported image formats/extensions ('jpg', 'png', etc...) mapped to the
104 respective OpenCV quality or compression parameter as {'jpg': cv2.IMWRITE_JPEG_QUALITY,
105 'png': cv2.IMWRITE_PNG_COMPRESSION, ...}. Parameter will be None if not found on the
106 current system library (e.g. {'jpg': None}).
107 """
108
109 def _get_cv2_param(param_name: str) -> int | None:
110 if param_name.startswith("CV_"):
111 param_name = param_name[3:]
112 try:
113 return getattr(cv2, param_name)
114 except AttributeError:
115 return None
116
117 return {
118 "jpg": _get_cv2_param("IMWRITE_JPEG_QUALITY"),
119 "png": _get_cv2_param("IMWRITE_PNG_COMPRESSION"),
120 "webp": _get_cv2_param("IMWRITE_WEBP_QUALITY"),
121 }
122
123
124##

Callers 2

save_imagesFunction · 0.90
save_images_commandFunction · 0.90

Calls 1

_get_cv2_paramFunction · 0.85

Tested by

no test coverage detected