ChessBoard.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ChessBot 作者: pakhandi 项目源码 文件源码
def detectAllVertices(self, testImg):
        # Detecting vertices on the newly constructed board
        self.gray = cv2.cvtColor(testImg, cv2.COLOR_BGR2GRAY)

        tempVertices = cv2.goodFeaturesToTrack(self.gray, int(self.FINAL_VERTICES_COUNT), 0.01, 10)
        tempVertices = np.int0(tempVertices)

        newVertices = []

        for i in tempVertices:
            x, y = i.ravel()
            newVertices.append((x, y))

        # Matrix to store coordinates of vertices on the board
        self.ALL_VERTICES = [[(0, 0) for x in range(self.FACTOR + 2)] for x in range(self.FACTOR + 2)]

        # Filling the matrix
        self.ALL_VERTICES[0][0] = (self.CORNERS[1])

        for i in range(0, self.FACTOR):
            for j in range(0, self.FACTOR):
                predicted_x = self.ALL_VERTICES[i][j][0] + int(
                    (self.OUTER_VERTICES[2][self.FACTOR - i][0] - self.OUTER_VERTICES[0][i][0]) / 8)
                predicted_y = self.ALL_VERTICES[i][j][1] + int(
                    (self.OUTER_VERTICES[3][self.FACTOR - i][1] - self.OUTER_VERTICES[1][i][1]) / 8)

                minn_dist = self.INT_MAX

                for point in newVertices:
                    this_dist = Geometry.getPointsDistance(point, (predicted_x, self.ALL_VERTICES[i][j][1]))
                    if this_dist < minn_dist:
                        self.ALL_VERTICES[i][j + 1] = point
                        minn_dist = this_dist

                minn_dist = self.INT_MAX

                for point in newVertices:
                    this_dist = Geometry.getPointsDistance(point, (self.ALL_VERTICES[i][j][0], predicted_y))
                    if this_dist < minn_dist:
                        self.ALL_VERTICES[i + 1][j] = point;
                        minn_dist = this_dist

        self.ALL_VERTICES[self.FACTOR][self.FACTOR] = (self.CORNERS[3])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号