匹配的拼图块

发布于 2024-09-07 21:00:55 字数 669 浏览 2 评论 0原文

我没有什么有用的事情可做,正在玩这样的拼图游戏:

alt text http://manual.gimp.org/nl/images/filters/examples/render-taj-jigsaw.jpg

我想知道是否可以制作一个程序来帮助我把它放在一起。

想象一下,我有一个小拼图,比如 4x3 的拼图,但小标签和空白不均匀 - 不同的拼图具有不同的高度、不同的形状和不同的大小。我要做的就是给所有这些碎片拍照,让程序分析它们并将它们的属性存储在某个地方。然后,当我拿起一块拼图时,我可以要求程序告诉我哪些拼图应该是它的“邻居” - 或者如果我必须填写一个空白,它会告诉我想要的拼图块如何看。

不幸的是,我从未在图像处理和模式识别方面做过任何事情,所以我想向您寻求一些指导 - 如何识别拼图块(基本上是带有标签和孔的正方形)<强>在图片中?

然后我可能需要旋转它,使其处于正确的位置,缩放到一定比例,然后测量每侧的制表符/空白,以及每侧的坡度(如果存在)。

我知道扫描/拍摄 1000 块拼图并使用它会太耗时,这只是一个我可以学到新东西的宠物项目。

I have nothing useful to do and was playing with jigsaw puzzle like this:

alt text http://manual.gimp.org/nl/images/filters/examples/render-taj-jigsaw.jpg

and I was wondering if it'd be possible to make a program that assists me in putting it together.

Imagine that I have a small puzzle, like 4x3 pieces, but the little tabs and blanks are non-uniform - different pieces have these tabs in different height, of different shape, of different size. What I'd do is to take pictures of all of these pieces, let a program analyze them and store their attributes somewhere. Then, when I pick up a piece, I could ask the program to tell me which pieces should be its 'neighbours' - or if I have to fill in a blank, it'd tell me how does the wanted puzzle piece(s) look.

Unfortunately I've never did anything with image processing and pattern recognition, so I'd like to ask you for some pointers - how do I recognize a jigsaw piece (basically a square with tabs and holes) in a picture?

Then I'd probably need to rotate it so it's in the right position, scale to some proportion and then measure tab/blank on each side, and also each side's slope, if present.

I know that it would be too time consuming to scan/photograph 1000 pieces of puzzle and use it, this would be just a pet project where I'd learn something new.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与他有关 2024-09-14 21:00:55

数据采集

(这称为色度键、蓝屏或背景颜色方法)

  1. 找到一个光线充足的房间,整个房间的照明变化最小。
  2. 找到整个拼图/图片中很少使用的颜色(色调)。
  3. 准备一张颜色完全相同的彩纸。
  4. 将尽可能多的拼图块放在彩纸上。
    • 您可以将谜题分批分类,并在以后将其用作计算机提示。
    • 确保碎片不会重叠或相互接触。
    • 暂时不用担心方向问题。
  5. 拍照并下载到电脑。
    • 可能需要进行颜色校准,因为色度键背景可能会扰乱数码相机的内置颜色平衡。

采集数据处理

  1. 获取一些计算机视觉软件
    • OpenCV、MATLAB、C++、Java、Python 成像库等
  2. 图像上的色度键颜色执行连通分量。
    • 询问连接组件(即拼图块)的的轮廓。
  3. 修复检测到的列表中的错误。
  4. 选择索引词汇(参见 Ira Baxter 的帖子)并测量各个部分。
    • 如果碎片是矩形,请先找到角。
    • 如果碎片是稍微偏离的四边形,则边长(从角到角测量)也是一个有价值的签名。
    • 在 SO 或 Google 上搜索“Shape Context”或此处
    • 最后获取该作品的颜色直方图,方便后续按颜色查询作品。
  5. 为了使它们可搜索,请将它们放入数据库中,以便您可以使用索引词汇的任意组合来查询片段。

