【教学类-50-09】20240505“数一数”图片样式09:数一数(几何图案——透明颜色重叠+纯黑边框+黑框粗细)

背景需求:

【教学类-50-03】20240408“数一数”图片样式03:透明图形与边框不相交,透明图形和其他透明图形重叠-CSDN博客文章浏览阅读867次,点赞28次,收藏25次。【教学类-50-03】20240408“数一数”图片样式03:透明图形与边框不相交,透明图形和其他透明图形重叠https://blog.csdn.net/reasonsummer/article/details/137547784

问题一:浅色相交不容易点数

      前期幼儿对透明相交的几何图形进行选择,发现星3星4的部分学具完全没有填写过,幼儿表示:“太难了!”“我不会!”“好多图案!”也有几位孩子对3-1、星3-5、星4-2进行的点数,正确率较高

图11-8-1 星3-1正确率高

星4-2与星3-2的对比发现:星4-2随机生成的透明几何图案相对数量少(2-5个),交叉重叠少,便于幼儿点数。星3-2的生成的透明几何图案较多,相交重叠的面积大、多个图案密集交叉,幼儿无法辨认而放弃。

问题二:浅黄色看不清

有幼儿说自己看不清楚星3星4中重叠交叉的透明柠檬黄(明度太高,太亮刺眼)。直方图上也显示黄色点数的错误率都是大于等于红色和蓝色的错误率。(图13-1),对于看不见的黄色,我鼓励幼儿用记号笔画圈。

问题三:圈画图案容易弄脏

针对透明图案看不清图形的情况,我鼓励孩子们用记号笔画上黑色边框在点数。少量幼儿圈画图形,但描边不整齐;手掌擦抹,容易弄脏图案。

图15-2 手动圈画黑色边框

综上所述,我希望在图案边框加上黑色边框线,让透明色相交重叠后也能看清楚图形的外形结构

第1次添加边框效果

透明相交图案代码

'''
02数一数图形(都是一个方向三角形)边框内+图案重叠(透明相交有边框) 0.3
作者:AI对话大师、阿夏
时间:2024年4月28日 20:00
'''

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import os
import random
import time
from shapely.geometry import Polygon
from shapely.ops import cascaded_union

c = int(input('画布大小(15)\n'))
num=int(input('多少张\n'))
alp=0.3  # 透明相交,有边框,能分辨差异
# float(input('透明度(1.0=分开纯色)\n'))

# 创建目录
output_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\数一数2\02几何框内连接'
end=output_dir+r'\02透明相交有框线'
os.makedirs(output_dir, exist_ok=True)
os.makedirs(end, exist_ok=True)


