def test_decode(self):
     arr = [[1, 0, 1, 0, 1, 0],
            [1, 0, 0, 0, 0, 1],
            [1, 0, 0, 1, 0, 0],
            [1, 1, 0, 1, 0, 1],
            [1, 1, 0, 1, 1, 0],
            [1, 1, 1, 1, 1, 1]]
     expect = 683
     self.assertTrue(DataMatrixCrypto.decode(arr) == expect)
     before = 62792
     matrix = DataMatrixCrypto.encode(before)
     after = DataMatrixCrypto.decode(matrix)
     self.assertTrue(before == after)
 def read_matrix(self, rect):
     """
         @param rect is two dimention array with point of a rectangle surrounding matrix area on image
         @return true if matrix is read succesfully or false if not
         Function read matrix in selected area.
     """
     wx = (rect[1][0] - rect[0][0]) / self.size
     wy = (rect[1][1] - rect[0][1]) / self.size
     vx = (rect[3][0] - rect[0][0]) / self.size
     vy = (rect[3][1] - rect[0][1]) / self.size
     first = [rect[0][0] + (wx + vx) / 2, rect[0][1] + (wy + vy) / 2]
     try:
         matrix = [[self.th[first[1] + i * wy + j * vy][first[0] + i * wx + j * vx] for i in range(self.size)] for j
                   in range(self.size)]
     except IndexError:
         return None
     if self.check_matrix(matrix):
         print(True)
         self.detected = True
         print(matrix)
         self.id = DataMatrixCrypto.decode(self.turn_matrix(matrix))
         print(matrix)
         print(self.id)
         return True
     else:
         self.detected = False
         return False