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
()
| 95 | |
| 96 | # TODO: Move this into scene_manager. |
| 97 | def 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 | ## |
no test coverage detected