for i in range(num):
    # 创建画布
    fig, ax = plt.subplots(figsize=(c, c))
    ax.set_xlim([0, c])
    ax.set_ylim([0, c])

    # 随机几个图形
    num_triangles = random.randint(1, 5)
    num_square = random.randint(1, 5)
    num_cicle = random.randint(1, 5)
    num_ellipse = random.randint(1, 5)
    num_rectangle = random.randint(1, 5)

    colors = ['red', 'yellow', 'blue']
    shapes = []
    # 直角三角形
    # for _ in range(num_triangles):
    #     while True:
    #         # 随机生成等腰直角三角形的顶点坐标
    #         base_point = np.random.rand(2) * c
    #         side_length = np.random.rand() * 2 + 1

    #         # 计算等腰直角三角形的顶点坐标
    #         top_point = base_point + np.array([side_length, 0])
    #         height_point = base_point + np.array([0, side_length])

    #         # 检查三角形是否在画布内部
    #         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c):
    #             break
        
    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充等腰直角三角形
    #     triangle_vertices = np.array([base_point, top_point, height_point])
    #     triangle = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(triangle)
   
   
    # # 随机生成多个等边三角形
    import math

    for _ in range(num_triangles):
        while True:
            # 随机生成等边三角形的顶点坐标
            base_point = np.random.rand(2) * c
            side_length = np.random.rand() * 2 + 1

            # 计算等边三角形的顶点坐标
            height = side_length * math.sqrt(3) / 2
            top_point = base_point + np.array([side_length / 2, height])
            left_point = base_point + np.array([0, 0])
            right_point = base_point + np.array([side_length, 0])

            # 检查三角形是否在画布内部
            triangle = Polygon([left_point, right_point, top_point])
            if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point >= 0) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充等边三角形
        triangle_vertices = np.array([left_point, right_point, top_point])
        triangle = Polygon(triangle_vertices)
        triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(triangle_patch)
        shapes.append(triangle)

    # 随机生成正方形
    for _ in range(num_square):
        while True:
            # 随机生成正方形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成正方形的边长
            side_length = np.random.rand() * 2 + 1

            # 检查正方形是否在画布内部
            if np.all(center - side_length/2 >= 0) and np.all(center + side_length/2 <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充正方形
        square = patches.Rectangle((center[0] - side_length/2, center[1] - side_length/2), side_length, side_length, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(square)

    # 随机生成圆形
    for _ in range(num_cicle):
        while True:
            # 随机生成圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成圆形的半径
            radius = np.random.rand() * 2 + 1

            # 检查圆形是否在画布内部
            if np.all(center - radius >= 0) and np.all(center + radius <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充圆形
        circle = patches.Circle(center, radius, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(circle)

    #  # 随机生成椭圆形
    # for _ in range(num_ellipse):
    #     while True:
    #         # 随机生成椭圆形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成椭圆形的长轴和短轴
    #         major_axis = np.random.rand() * 2 + 1
    #         minor_axis = np.random.rand() * 2 + 1

    #         # 检查椭圆形是否在画布内部
    #         ellipse_vertices = []
    #         num_points = 100
    #         angle = np.linspace(0, 2 * np.pi, num_points)
    #         for a in angle:
    #             x = center[0] + major_axis / 2 * np.cos(a)
    #             y = center[1] + minor_axis / 2 * np.sin(a)
    #             ellipse_vertices.append([x, y])
    #         ellipse = Polygon(ellipse_vertices)
    #         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
    #                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
    #             shape.intersects(ellipse) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充椭圆形
    #     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(ellipse_patch)
    #     shapes.append(ellipse)
      # # 随机生成椭圆形水平的垂直的(90和180)
#     import random

    for _ in range(num_ellipse):
        while True:
            # 随机生成椭圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成椭圆形的长轴和短轴
            major_axis = np.random.rand() * 2 + 1
            minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比

            # 随机选择椭圆形的旋转角度(90度或180度)
            angle = np.random.choice([np.pi / 2, np.pi])

            # 检查椭圆形是否在画布内部
            ellipse_vertices = []
            num_points = 100
            angle_points = np.linspace(0, 2 * np.pi, num_points)
            for a in angle_points:
                x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)
                y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)
                ellipse_vertices.append([x, y])
            ellipse = Polygon(ellipse_vertices)
            if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
                    center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
                shape.intersects(ellipse) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充椭圆形
        ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), alpha=alp,
                                        facecolor=color,edgecolor='black')
        ax.add_patch(ellipse_patch)
        shapes.append(ellipse)
    # # 随机生成长方形
    # for _ in range(num_rectangle):
    #     while True:
    #         # 随机生成长方形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成长方形的长和宽
    #         width = np.random.rand() * 2 + 1
    #         height = np.random.rand() * 2 + 1

    #         # 检查长方形是否在画布内部
    #         rectangle = Polygon([(center[0] - width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] + height / 2),
    #                              (center[0] - width / 2, center[1] + height / 2)])
    #         if np.all(center - np.array([width, height]) / 2 >= 0) and np.all(
    #                 center + np.array([width, height]) / 2 <= c) and not any(
    #             shape.intersects(rectangle) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充长方形
    #     rectangle_patch = patches.Rectangle((center[0] - width / 2, center[1] - height / 2), width, height,
    #                                         alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(rectangle_patch)
    #     shapes.append(rectangle)

    # 隐藏坐标轴
    ax.axis('off')

    # 保存图形
    output_path = os.path.join(end, f'{i:02d}.png')
    plt.savefig(output_path, dpi=200, bbox_inches='tight')

    # 关闭画布
    plt.close(fig)

    # 暂停3秒
    time.sleep(3)

但是幼儿操作中,我感觉打印出来的纸片上的黑色边框线并不明显。

所以有些孩子就在透明色的重叠图案上画边框做区分。

这种情况下,我有两个思路:

一、把透明度0.3改成0.9,增加背景色的纯度。

二、保留0.3的填充色透明度,但增加边框线条的粗细

第2次添加边框效果

实验一:把透明度0.3改成0.9,增加背景色的纯度。

'''
02数一数图形(都是一个方向三角形)边框内+图案重叠(透明相交有边框)0.9
作者:AI对话大师、阿夏
时间:2024年4月28日 20:00
'''

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import os
import random
import time
from shapely.geometry import Polygon
from shapely.ops import cascaded_union

c = int(input('画布大小(15)\n'))
num=int(input('多少张\n'))
alp=0.9  # 透明相交,有边框,能分辨差异
# float(input('透明度(1.0=分开纯色)\n'))

# 创建目录
output_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\数一数2\02几何框内连接'
end=output_dir+r'\02透明相交有框线'
os.makedirs(output_dir, exist_ok=True)
os.makedirs(end, exist_ok=True)


