How can I properly align cube over the marker in OpenGL?











up vote
0
down vote

favorite
3












I am trying to render a cube over a detect marker in openGL. I am doing it like this.



    rmtx = cv2.Rodrigues(rvec)[0]
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0][0][0]],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[0][0][1]],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[0][0][2]],
[0.0 ,0.0 ,0.0 ,1.0 ]])
Inverse_mat = np.array([[ 1.0, 1.0, 1.0, 1.0],
[-1.0,-1.0,-1.0,-1.0],
[-1.0,-1.0,-1.0,-1.0],
[ 1.0, 1.0, 1.0, 1.0]])
m1 = m1 * Inverse_mat
m1 = np.transpose(m1)


After loading the matrix m1 there is glutSolidCube() statement. The problem is that the cube is not in the viewable screen of openGL. I even scaled and shifted the tvec parameters of m1.



X = np.array([[1,0,0,x shift],
[0,1,0,y shift],
[0,0,1,z shift],
[0,0,0,1]])
Y = np.array([[tvec[0][0][0]],
[tvec[0][0][1]],
[tvec[0][0][2]],
[1]])
tvec = np.array([[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row in X])
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0]/scale x],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[1]/scale y],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[2]/scale z],
[0.0 ,0.0 ,0.0 ,1.0 ]])


This brings the cube over the marker but it is not aligned properly.



Moreover the values used for scaling and shifting is as per view on my screen and I want a general solution. What should I do?










share|improve this question






















  • Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
    – Paritosh Kulkarni
    Nov 23 at 15:40










  • Yes camera is well calibrated and the extrinsic values are pretty much correct.
    – mastersad
    Nov 25 at 5:09










  • I did not get the step you are building inverse matrix . Can you explain steps.
    – Paritosh Kulkarni
    Nov 25 at 22:40















up vote
0
down vote

favorite
3












I am trying to render a cube over a detect marker in openGL. I am doing it like this.



    rmtx = cv2.Rodrigues(rvec)[0]
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0][0][0]],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[0][0][1]],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[0][0][2]],
[0.0 ,0.0 ,0.0 ,1.0 ]])
Inverse_mat = np.array([[ 1.0, 1.0, 1.0, 1.0],
[-1.0,-1.0,-1.0,-1.0],
[-1.0,-1.0,-1.0,-1.0],
[ 1.0, 1.0, 1.0, 1.0]])
m1 = m1 * Inverse_mat
m1 = np.transpose(m1)


After loading the matrix m1 there is glutSolidCube() statement. The problem is that the cube is not in the viewable screen of openGL. I even scaled and shifted the tvec parameters of m1.



X = np.array([[1,0,0,x shift],
[0,1,0,y shift],
[0,0,1,z shift],
[0,0,0,1]])
Y = np.array([[tvec[0][0][0]],
[tvec[0][0][1]],
[tvec[0][0][2]],
[1]])
tvec = np.array([[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row in X])
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0]/scale x],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[1]/scale y],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[2]/scale z],
[0.0 ,0.0 ,0.0 ,1.0 ]])


This brings the cube over the marker but it is not aligned properly.



Moreover the values used for scaling and shifting is as per view on my screen and I want a general solution. What should I do?










share|improve this question






















  • Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
    – Paritosh Kulkarni
    Nov 23 at 15:40










  • Yes camera is well calibrated and the extrinsic values are pretty much correct.
    – mastersad
    Nov 25 at 5:09










  • I did not get the step you are building inverse matrix . Can you explain steps.
    – Paritosh Kulkarni
    Nov 25 at 22:40













up vote
0
down vote

favorite
3









up vote
0
down vote

favorite
3






3





I am trying to render a cube over a detect marker in openGL. I am doing it like this.



    rmtx = cv2.Rodrigues(rvec)[0]
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0][0][0]],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[0][0][1]],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[0][0][2]],
[0.0 ,0.0 ,0.0 ,1.0 ]])
Inverse_mat = np.array([[ 1.0, 1.0, 1.0, 1.0],
[-1.0,-1.0,-1.0,-1.0],
[-1.0,-1.0,-1.0,-1.0],
[ 1.0, 1.0, 1.0, 1.0]])
m1 = m1 * Inverse_mat
m1 = np.transpose(m1)


