修好了bug的安安展示
This commit is contained in:
@ -245,24 +245,21 @@ async def _(
|
|||||||
img_processed.save(img_data, "PNG")
|
img_processed.save(img_data, "PNG")
|
||||||
await snaur_display_cmd.send(await UniMessage().image(raw=img_data).export())
|
await snaur_display_cmd.send(await UniMessage().image(raw=img_data).export())
|
||||||
|
|
||||||
anan_display_cmd = on_alconna(
|
anan_display_cmd = on_message()
|
||||||
Alconna(
|
|
||||||
"安安展示",
|
|
||||||
Args["image", Image],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
@anan_display_cmd.handle()
|
@anan_display_cmd.handle()
|
||||||
async def _(msg: UniMsg, evt: Event, bot: Bot):
|
async def _(msg: UniMsg, evt: Event, bot: Bot):
|
||||||
flag = False
|
flag = False
|
||||||
for text in cast(Iterable[Text], msg.get(Text)):
|
for text in cast(Iterable[Text], msg.get(Text)):
|
||||||
if text.text.strip() == "安安展示":
|
stripped = text.text.strip()
|
||||||
|
if stripped == "安安展示":
|
||||||
flag = True
|
flag = True
|
||||||
elif text.text.strip() == "":
|
elif stripped == "":
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
if not flag:
|
if not flag:
|
||||||
return
|
return
|
||||||
|
|
||||||
match await extract_image_from_message(evt.get_message(), evt, bot):
|
match await extract_image_from_message(evt.get_message(), evt, bot):
|
||||||
case Success(img):
|
case Success(img):
|
||||||
img_handled = await draw_anan_display(img)
|
img_handled = await draw_anan_display(img)
|
||||||
|
|||||||
@ -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_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_image_top = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "anan_top.png")
|
||||||
ANAN_QUAD_POINTS = np.float32(cast(Any, [
|
ANAN_QUAD_POINTS = np.float32([
|
||||||
[150, 250],
|
[157, 585],
|
||||||
[650, 250],
|
[793, 599],
|
||||||
[630, 750],
|
[781, 908],
|
||||||
[170, 750],
|
[160, 908]
|
||||||
]))
|
])
|
||||||
|
|
||||||
def _draw_cao_display(image: PIL.Image.Image):
|
def _draw_cao_display(image: PIL.Image.Image):
|
||||||
src = np.array(image.convert("RGB"))
|
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:
|
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]
|
h, w = src.shape[:2]
|
||||||
|
|
||||||
src_points = np.float32(cast(Any, [
|
src_points = np.float32([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[w, 0],
|
[w, 0],
|
||||||
[w, h],
|
[w, h],
|
||||||
[0, h]
|
[0, h]
|
||||||
]))
|
])
|
||||||
dst_points = ANAN_QUAD_POINTS
|
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
|
output_w, output_h = anan_image_top.size
|
||||||
|
|
||||||
src_rgb = cv2.cvtColor(src, cv2.COLOR_RGBA2RGB) if src.shape[2] == 4 else src
|
src_rgb = cv2.cvtColor(src, cv2.COLOR_RGBA2RGB) if src.shape[2] == 4 else src
|
||||||
warped_rgb = cv2.warpPerspective(
|
warped_rgb = cv2.warpPerspective(
|
||||||
src_rgb,
|
src_rgb,
|
||||||
|
|||||||
Reference in New Issue
Block a user