for i in range(num):
    # 创建画布
    fig, ax = plt.subplots(figsize=(c, c))
    ax.set_xlim([0, c])
    ax.set_ylim([0, c])

    # 随机几个图形
    num_triangles = random.randint(1, 5)
    num_square = random.randint(1, 5)
    num_cicle = random.randint(1, 5)
    num_ellipse = random.randint(1, 5)
    num_rectangle = random.randint(1, 5)

    colors = ['red', 'yellow', 'blue']
    shapes = []
    # 直角三角形
    # for _ in range(num_triangles):
    #     while True:
    #         # 随机生成等腰直角三角形的顶点坐标
    #         base_point = np.random.rand(2) * c
    #         side_length = np.random.rand() * 2 + 1

    #         # 计算等腰直角三角形的顶点坐标
    #         top_point = base_point + np.array([side_length, 0])
    #         height_point = base_point + np.array([0, side_length])

    #         # 检查三角形是否在画布内部
    #         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c):
    #             break
        
    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充等腰直角三角形
    #     triangle_vertices = np.array([base_point, top_point, height_point])
    #     triangle = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(triangle)
   
   
    # # 随机生成多个等边三角形
    import math

    for _ in range(num_triangles):
        while True:
            # 随机生成等边三角形的顶点坐标
            base_point = np.random.rand(2) * c
            side_length = np.random.rand() * 2 + 1

            # 计算等边三角形的顶点坐标
            height = side_length * math.sqrt(3) / 2
            top_point = base_point + np.array([side_length / 2, height])
            left_point = base_point + np.array([0, 0])
            right_point = base_point + np.array([side_length, 0])

            # 检查三角形是否在画布内部
            triangle = Polygon([left_point, right_point, top_point])
            if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point >= 0) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充等边三角形
        triangle_vertices = np.array([left_point, right_point, top_point])
        triangle = Polygon(triangle_vertices)
        triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(triangle_patch)
        shapes.append(triangle)

    # 随机生成正方形
    for _ in range(num_square):
        while True:
            # 随机生成正方形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成正方形的边长
            side_length = np.random.rand() * 2 + 1

            # 检查正方形是否在画布内部
            if np.all(center - side_length/2 >= 0) and np.all(center + side_length/2 <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充正方形
        square = patches.Rectangle((center[0] - side_length/2, center[1] - side_length/2), side_length, side_length, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(square)

    # 随机生成圆形
    for _ in range(num_cicle):
        while True:
            # 随机生成圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成圆形的半径
            radius = np.random.rand() * 2 + 1

            # 检查圆形是否在画布内部
            if np.all(center - radius >= 0) and np.all(center + radius <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充圆形
        circle = patches.Circle(center, radius, alpha=alp, facecolor=color,edgecolor='black')
        ax.add_patch(circle)

    #  # 随机生成椭圆形
    # for _ in range(num_ellipse):
    #     while True:
    #         # 随机生成椭圆形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成椭圆形的长轴和短轴
    #         major_axis = np.random.rand() * 2 + 1
    #         minor_axis = np.random.rand() * 2 + 1

    #         # 检查椭圆形是否在画布内部
    #         ellipse_vertices = []
    #         num_points = 100
    #         angle = np.linspace(0, 2 * np.pi, num_points)
    #         for a in angle:
    #             x = center[0] + major_axis / 2 * np.cos(a)
    #             y = center[1] + minor_axis / 2 * np.sin(a)
    #             ellipse_vertices.append([x, y])
    #         ellipse = Polygon(ellipse_vertices)
    #         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
    #                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
    #             shape.intersects(ellipse) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充椭圆形
    #     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(ellipse_patch)
    #     shapes.append(ellipse)
      # # 随机生成椭圆形水平的垂直的(90和180)
#     import random

    for _ in range(num_ellipse):
        while True:
            # 随机生成椭圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成椭圆形的长轴和短轴
            major_axis = np.random.rand() * 2 + 1
            minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比

            # 随机选择椭圆形的旋转角度(90度或180度)
            angle = np.random.choice([np.pi / 2, np.pi])

            # 检查椭圆形是否在画布内部
            ellipse_vertices = []
            num_points = 100
            angle_points = np.linspace(0, 2 * np.pi, num_points)
            for a in angle_points:
                x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)
                y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)
                ellipse_vertices.append([x, y])
            ellipse = Polygon(ellipse_vertices)
            if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
                    center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
                shape.intersects(ellipse) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充椭圆形
        ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), alpha=alp,
                                        facecolor=color,edgecolor='black')
        ax.add_patch(ellipse_patch)
        shapes.append(ellipse)
    # # 随机生成长方形
    # for _ in range(num_rectangle):
    #     while True:
    #         # 随机生成长方形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成长方形的长和宽
    #         width = np.random.rand() * 2 + 1
    #         height = np.random.rand() * 2 + 1

    #         # 检查长方形是否在画布内部
    #         rectangle = Polygon([(center[0] - width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] + height / 2),
    #                              (center[0] - width / 2, center[1] + height / 2)])
    #         if np.all(center - np.array([width, height]) / 2 >= 0) and np.all(
    #                 center + np.array([width, height]) / 2 <= c) and not any(
    #             shape.intersects(rectangle) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充长方形
    #     rectangle_patch = patches.Rectangle((center[0] - width / 2, center[1] - height / 2), width, height,
    #                                         alpha=alp, facecolor=color,edgecolor='black')
    #     ax.add_patch(rectangle_patch)
    #     shapes.append(rectangle)

    # 隐藏坐标轴
    ax.axis('off')

    # 保存图形
    output_path = os.path.join(end, f'{i:02d}.png')
    plt.savefig(output_path, dpi=200, bbox_inches='tight')

    # 关闭画布
    plt.close(fig)

    # 暂停3秒
    time.sleep(3)

再测试其他透明度。

透明度0.8中出现多图案同位置重叠,因为填充色纯度高,所以后面图案就看不见了。

这种情况需要用代码来剔除,至少让图形一部分漏出来,否则影响最后的统计结果(代码写出来5个圆,但明面上只能看到4个圆)