After loading the matrix m1 there is glutSolidCube() statement. The problem is that the cube is not in the viewable screen of openGL. I even scaled and shifted the tvec parameters of m1.



X = np.array([[1,0,0,x shift],
[0,1,0,y shift],
[0,0,1,z shift],
[0,0,0,1]])
Y = np.array([[tvec[0][0][0]],
[tvec[0][0][1]],
[tvec[0][0][2]],
[1]])
tvec = np.array([[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row in X])
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0]/scale x],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[1]/scale y],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[2]/scale z],
[0.0 ,0.0 ,0.0 ,1.0 ]])


This brings the cube over the marker but it is not aligned properly.



Moreover the values used for scaling and shifting is as per view on my screen and I want a general solution. What should I do?










share|improve this question













I am trying to render a cube over a detect marker in openGL. I am doing it like this.



    rmtx = cv2.Rodrigues(rvec)[0]
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0][0][0]],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[0][0][1]],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[0][0][2]],
[0.0 ,0.0 ,0.0 ,1.0 ]])
Inverse_mat = np.array([[ 1.0, 1.0, 1.0, 1.0],
[-1.0,-1.0,-1.0,-1.0],
[-1.0,-1.0,-1.0,-1.0],
[ 1.0, 1.0, 1.0, 1.0]])
m1 = m1 * Inverse_mat
m1 = np.transpose(m1)


After loading the matrix m1 there is glutSolidCube() statement. The problem is that the cube is not in the viewable screen of openGL. I even scaled and shifted the tvec parameters of m1.



X = np.array([[1,0,0,x shift],
[0,1,0,y shift],
[0,0,1,z shift],
[0,0,0,1]])
Y = np.array([[tvec[0][0][0]],
[tvec[0][0][1]],
[tvec[0][0][2]],
[1]])
tvec = np.array([[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row in X])
m1 = np.array([[rmtx[0][0],rmtx[0][1],rmtx[0][2],tvec[0]/scale x],
[rmtx[1][0],rmtx[1][1],rmtx[1][2],tvec[1]/scale y],
[rmtx[2][0],rmtx[2][1],rmtx[2][2],tvec[2]/scale z],
[0.0 ,0.0 ,0.0 ,1.0 ]])


This brings the cube over the marker but it is not aligned properly.



Moreover the values used for scaling and shifting is as per view on my screen and I want a general solution. What should I do?







python-3.x opengl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 7:54









mastersad

15




15












  • Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
    – Paritosh Kulkarni
    Nov 23 at 15:40










  • Yes camera is well calibrated and the extrinsic values are pretty much correct.
    – mastersad
    Nov 25 at 5:09










  • I did not get the step you are building inverse matrix . Can you explain steps.
    – Paritosh Kulkarni
    Nov 25 at 22:40


















  • Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
    – Paritosh Kulkarni
    Nov 23 at 15:40










  • Yes camera is well calibrated and the extrinsic values are pretty much correct.
    – mastersad
    Nov 25 at 5:09










  • I did not get the step you are building inverse matrix . Can you explain steps.
    – Paritosh Kulkarni
    Nov 25 at 22:40
















Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
– Paritosh Kulkarni
Nov 23 at 15:40




Have you properly calibrated your camera and got extrinsic values? That will form proper projection matrix for your rendering.
– Paritosh Kulkarni
Nov 23 at 15:40












Yes camera is well calibrated and the extrinsic values are pretty much correct.
– mastersad
Nov 25 at 5:09




Yes camera is well calibrated and the extrinsic values are pretty much correct.
– mastersad
Nov 25 at 5:09












I did not get the step you are building inverse matrix . Can you explain steps.
– Paritosh Kulkarni
Nov 25 at 22:40




I did not get the step you are building inverse matrix . Can you explain steps.
– Paritosh Kulkarni
Nov 25 at 22:40

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426198%2fhow-can-i-properly-align-cube-over-the-marker-in-opengl%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426198%2fhow-can-i-properly-align-cube-over-the-marker-in-opengl%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks