lvreng GitHub avatar

puzzle-vision-simulator

lvreng

A visual algorithm simulation and puzzle solving program for the 2026 National College Student Electronic Design Contest Problem E, which reconstructs randomly cut and scattered polygons into a target rectangle from rendered images and outputs pose matrices.

Stars

51

7-day growth

No data

Forks

5

Open issues

0

License

No data

Last updated

2026-07-29

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It closely mirrors the official contest requirements, provides complete data isolation between generation and recognition, and includes a GUI, batch testing, and animation playback, making it a practical reference for participants.

Who it is for

  • Students preparing for the 2026 electronic design contest (Problem E)
  • Advisors and instructors of contest teams
  • Developers working on computer vision for robotic manipulation
  • Hobbyists interested in puzzle solving algorithms

Use cases

  • Algorithm validation and debugging for contest preparation
  • Training and testing of visual segmentation and pose estimation pipelines
  • Generating ground-truth transforms for robot arm integration
  • Demonstrating the complete pipeline from camera image to assembled rectangle

Strengths

  • Strict data isolation: the recognition module only receives a rendered image, not synthetic ground truth
  • Supports 1–4 pieces with random straight or radial cuts, each meeting contest constraints
  • Outputs 3×3 homogeneous transformation matrices for each piece in pixel coordinates
  • Includes animated playback of piece motion and batch testing (100 random scenes)

Considerations

  • Assumes solid‑color pieces, top‑down view, no occlusion, and minimal perspective distortion
  • Does not include camera calibration, hand‑eye calibration, or robot arm control logic
  • White pieces may require background subtraction or fixed‑color thresholding in real use

README quick start

2026 年全国大学生电子设计竞赛 E 题:拼图装置

面向 2026 年全国大学生电子设计竞赛赛区赛(TI 杯)暨模拟电子系统设计 专题赛选拔赛 E 题“拼图装置”的视觉算法仿真、拼接求解与位姿输出程序。

这个项目生成一张随机切成 1~4 个多边形的矩形卡纸,把碎片随机旋转、平移并无重叠地摆放在 A4 纸上半区,然后只从渲染图像完成:

  1. 颜色分割与多边形轮廓识别;
  2. 根据切割边长度配对恢复碎片邻接关系;
  3. 通过刚体变换与全局闭环优化拼回矩形;
  4. 输出每块碎片从当前位置到下半区目标矩形的 3×3 齐次旋转平移矩阵。
  5. 按 P0、P1…的顺序实时播放每块碎片旋转、平移到目标位置的动画。

碎片数量可在界面中设置为 1~4。算法根据数量生成直线切割或中心放射切割, 每块都有矩形外边,符合赛题“不超过 4 片、每片不超过 5 边、每片至少一条边位于目标矩形外边”的约束。 仿真目标矩形固定为 10 cm × 6 cm,使用 40 px/cm 的比例渲染为 400 px × 240 px;切割、还原与位姿输出共用这一尺寸定义。

演示

逐块实时运动与拼接

动画展示视觉识别完成后,P0、P1、P2、P3 依次按照求解出的旋转和平移矩阵, 运动到 10 cm × 6 cm 目标矩形并完成拼接。GIF 会在 GitHub 页面自动循环播放。

4 块碎片

查看 4 块碎片高清 WebM 演示

3 块碎片

查看 3 块碎片高清 WebM 演示

与 2026 年电赛 E 题的对应关系

赛题视觉需求本项目实现
待拼接碎片不超过 4 片界面可设置 1~4 片
每片不超过 5 条边仿真生成的碎片最多 5 条边
每片至少一条边位于目标矩形外边切割生成器保证每片包含矩形外边
随机摆放后自动识别颜色分割、轮廓提取、多边形顶点识别
拼接成目标矩形切割边配对、邻接恢复、刚体拼接与全局闭环误差优化
目标矩形尺寸固定为 10 cm × 6 cm
机械臂移动所需位姿输出每片的旋转角、平移量及 3×3 齐次矩阵
展示移动过程按碎片编号依次播放实时旋转和平移动画
正常室内照明算法接口可替换为标定后的真实相机图像

本仓库实现的是视觉算法与拼接求解仿真。接入真实机械臂时,还需完成相机标定、 像素到工作台坐标转换、手眼标定、抓取点规划及机械臂运动控制。

生成与识别的数据隔离

生成阶段和视觉阶段通过图像边界隔离:

随机切割多边形 + 随机真值位姿
              │
              ▼
          渲染/PNG 编码
              │
              ▼
        PNG 解码后的相机像素
              │
              ├── 颜色分割与轮廓检测
              ├── 切割边配对与邻接恢复
              └── 全局拼接规划与位姿矩阵

generate_camera_frame() 只返回图像像素,不返回生成多边形、顶点、邻接关系或 真值旋转平移矩阵。analyze_camera_frame() 只接收图像;碎片数量也由图像轮廓 自动统计。界面中的“碎片数量”只控制生成器,不作为识别或拼接求解输入。 因此视觉结果可替换为真实相机图片,不依赖仿真生成数据。

隔离回归测试:

python3 -m unittest tests/test_image_isolation.py

运行

可视化测试界面:

python3 puzzle_gui.py

界面可按“生成场景 → 识别碎片 → 还原矩形”单步测试,也可自动演示、批量测试 100 个随机场景,并在右侧查看每块碎片的旋转角、平移量和 3×3 齐次矩阵。

命令行版本:

python3 puzzle_sim.py

指定随机种子并批量验证:

python3 puzzle_sim.py --seed 12 --output output/demo
python3 puzzle_sim.py --seed 12 --pieces 3 --output output/three
python3 puzzle_sim.py --batch 100

单次运行输出:

  • scene.png:随机摆放的相机输入;
  • detected.png:视觉识别出的轮廓、顶点与编号;
  • solution.png:目标矩形及还原结果;
  • transforms.json:每片的中心、角度、2×3 与 3×3 变换矩阵;
  • summary.png:输入、识别、还原三联图。

矩阵采用图像像素坐标(x 向右、y 向下)。对当前图像中的点 [x, y, 1]^T 左乘 matrix_3x3,即可得到目标矩形中的对应位置。机械臂使用时,再通过相机标定得到的单应矩阵/手眼标定矩阵,把像素位姿转换为工作台或机器人坐标。

算法边界

当前版本针对纯色碎片和俯视相机,假设碎片不接触、不遮挡、透视畸变较小。真机建议先做相机畸变校正和工作

Description

适配 2026 年全国大学生电子设计竞赛 E 题:1~4 片拼图视觉识别、矩形还原、位姿矩阵与可视化仿真

Related repositories

Similar projects matched by category, topics, and programming language.

lopopolo
Featured
lopopolo GitHub avatar

harness-engineering

Harness Engineering is a methodology for improving coding agent outputs by carefully crafting the environment around them—providing curated context, tools, and executable constraints that encode an organization’s nonfunctional requirements and cumulative lessons.

AI & Machine LearningAI Agents
2,390
slvDev
Featured
slvDev GitHub avatar

esp32-ai

A 28.9 million parameter language model runs on an $8 ESP32-S3 microcontroller entirely on-device, generating simple stories at about 9.5 tokens per second.

AI & Machine LearningLarge Language Models
1,960
littledivy
Featured
littledivy GitHub avatar

mimic

mimic captures traffic from any iOS or web app and automatically generates a Python client library that lets you call the app's API like a regular library.

AI & Machine Learning
1,482