通过0.9-0.1的透明度测试,我感觉0.3的透明度出现透明,能够看到底层的几何图形,不会像0.9时颜色深,把最底层的图片遮挡了,完全看不见。

因此为了让图案边框线更星期,需要对黑色边框加粗(1磅变成10磅?)

实验二、图形黑色边框线加粗

代码展示

'''
02数一数图形(都是一个方向三角形)边框内+图案重叠(透明相交有边框)5磅黑色边框
作者:AI对话大师、阿夏
时间:2024年4月28日 20:00
'''

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import os
import random
import time
from shapely.geometry import Polygon
from shapely.ops import cascaded_union

c = int(input('画布大小(15)\n'))
num=int(input('多少张\n'))
alp=1.0  # 透明相交,有边框,能分辨差异
cx=5
# float(input('透明度(1.0=分开纯色)\n'))

# 创建目录
output_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\数一数2\02几何框内连接'
end=output_dir+r'\02透明相交有框线'
os.makedirs(output_dir, exist_ok=True)
os.makedirs(end, exist_ok=True)


for i in range(num):
    # 创建画布
    fig, ax = plt.subplots(figsize=(c, c))
    ax.set_xlim([0, c])
    ax.set_ylim([0, c])

    # 随机几个图形
    num_triangles = random.randint(1, 5)
    num_square = random.randint(1, 5)
    num_cicle = random.randint(1, 5)
    num_ellipse = random.randint(1, 5)
    num_rectangle = random.randint(1, 5)

    colors = ['red', 'yellow', 'blue']
    shapes = []
    # 直角三角形
    # for _ in range(num_triangles):
    #     while True:
    #         # 随机生成等腰直角三角形的顶点坐标
    #         base_point = np.random.rand(2) * c
    #         side_length = np.random.rand() * 2 + 1

    #         # 计算等腰直角三角形的顶点坐标
    #         top_point = base_point + np.array([side_length, 0])
    #         height_point = base_point + np.array([0, side_length])

    #         # 检查三角形是否在画布内部
    #         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c):
    #             break
        
    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充等腰直角三角形
    #     triangle_vertices = np.array([base_point, top_point, height_point])
    #     triangle = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black',linewidth=10)
    #     ax.add_patch(triangle)
   
   
    # # 随机生成多个等边三角形
    import math

    for _ in range(num_triangles):
        while True:
            # 随机生成等边三角形的顶点坐标
            base_point = np.random.rand(2) * c
            side_length = np.random.rand() * 2 + 1

            # 计算等边三角形的顶点坐标
            height = side_length * math.sqrt(3) / 2
            top_point = base_point + np.array([side_length / 2, height])
            left_point = base_point + np.array([0, 0])
            right_point = base_point + np.array([side_length, 0])

            # 检查三角形是否在画布内部
            triangle = Polygon([left_point, right_point, top_point])
            if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point >= 0) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充等边三角形
        triangle_vertices = np.array([left_point, right_point, top_point])
        triangle = Polygon(triangle_vertices)
        triangle_patch = patches.Polygon(triangle_vertices, closed=True, alpha=alp, facecolor=color,edgecolor='black',linewidth=cx)
        ax.add_patch(triangle_patch)
        shapes.append(triangle)

    # 随机生成正方形
    for _ in range(num_square):
        while True:
            # 随机生成正方形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成正方形的边长
            side_length = np.random.rand() * 2 + 1

            # 检查正方形是否在画布内部
            if np.all(center - side_length/2 >= 0) and np.all(center + side_length/2 <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充正方形
        square = patches.Rectangle((center[0] - side_length/2, center[1] - side_length/2), side_length, side_length, alpha=alp, facecolor=color,edgecolor='black',linewidth=cx)
        ax.add_patch(square)

    # 随机生成圆形
    for _ in range(num_cicle):
        while True:
            # 随机生成圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成圆形的半径
            radius = np.random.rand() * 2 + 1

            # 检查圆形是否在画布内部
            if np.all(center - radius >= 0) and np.all(center + radius <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充圆形
        circle = patches.Circle(center, radius, alpha=alp, facecolor=color,edgecolor='black',linewidth=cx)
        ax.add_patch(circle)

    #  # 随机生成椭圆形
    # for _ in range(num_ellipse):
    #     while True:
    #         # 随机生成椭圆形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成椭圆形的长轴和短轴
    #         major_axis = np.random.rand() * 2 + 1
    #         minor_axis = np.random.rand() * 2 + 1

    #         # 检查椭圆形是否在画布内部
    #         ellipse_vertices = []
    #         num_points = 100
    #         angle = np.linspace(0, 2 * np.pi, num_points)
    #         for a in angle:
    #             x = center[0] + major_axis / 2 * np.cos(a)
    #             y = center[1] + minor_axis / 2 * np.sin(a)
    #             ellipse_vertices.append([x, y])
    #         ellipse = Polygon(ellipse_vertices)
    #         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
    #                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
    #             shape.intersects(ellipse) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充椭圆形
    #     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, alpha=alp, facecolor=color,edgecolor='black',linewidth=cx)
    #     ax.add_patch(ellipse_patch)
    #     shapes.append(ellipse)
      # # 随机生成椭圆形水平的垂直的(90和180)
#     import random

    for _ in range(num_ellipse):
        while True:
            # 随机生成椭圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成椭圆形的长轴和短轴
            major_axis = np.random.rand() * 2 + 1
            minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比

            # 随机选择椭圆形的旋转角度(90度或180度)
            angle = np.random.choice([np.pi / 2, np.pi])

            # 检查椭圆形是否在画布内部
            ellipse_vertices = []
            num_points = 100
            angle_points = np.linspace(0, 2 * np.pi, num_points)
            for a in angle_points:
                x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)
                y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)
                ellipse_vertices.append([x, y])
            ellipse = Polygon(ellipse_vertices)
            if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
                    center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
                shape.intersects(ellipse) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)

        # 创建并填充椭圆形
        ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), alpha=alp,
                                        facecolor=color,edgecolor='black',linewidth=cx)
        ax.add_patch(ellipse_patch)
        shapes.append(ellipse)
    # # 随机生成长方形
    # for _ in range(num_rectangle):
    #     while True:
    #         # 随机生成长方形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成长方形的长和宽
    #         width = np.random.rand() * 2 + 1
    #         height = np.random.rand() * 2 + 1

    #         # 检查长方形是否在画布内部
    #         rectangle = Polygon([(center[0] - width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] + height / 2),
    #                              (center[0] - width / 2, center[1] + height / 2)])
    #         if np.all(center - np.array([width, height]) / 2 >= 0) and np.all(
    #                 center + np.array([width, height]) / 2 <= c) and not any(
    #             shape.intersects(rectangle) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充长方形
    #     rectangle_patch = patches.Rectangle((center[0] - width / 2, center[1] - height / 2), width, height,
    #                                         alpha=alp, facecolor=color,edgecolor='black',linewidth=cx)
    #     ax.add_patch(rectangle_patch)
    #     shapes.append(rectangle)

    # 隐藏坐标轴
    ax.axis('off')

    # 保存图形
    output_path = os.path.join(end, f'{i:02d}.png')
    plt.savefig(output_path, dpi=200, bbox_inches='tight')

    # 关闭画布
    plt.close(fig)

    # 暂停3秒
    time.sleep(3)

