|
7 | 7 | from mongo_thingy import Thingy |
8 | 8 | from PIL import Image, ImageFilter, ImageOps |
9 | 9 |
|
10 | | -from api.config import BACKUP, DOT_PATH |
| 10 | +from api.config import BACKUP, CSGO2_MASK_PATH, VALORANT_MASK_PATH |
11 | 11 | from api.models.filter import Filter |
12 | 12 | from api.models.segment import Segment |
13 | 13 | from api.tools.audio import silence_if_no_audio |
14 | 14 | from api.tools.enums import SupportedGames |
15 | 15 | from api.tools.ffmpeg import merge_videos |
16 | 16 |
|
17 | 17 | logger = logging.getLogger("uvicorn") |
| 18 | +valorant_mask = Image.open(VALORANT_MASK_PATH) |
| 19 | +csgo2_mask = Image.open(CSGO2_MASK_PATH) |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class Highlight(Thingy): |
@@ -130,9 +132,7 @@ def _apply_filter_and_do_operations( |
130 | 132 |
|
131 | 133 | image = image.crop((1, 1, image.width - 2, image.height - 2)) |
132 | 134 |
|
133 | | - dot = Image.open(DOT_PATH) |
134 | | - |
135 | | - image.paste(dot, (0, 0), dot) |
| 135 | + image.paste(valorant_mask, (0, 0), valorant_mask) |
136 | 136 |
|
137 | 137 | left = image.crop((0, 0, 25, 60)) |
138 | 138 | right = image.crop((95, 0, 120, 60)) |
@@ -162,13 +162,31 @@ def post_process(image: Image) -> Image: |
162 | 162 | post_process, (899, 801, 122, 62), framerate=framerate |
163 | 163 | ) |
164 | 164 |
|
| 165 | + async def extract_csgo2_images(self, framerate: int = 4) -> bool: |
| 166 | + def post_process(image: Image) -> Image: |
| 167 | + image = ImageOps.grayscale( |
| 168 | + image.filter(ImageFilter.FIND_EDGES).filter( |
| 169 | + ImageFilter.EDGE_ENHANCE_MORE |
| 170 | + ) |
| 171 | + ) |
| 172 | + final = Image.new("RGB", (100, 100)) |
| 173 | + final.paste(image, (0, 0)) |
| 174 | + final.paste(csgo2_mask, (0, 0), csgo2_mask) |
| 175 | + return final |
| 176 | + |
| 177 | + return await self.extract_images( |
| 178 | + post_process, (930, 925, 100, 100), framerate=framerate |
| 179 | + ) |
| 180 | + |
165 | 181 | async def extract_images_from_game( |
166 | 182 | self, game: SupportedGames, framerate: int = 4 |
167 | 183 | ) -> bool: |
168 | 184 | if game == SupportedGames.OVERWATCH: |
169 | 185 | return await self.extract_overwatch_images(framerate) |
170 | 186 | elif game == SupportedGames.VALORANT: |
171 | 187 | return await self.extract_valorant_images(framerate) |
| 188 | + elif game == SupportedGames.CSGO2: |
| 189 | + return await self.extract_csgo2_images(framerate) |
172 | 190 | else: |
173 | 191 | raise NotImplementedError |
174 | 192 |
|
|
0 commit comments