Ask Your Question

Revision history [back]

ArUco relative marker position and rvec/tvec inversion

I am trying to write a program with aruco+openCV. Program detects two ArUco markers, invert the second one and compose them together. Result is another tvec and rvec. I am summing tvec and first markers tvec, multiplying rvec and first markers rvec. And trying to show that with projectPoints and cv.imshow. My tvec/rvec invert operation code:

def inversePerspective(rvec, tvec):
    R, _ = cv2.Rodrigues(rvec)
    R = np.matrix(R).T
    invTvec = np.dot(-R, np.matrix(tvec))
    invRvec, _ = cv2.Rodrigues(R)
    return invRvec, invTvec

In another question user Tetragramm helped me to understand the basics. You can find the question in: http://answers.opencv.org/question/175705/mapping-aruco-markers/

And I thought I should test my functions. In relative position function:

def relativePosition(rvec1, tvec1, rvec2, tvec2):
    rvec1, tvec1 = rvec1.reshape((3, 1)), tvec1.reshape((3, 1))
    rvec2, tvec2 = rvec2.reshape((3, 1)), tvec2.reshape((3, 1))

    # Inverse the second marker, the right one in the image
    invRvec, invTvec = inversePerspective(rvec2, tvec2)

    print(invRvec, invTvec, "\n and \n", inversePerspective(invRvec, invTvec))

    info = cv2.composeRT(rvec1, tvec1, invRvec, invTvec)
    composedRvec, composedTvec = info[0], info[1]

    composedRvec = composedRvec.reshape((3, 1))
    composedTvec = composedTvec.reshape((3, 1))

    return composedRvec, composedTvec

I executed code once and showed 2 markers that near to each other. Normally I should expect that in print function, it should print almost the same matrices. The output was:

[[0.03154277]
 [0.09233561]
 [1.50092897]] [[ 0.0208505 ]
 [ 0.05647337]
 [-0.00029105]]
 and
 (array([[-0.03154277],
   [-0.09233561],
   [-1.50092897]]), matrix([[-0.05770734],
  [ 0.01679542],
  [-0.00344181]]))

Obviously they are different. Is there anything I did wrong ? My current code is in github and I really accept any kind of help. I am searching for days and days. Thanks in advance for the answers, here is the codebase: https://github.com/aliyasineser/GraduationProjectII/blob/master/aruco_tracker.py

ArUco relative marker position and rvec/tvec inversion

I am trying to write a program with aruco+openCV. Program detects two ArUco markers, invert the second one and compose them together. Result is another tvec and rvec. I am summing tvec and first markers tvec, multiplying rvec and first markers rvec. And trying to show that with projectPoints and cv.imshow. My tvec/rvec invert operation code:

def inversePerspective(rvec, tvec):
    R, _ = cv2.Rodrigues(rvec)
    R = np.matrix(R).T
    invTvec = np.dot(-R, np.matrix(tvec))
    invRvec, _ = cv2.Rodrigues(R)
    return invRvec, invTvec

In another question user Tetragramm helped me to understand the basics. You can find the question in: http://answers.opencv.org/question/175705/mapping-aruco-markers/

And I thought I should test my functions. In relative position function:

def relativePosition(rvec1, tvec1, rvec2, tvec2):
    rvec1, tvec1 = rvec1.reshape((3, 1)), tvec1.reshape((3, 1))
    rvec2, tvec2 = rvec2.reshape((3, 1)), tvec2.reshape((3, 1))

    # Inverse the second marker, the right one in the image
    invRvec, invTvec = inversePerspective(rvec2, tvec2)

    print(invRvec, invTvec, "\n and \n", inversePerspective(invRvec, invTvec))

    info = cv2.composeRT(rvec1, tvec1, invRvec, invTvec)
    composedRvec, composedTvec = info[0], info[1]

    composedRvec = composedRvec.reshape((3, 1))
    composedTvec = composedTvec.reshape((3, 1))

    return composedRvec, composedTvec

I executed code once and showed 2 markers that near to each other. Normally I should expect that in print function, it should print almost the same matrices. The output was:

[[0.03154277]
 [0.09233561]
 [1.50092897]] [[ 0.0208505 ]
 [ 0.05647337]
 [-0.00029105]]
 and
 (array([[-0.03154277],
   [-0.09233561],
   [-1.50092897]]), matrix([[-0.05770734],
  [ 0.01679542],
  [-0.00344181]]))

Obviously they are different. Is there anything I did wrong ? My current code is in github and I really accept any kind of help. I am searching for days and days. Thanks in advance for the answers, here is the codebase: https://github.com/aliyasineser/GraduationProjectII/blob/master/aruco_tracker.py

ArUco relative marker position and rvec/tvec inversion

I am trying to write a program with aruco+openCV. Program detects two ArUco markers, invert the second one and compose them together. Result is another tvec and rvec. I am summing tvec and first markers tvec, multiplying rvec and first markers rvec. And trying to show that with projectPoints and cv.imshow. My tvec/rvec invert operation code:

def inversePerspective(rvec, tvec):
    R, _ = cv2.Rodrigues(rvec)
    R = np.matrix(R).T
    invTvec = np.dot(-R, np.matrix(tvec))
    invRvec, _ = cv2.Rodrigues(R)
    return invRvec, invTvec

In another question user Tetragramm helped me to understand the basics. You can find the question in: http://answers.opencv.org/question/175705/mapping-aruco-markers/

And I thought I should test my functions. In relative position function:

def relativePosition(rvec1, tvec1, rvec2, tvec2):
    rvec1, tvec1 = rvec1.reshape((3, 1)), tvec1.reshape((3, 1))
    rvec2, tvec2 = rvec2.reshape((3, 1)), tvec2.reshape((3, 1))

    # Inverse the second marker, the right one in the image
    invRvec, invTvec = inversePerspective(rvec2, tvec2)

    print(invRvec, invTvec, print(rvec2, tvec2, "\n and \n", inversePerspective(invRvec, invTvec))

    info = cv2.composeRT(rvec1, tvec1, invRvec, invTvec)
    composedRvec, composedTvec = info[0], info[1]

    composedRvec = composedRvec.reshape((3, 1))
    composedTvec = composedTvec.reshape((3, 1))

    return composedRvec, composedTvec

I executed code once and showed 2 markers that near to each other. Normally I should expect that in print function, it should print almost the same matrices. The output was:

[[0.03154277]
 [0.09233561]
 [1.50092897]] [[ 0.0208505 ]
rvec:  [[-0.08162009]
[-0.07777238]
 [-1.46936788]] tvec:  [[-0.05844654]
 [ 0.05647337]
 [-0.00029105]]
0.01511464]
 [ 0.00109817]]
 and
 (array([[-0.03154277],
   [-0.09233561],
   [-1.50092897]]), matrix([[-0.05770734],
 [[-0.08162009]
 [-0.07777238]
 [-1.46936788]] [[-0.05844654]
 [ 0.01679542],
  [-0.00344181]]))
0.01511464]
 [ 0.00109817]]

Obviously they are different. It means that my invert code is ok. And I am using composeRT to compose two rvec/tvecs. Is there anything I did wrong ? My current code is in github and I really accept any kind of help. I am searching for days and days. Thanks in advance for the answers, here is the codebase: https://github.com/aliyasineser/GraduationProjectII/blob/master/aruco_tracker.py

Edit: I print wrong test code. I corrected that.