结果:此时可以发现,透明度影响边框线颜色,如果透明度越低边框线黑色会转为灰色,所以看不清楚。也就是说,这个透明度实际上的填充和边框共有的透明度

第3次添加边框效果

前期问题:设置填充出现透明后,边框也变成透明(黑变灰)

AI修改:让边框的透明度与填充透明度分开

代码展示

'''
02数一数图形(都是一个方向三角形)边框内+图案重叠(透明相交有边框)填充透明度0.3,边框深黑 透明度1.0 边框线粗细3磅
作者:AI对话大师、阿夏
时间:2024年4月28日 20:00
'''

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import os
import random
import time
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
import matplotlib.colors as mcolors

c = int(input('画布大小(15)\n'))
num=int(input('多少张\n'))
bjs=0.3  # 填充色的透明度
bkx=1.0  # 边框线的透明度(深黑
cx=3  # 黑色边框线的粗细
# alp=1.0  # 透明相交,有边框,能分辨差异
# float(input('透明度(1.0=分开纯色)\n'))

# 创建目录
output_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\数一数2\02几何框内连接'
end=output_dir+r'\02透明相交有框线'
os.makedirs(output_dir, exist_ok=True)
os.makedirs(end, exist_ok=True)


for i in range(num):
    # 创建画布
    fig, ax = plt.subplots(figsize=(c, c))
    ax.set_xlim([0, c])
    ax.set_ylim([0, c])

    # 随机几个图形
    num_triangles = random.randint(1, 5)
    num_square = random.randint(1, 5)
    num_cicle = random.randint(1, 5)
    num_ellipse = random.randint(1, 5)
    num_rectangle = random.randint(1, 5)

    colors = ['red', 'yellow', 'blue']
    
    shapes = []
    # 直角三角形
    # for _ in range(num_triangles):
    #     while True:
    #         # 随机生成等腰直角三角形的顶点坐标
    #         base_point = np.random.rand(2) * c
    #         side_length = np.random.rand() * 2 + 1

    #         # 计算等腰直角三角形的顶点坐标
    #         top_point = base_point + np.array([side_length, 0])
    #         height_point = base_point + np.array([0, side_length])

    #         # 检查三角形是否在画布内部
    #         if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(height_point <= c):
    #             break
        
    #     # 随机选择颜色
    #     color = np.random.choice(colors)

    #     # 创建并填充等腰直角三角形
    #     triangle_vertices = np.array([base_point, top_point, height_point])
    #     triangle = patches.Polygon(triangle_vertices, closed=True, facecolor=fill_color, edgecolor=edge_color,linewidth=10)
    #     ax.add_patch(triangle)
   
   
    # # 随机生成多个等边三角形
    import math

    for _ in range(num_triangles):
        while True:
            # 随机生成等边三角形的顶点坐标
            base_point = np.random.rand(2) * c
            side_length = np.random.rand() * 2 + 1

            # 计算等边三角形的顶点坐标
            height = side_length * math.sqrt(3) / 2
            top_point = base_point + np.array([side_length / 2, height])
            left_point = base_point + np.array([0, 0])
            right_point = base_point + np.array([side_length, 0])

   

            # 检查三角形是否在画布内部
            triangle = Polygon([left_point, right_point, top_point])
            if np.all(base_point >= 0) and np.all(top_point <= c) and np.all(left_point >= 0) and np.all(right_point <= c) and not any(shape.intersects(triangle) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)
       
        fill_color = mcolors.to_rgba(color, alpha=bjs)
        edge_color = mcolors.to_rgba('black', alpha=bkx)
            

        # 创建并填充等边三角形
        triangle_vertices = np.array([left_point, right_point, top_point])
        triangle = Polygon(triangle_vertices)

       
        triangle_patch = patches.Polygon(triangle_vertices, closed=True, facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
        ax.add_patch(triangle_patch)
        shapes.append(triangle)

    # 随机生成正方形
    for _ in range(num_square):
        while True:
            # 随机生成正方形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成正方形的边长
            side_length = np.random.rand() * 2 + 1

            # 检查正方形是否在画布内部
            if np.all(center - side_length/2 >= 0) and np.all(center + side_length/2 <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)
        fill_color = mcolors.to_rgba(color, alpha=bjs)
        edge_color = mcolors.to_rgba('black', alpha=bkx)

        # 创建并填充正方形
        square = patches.Rectangle((center[0] - side_length/2, center[1] - side_length/2), side_length, side_length, facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
        ax.add_patch(square)

    # 随机生成圆形
    for _ in range(num_cicle):
        while True:
            # 随机生成圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成圆形的半径
            radius = np.random.rand() * 2 + 1

            # 检查圆形是否在画布内部
            if np.all(center - radius >= 0) and np.all(center + radius <= c):
                break

        # 随机选择颜色
        color = np.random.choice(colors)
        fill_color = mcolors.to_rgba(color, alpha=bjs)
        edge_color = mcolors.to_rgba('black', alpha=bkx)

        # 创建并填充圆形
        circle = patches.Circle(center, radius, facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
        ax.add_patch(circle)

    #  # 随机生成椭圆形
    # for _ in range(num_ellipse):
    #     while True:
    #         # 随机生成椭圆形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成椭圆形的长轴和短轴
    #         major_axis = np.random.rand() * 2 + 1
    #         minor_axis = np.random.rand() * 2 + 1

    #         # 检查椭圆形是否在画布内部
    #         ellipse_vertices = []
    #         num_points = 100
    #         angle = np.linspace(0, 2 * np.pi, num_points)
    #         for a in angle:
    #             x = center[0] + major_axis / 2 * np.cos(a)
    #             y = center[1] + minor_axis / 2 * np.sin(a)
    #             ellipse_vertices.append([x, y])
    #         ellipse = Polygon(ellipse_vertices)
    #         if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
    #                 center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
    #             shape.intersects(ellipse) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)
    #     fill_color = mcolors.to_rgba(color, alpha=bjs)
    #     edge_color = mcolors.to_rgba('black', alpha=bkx)
    #     # 创建并填充椭圆形
    #     ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
    #     ax.add_patch(ellipse_patch)
    #     shapes.append(ellipse)
      # # 随机生成椭圆形水平的垂直的(90和180)
#     import random

    for _ in range(num_ellipse):
        while True:
            # 随机生成椭圆形的中心点坐标
            center = np.random.rand(2) * c

            # 随机生成椭圆形的长轴和短轴
            major_axis = np.random.rand() * 2 + 1
            minor_axis = major_axis / 2  # 将短轴设为长轴的一半,以满足2:1的长宽比

            # 随机选择椭圆形的旋转角度(90度或180度)
            angle = np.random.choice([np.pi / 2, np.pi])

            # 检查椭圆形是否在画布内部
            ellipse_vertices = []
            num_points = 100
            angle_points = np.linspace(0, 2 * np.pi, num_points)
            for a in angle_points:
                x = center[0] + major_axis / 2 * np.cos(a) * np.cos(angle) - minor_axis / 2 * np.sin(a) * np.sin(angle)
                y = center[1] + major_axis / 2 * np.cos(a) * np.sin(angle) + minor_axis / 2 * np.sin(a) * np.cos(angle)
                ellipse_vertices.append([x, y])
            ellipse = Polygon(ellipse_vertices)
            if np.all(center - np.array([major_axis, minor_axis]) / 2 >= 0) and np.all(
                    center + np.array([major_axis, minor_axis]) / 2 <= c) and not any(
                shape.intersects(ellipse) for shape in shapes):
                break

        # 随机选择颜色
        color = np.random.choice(colors)
        fill_color = mcolors.to_rgba(color, alpha=bjs)
        edge_color = mcolors.to_rgba('black', alpha=bkx)
        # 创建并填充椭圆形
        ellipse_patch = patches.Ellipse((center[0], center[1]), major_axis, minor_axis, angle=np.rad2deg(angle), facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
        ax.add_patch(ellipse_patch)
        shapes.append(ellipse)
    # # 随机生成长方形
    # for _ in range(num_rectangle):
    #     while True:
    #         # 随机生成长方形的中心点坐标
    #         center = np.random.rand(2) * c

    #         # 随机生成长方形的长和宽
    #         width = np.random.rand() * 2 + 1
    #         height = np.random.rand() * 2 + 1

    #         # 检查长方形是否在画布内部
    #         rectangle = Polygon([(center[0] - width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] - height / 2),
    #                              (center[0] + width / 2, center[1] + height / 2),
    #                              (center[0] - width / 2, center[1] + height / 2)])
    #         if np.all(center - np.array([width, height]) / 2 >= 0) and np.all(
    #                 center + np.array([width, height]) / 2 <= c) and not any(
    #             shape.intersects(rectangle) for shape in shapes):
    #             break

    #     # 随机选择颜色
    #     color = np.random.choice(colors)
    #     fill_color = mcolors.to_rgba(color, alpha=bjs)
    #     edge_color = mcolors.to_rgba('black', alpha=bkx)
    #     # 创建并填充长方形
    #     rectangle_patch = patches.Rectangle((center[0] - width / 2, center[1] - height / 2), width, height,
    #                                         facecolor=fill_color, edgecolor=edge_color,linewidth=cx)
    #     ax.add_patch(rectangle_patch)
    #     shapes.append(rectangle)

    # 隐藏坐标轴
    ax.axis('off')

    # 保存图形
    output_path = os.path.join(end, f'{i:02d}.png')
    plt.savefig(output_path, dpi=200, bbox_inches='tight')

    # 关闭画布
    plt.close(fig)

    # 暂停3秒
    time.sleep(3)

举例说明1 部分透明

1、填充色透明度0.3(透明的)

2、边框黑色透明度1.0(纯黑)、

3、边框黑色粗细3磅,

4、打印3张(15*15CM画布)

举例说明2:完全透明

1、填充色透明度0.1(几乎全透明)

2、边框黑色透明度1.0(纯黑)、

3、边框黑色粗细1磅,

4、打印3张(15*15CM画布)

举例说明3:不透明

1、填充色透明度0.7(几乎不透明

2、边框黑色透明度1.0(纯黑)、

3、边框黑色粗细1磅,

4、打印3张(15*15CM画布)

因为填充色接近与纯色,黑色边框看起来不明显(填充色与边框颜色的对比不强烈)

举例说明4:不透明

1、填充色透明度0.7(几乎不透明

2、边框黑色透明度1.0(纯黑)、

3、边框黑色粗细3磅(把黑色边框加粗1磅变成3磅)

4、打印3张(15*15CM画布)

到此,制作透明填充的几何图案时,也可以设置统一的黑色(0,0,0)边框来进行图形区分和判断。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/593101.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

银行ETL-监管报送

1104报表 1104报表主要包括&#xff1a;资产负债&#xff0c;表外业务、流动性风险、贷款质量、投向行业和地区、重点客户等。 1104报表分类 普通报表、机构特色类报表。 反洗钱 大额交易、可疑交易。标签分类&#xff1a;疑似犯罪、疑似毒品、疑似传销。 反洗钱—接口报…

tomcat+maven+java+mysql图书管理系统2-完善项目结构,添加相关依赖

1.创建java目录 接着选择java&#xff0c;回车&#xff0c;则创建成功&#xff0c;成功后在左侧栏能看见 2.修改pom.xml文件,(添加依赖) <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi…

pandas读取文件导致jupyter内核崩溃如何解决

读取execl文件出现以下问题: str_name "D:\\cao_use\\2017_2021(new).xlsx" train_df pd.read_excel(str_name, usecols[0])崩溃的指示图如下所示: bug原因:读入的文件太大&#xff0c;所需时间过长&#xff0c;在读取的过程中&#xff0c;使用中断按钮暂停会直…

mac监听 linux服务器可视化(Grafana+Promethus+Node_exporter)

Grafana和promethus(普罗米修斯)的安装和使用 监控系统的Prometheus类似于一个注册中心&#xff0c;我们可以只需要配置一个Prometheus,而在其他服务器&#xff0c;只需要安装node_exporter,它们的数据流转就是通过exporter采集数据信息&#xff0c;然后告诉prometheus它的位置…

AI视频教程下载:用 ChatGPT 和 WordPress 创建赚钱网站

您是否有兴趣开设网站&#xff08;博客&#xff09;&#xff0c;但不知道从何入手&#xff1f; 或者您已经开设了网站&#xff08;博客&#xff09;&#xff0c;但难以从中获利&#xff1f; 别找啦&#xff01; 本课程旨在教授您使用 WordPress 创建成功盈利网站&#xff08;博…

OpenCV(五) —— 人脸识别模型训练与 Windows 下的人脸识别

本文主要内容&#xff1a; 如何训练 OpenCV 的人脸识别模型如何在 Windows 下利用 OpenCV 进行人脸识别 1、概述 人脸识别需要人脸模型&#xff08;特征集合&#xff09;的支持&#xff0c;人脸定位的速度与准确度取决于模型。 OpenCV 提供了已经训练好的模型&#xff0c;无…

【莫比乌斯变换-04】求解莫比乌斯变换系数

求解莫比乌斯变换系数 文章目录 一、说明二、如何确定双线性变换系数2.1 变换基本形式2.2 通过三点确定 三、一般情况的变换3.1 最简单的情况&#xff1a;无穷大3.2 处理无穷大 四、Python 代码 一、说明 上一篇文章是对双线性变换的视觉介绍&#xff0c;又名莫比乌斯变换或分…

ThreeJS:补间动画与Tween.JS

补间动画 补间动画指的是做FLASH动画时&#xff0c;在两个关键帧中间需要做“补间动画”&#xff0c;才能实现图画的运动&#xff1b;插入补间动画后两个关键帧之间的插补帧是由计算机自动运算而得到的。 ——摘自《百度百科&#xff1a;补间动画_百度百科》 Tween.js Tween.js…

Python-VBA函数之旅-oct函数

目录 一、oct函数的常见应用场景 二、oct函数使用注意事项 三、如何用好oct函数&#xff1f; 1、oct函数&#xff1a; 1-1、Python&#xff1a; 1-2、VBA&#xff1a; 2、推荐阅读&#xff1a; 个人主页&#xff1a;神奇夜光杯-CSDN博客 一、oct函数的常见应用场景 oc…

W801学习笔记十七:古诗学习应用——上

硬件驱动以及软件架构大体上已经完成&#xff0c;尚存一些遗漏之处&#xff0c;后续会寻找合适的时机进行补充。自此章起&#xff0c;将正式迈入软件应用阶段&#xff0c;尤其是游戏开发领域。 关于第一个应用&#xff0c;此前已有一些构想&#xff1a; 其一&#xff0c;随机…

IO流-其他流:数据流,序列化流

import java.io.DataOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream;public class DataOutputStream1 {public static void main(String[] args) {//创建一个数据输出流包装一个低级的字节输出流try (DataOutputStream dosnew DataOutp…

9.3.k8s的控制器资源(deployment部署控制器)

目录 一、deployment部署控制器概念 二、deployment资源的清单编写 三、小结 功能 使用场景 原理 四、deployment实现升级和回滚 1.编辑deployment资源清单&#xff08;v1版本&#xff09; 2.创建service资源用于访问 ​编辑 3.修改deploy清单中pod镜像版本为V2 4…

「C/C++ 01」scanf()与回车滞留问题

目录 〇、scanf()接收用户输入的流程 一、回车的缓冲区滞留问题是什么&#xff1f; 二、为什么&#xff1f; 三、四个解决方法&#xff1a; 1. 在前面的scanf()中加上\n 2. 在scanf("%c")中添加空格 3. 使用getchar()来吸收回车 4. 使用fflush()清空缓冲区 〇、scan…

2.spring security 简单入门

创建springboot 项目&#xff0c;引入spring security坐标 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--spring security坐标--><dependency&g…

leecode每日一练

我一开始的思路也是dp&#xff0c;但是转移方程想错了&#xff0c;这个题目转移方程应该是dp[i] max(dp[i-2]nums[i],dp[i-1]) class Solution { public:int rob(vector<int>& nums) {int len nums.size();vector<int> dp(len);int ans 0;if(len>1)dp[0]…

IoTDB 入门教程 基础篇①——时序数据库为什么选IoTDB ?

文章目录 一、前文二、性能排行第一三、完全开源四、数据文件TsFile五、乱序数据高写入六、其他七、参考 一、前文 IoTDB入门教程——导读 关注博主的同学都知道&#xff0c;博主在物联网领域深耕多年。 时序数据库&#xff0c;博主已经用过很多&#xff0c;从最早的InfluxDB&a…

《Fundamentals of Power Electronics》——脉宽调制器建模

下图给出了一个简单脉宽调制器电路的原理图。 脉宽调制器电路产生一个用于指令转换器功率管导通和关断的逻辑信号δ(t)。该逻辑信号δ(t)是周期性的&#xff0c;其频率为fs&#xff0c;占空比为d(t)。脉宽调制器的输入是一个模拟控制信号vc(t)。脉宽调制器的作用是产生一个与模…

观测与预测差值自动变化系统噪声Q的自适应UKF(AUKF_Q)MATLAB编写

简述 基于三维模型的UKF&#xff0c;设计一段时间的输入状态误差较大&#xff0c;此时通过对比预测的状态值与观测值的残差&#xff0c;在相应的情况下自适应扩大系统方差Q&#xff0c;构成自适应无迹卡尔曼滤波&#xff08;AUKF&#xff09;&#xff0c;与传统的UKF相比&…

【人工智能Ⅱ】实验5:自然语言处理实践(情感分类)

实验5&#xff1a;自然语言处理实践&#xff08;情感分类&#xff09; 一&#xff1a;实验目的与要求 1&#xff1a;掌握RNN、LSTM、GRU的原理。 2&#xff1a;学习用RNN、LSTM、GRU网络建立训练模型&#xff0c;并对模型进行评估。 3&#xff1a;学习用RNN、LSTM、GRU网络做…

递归、搜索与回溯算法:记忆化搜索

例题一 解法&#xff08;暴搜 -> 记忆化搜索 -> 动态规划&#xff09;&#xff1a; 算法思路&#xff1a; 暴搜&#xff1a; a. 递归含义&#xff1a;给 dfs ⼀个使命&#xff0c;给他⼀个数 n &#xff0c;返回第 n 个斐波那契数的值&#xff1b; b. 函数体&…
最新文章