Data acquisition

(This is known as Chroma Key, Blue Screen or Background Color method)

  1. Find a well-lit room, with the least lighting variation across the room.
  2. Find a color (hue) that is rarely used in the entire puzzle / picture.
  3. Get a color paper that has that exactly same color.
  4. Place as many puzzle pieces on the color paper as it'll fit.
    • You can categorize the puzzles into batches and use it as a computer hint later on.
    • Make sure the pieces do not overlap or touch each other.
    • Do not worry about orientation yet.
  5. Take picture and download to computer.
    • Color calibration may be needed because the Chroma Key background may have upset the built-in color balance of the digital camera.

Acquisition data processing

  1. Get some computer vision software
    • OpenCV, MATLAB, C++, Java, Python Imaging Library, etc.
  2. Perform connected-component on the chroma key color on the image.
    • Ask for the contours of the holes of the connected component, which are the puzzle pieces.
  3. Fix errors in the detected list.
  4. Choose the indexing vocabulary (cf. Ira Baxter's post) and measure the pieces.
    • If the pieces are rectangular, find the corners first.
    • If the pieces are silghtly-off quadrilateral, the side lengths (measured corner to corner) is also a valuable signature.
    • Search for "Shape Context" on SO or Google or here.
    • Finally, get the color histogram of the piece, so that you can query pieces by color later.
  5. To make them searchable, put them in a database, so that you can query pieces with any combinations of indexing vocabulary.
简单气质女生网名 2024-09-14 21:00:55

退一步回到问题本身。构建拼图的问题可以很简单(P),也可以很困难(NP),具体取决于这些拼图是只适合一个邻居还是多个邻居。如果每条边只有一个适合,那么您只需找到每个块/边的邻居即可完成(O(#pieces*#sides))。如果某些块允许多次适合不同的邻居,那么,为了完成整个拼图,您可能需要回溯(因为您做出了错误的选择并且陷入了困境)。

然而,首先要解决的问题是如何表示棋子。如果您想表示任意形状,那么您可以使用透明度或蒙版来表示图块的哪些区域实际上是该块的一部分。如果您使用正方形,那么问题可能会更容易。在后一种情况下,您可以考虑正方形每边的最后一行像素,并将其与您在所有其他块中找到的最相似的像素行进行匹配。

尽管您使用的是方形瓷砖,但您可以使用第二种方法来实际帮助您解决真正的难题。真正的谜题通常是建立在 NxM 网格上的。当扫描盒子中的图像时,您将其分成相同的 NxM 方形瓷砖网格,然后让系统来解决这个问题。然后,问题是用系统内部的图块直观地映射您手中的实际波浪形部件(当它们很小且颜色均匀时)。但是,如果您在内部表示任意形状,则会遇到同样的问题。

A step back to the problem itself. The problem of building a puzzle can be easy (P) or hard (NP), depending of whether the pieces fit only one neighbour, or many. If there is only one fit for each edge, then you just find, for each piece/side its neighbour and you're done (O(#pieces*#sides)). If some pieces allow multiple fits into different neighbours, then, in order to complete the whole puzzle, you may need backtracking (because you made a wrong choice and you get stuck).

However, the first problem to solve is how to represent pieces. If you want to represent arbitrary shapes, then you can probably use transparency or masks to represent which areas of a tile are actually part of the piece. If you use square shapes then the problem may be easier. In the latter case, you can consider the last row of pixels on each side of the square and match it with the most similar row of pixels that you find across all other pieces.

You can use the second approach to actually help you solve a real puzzle, despite the fact that you use square tiles. Real puzzles are normally built upon a NxM grid of pieces. When scanning the image from the box, you split it into the same NxM grid of square tiles, and get the system to solve that. The problem is then to visually map the actual squiggly piece that you hold in your hand with a tile inside the system (when they are small and uniformly coloured). But you get the same problem if you represent arbitrary shapes internally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文