修好了bug的安安展示

This commit is contained in:
TNOTawa
2025-10-21 22:02:41 +08:00
parent b552aacf89
commit bc9d025836
2 changed files with 17 additions and 18 deletions

View File

@ -245,24 +245,21 @@ async def _(
img_processed.save(img_data, "PNG")
await snaur_display_cmd.send(await UniMessage().image(raw=img_data).export())
anan_display_cmd = on_alconna(
Alconna(
"安安展示",
Args["image", Image],
),
)
anan_display_cmd = on_message()
@anan_display_cmd.handle()
async def _(msg: UniMsg, evt: Event, bot: Bot):
flag = False
for text in cast(Iterable[Text], msg.get(Text)):
if text.text.strip() == "安安展示":
stripped = text.text.strip()
if stripped == "安安展示":
flag = True
elif text.text.strip() == "":
elif stripped == "":
continue
else:
return
if not flag:
return
match await extract_image_from_message(evt.get_message(), evt, bot):
case Success(img):
img_handled = await draw_anan_display(img)

View File

@ -29,12 +29,12 @@ SNAUR_QUAD_POINTS = np.float32(cast(Any, [
anan_image_base = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "anan_base.png")
anan_image_top = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "anan_top.png")
ANAN_QUAD_POINTS = np.float32(cast(Any, [
[150, 250],
[650, 250],
[630, 750],
[170, 750],
]))
ANAN_QUAD_POINTS = np.float32([
[157, 585],
[793, 599],
[781, 908],
[160, 908]
])
def _draw_cao_display(image: PIL.Image.Image):
src = np.array(image.convert("RGB"))
@ -150,18 +150,20 @@ async def draw_snaur_display(
def _draw_anan_display(image: PIL.Image.Image) -> PIL.Image.Image:
src = np.array(image.convert("RGB"))
src = np.array(image.convert("RGBA"))
h, w = src.shape[:2]
src_points = np.float32(cast(Any, [
src_points = np.float32([
[0, 0],
[w, 0],
[w, h],
[0, h]
]))
])
dst_points = ANAN_QUAD_POINTS
M = cv2.getPerspectiveTransform(cast(Any, src_points), cast(Any, dst_points))
M = cv2.getPerspectiveTransform(src_points, dst_points)
output_w, output_h = anan_image_top.size
src_rgb = cv2.cvtColor(src, cv2.COLOR_RGBA2RGB) if src.shape[2] == 4 else src
warped_rgb = cv2.warpPerspective(
src_rgb,