首页 > 解决方案 > 有什么方法可以加入多个矢量(jpg格式)图像而没有任何重叠?

问题描述

我有一个拼图,其中图像分为 32 个图块。这些瓷砖被洗牌。现在我想用 python 和 OpenCV 解决这个难题。问题是图像中没有重叠。

例子

左图 右图

好处是图像具有统一的像素,因为它是从矢量图像转换而来的。

我尝试的是根据给定图像每一侧的分数找到给定图像每一侧的每个图像。

分数是多少? 所以我拍了一张图片,一方面让我们说右找到图像的最后一列(右侧)和所有其他图像的第一列(左侧)之间的差异,并将该差异相加并调用该分数。

#rightScore[i] will store the index of image on right side of the image at index 'i'.
#right[i] will store the pixels of right side of image at index 'i'.
#similarly for other sides.


    rightScore = np.zeros((36,))
    topScore = np.zeros((36,))
    bottomScore = np.zeros((36,))
    leftScore = np.zeros((36,))

    for i in range(36):
        score = np.inf
        for j in range(36): 
            if i==j: 
                continue

            temp = np.sum(np.abs(np.ravel(right[i] - left[j])))
            if score > temp: 
                rightScore[i] = j
                score = temp

现在对于给定的图像,我使用所有其他图像生成分数,然后找到最低分数。具有最低分数的相应图像是将位于给定图像左侧的图像。我为所有方面做这件事。

此方法适用于某些图像,但不适用于所有图像。任何人都可以帮忙吗?

另外,我知道最终图像将有 12 行,每行 3 个图块(12 * 3)。

标签: pythonopencvcomputer-visionpuzzle

解决方案


推荐阅读