some more fixes
This commit is contained in:
parent
879c0196d4
commit
b92a46c130
@ -1,5 +1,4 @@
|
||||
// Yannick Verdie 2010
|
||||
|
||||
// --- Please read help() below: ---
|
||||
|
||||
#include <iostream>
|
||||
@ -11,14 +10,6 @@
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/legacy/compat.hpp>
|
||||
|
||||
#if defined WIN32 || defined _WIN32 || defined WINCE
|
||||
#include <windows.h>
|
||||
#undef small
|
||||
#undef min
|
||||
#undef max
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
@ -30,21 +21,22 @@ using namespace cv;
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "\nThis demo demonstrates the use of the Qt enhanced version of the highgui GUI interface\n"
|
||||
cout << "This demo demonstrates the use of the Qt enhanced version of the highgui GUI interface\n"
|
||||
"and dang if it doesn't throw in the use of of the POSIT 3D tracking algorithm too\n"
|
||||
"It works off of the video: cube4.avi\n"
|
||||
"Using OpenCV version " << CV_VERSION << "\n\n"
|
||||
" 1). This demo is mainly based on work from Javier Barandiaran Martirena\n"
|
||||
|
||||
" 1) This demo is mainly based on work from Javier Barandiaran Martirena\n"
|
||||
" See this page http://code.opencv.org/projects/opencv/wiki/Posit.\n"
|
||||
" 2). This is a demo to illustrate how to use **OpenGL Callback**.\n"
|
||||
" 3). You need Qt binding to compile this sample with OpenGL support enabled.\n"
|
||||
" 4). The features' detection is very basic and could highly be improved \n"
|
||||
" 2) This is a demo to illustrate how to use **OpenGL Callback**.\n"
|
||||
" 3) You need Qt binding to compile this sample with OpenGL support enabled.\n"
|
||||
" 4) The features' detection is very basic and could highly be improved\n"
|
||||
" (basic thresholding tuned for the specific video) but 2).\n"
|
||||
" 5) THANKS TO Google Summer of Code 2010 for supporting this work!\n" << endl;
|
||||
" 5) Thanks to Google Summer of Code 2010 for supporting this work!\n" << endl;
|
||||
}
|
||||
|
||||
#define FOCAL_LENGTH 600
|
||||
#define CUBE_SIZE 10
|
||||
#define CUBE_SIZE 0.5
|
||||
|
||||
static void renderCube(float size)
|
||||
{
|
||||
@ -129,10 +121,8 @@ static void foundCorners(vector<CvPoint2D32f> *srcImagePoints, const Mat& source
|
||||
|
||||
if (contours.size() == srcImagePoints_temp.size())
|
||||
{
|
||||
|
||||
for (size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
|
||||
p.x = p.y = 0;
|
||||
|
||||
for (size_t j = 0 ; j < contours[i].size(); j++)
|
||||
@ -150,37 +140,29 @@ static void foundCorners(vector<CvPoint2D32f> *srcImagePoints, const Mat& source
|
||||
// get point 0;
|
||||
size_t index = 0;
|
||||
for (size_t i = 1 ; i<srcImagePoints_temp.size(); i++)
|
||||
{
|
||||
if (srcImagePoints_temp.at(i).y > srcImagePoints_temp.at(index).y)
|
||||
index = i;
|
||||
}
|
||||
srcImagePoints->at(0) = srcImagePoints_temp.at(index);
|
||||
|
||||
// get point 1;
|
||||
index = 0;
|
||||
for (size_t i = 1 ; i<srcImagePoints_temp.size(); i++)
|
||||
{
|
||||
if (srcImagePoints_temp.at(i).x > srcImagePoints_temp.at(index).x)
|
||||
index = i;
|
||||
}
|
||||
srcImagePoints->at(1) = srcImagePoints_temp.at(index);
|
||||
|
||||
// get point 2;
|
||||
index = 0;
|
||||
for (size_t i = 1 ; i<srcImagePoints_temp.size(); i++)
|
||||
{
|
||||
if (srcImagePoints_temp.at(i).x < srcImagePoints_temp.at(index).x)
|
||||
index = i;
|
||||
}
|
||||
srcImagePoints->at(2) = srcImagePoints_temp.at(index);
|
||||
|
||||
// get point 3;
|
||||
index = 0;
|
||||
for (size_t i = 1 ; i<srcImagePoints_temp.size(); i++ )
|
||||
{
|
||||
if (srcImagePoints_temp.at(i).y < srcImagePoints_temp.at(index).y)
|
||||
index = i;
|
||||
}
|
||||
srcImagePoints->at(3) = srcImagePoints_temp.at(index);
|
||||
|
||||
Mat Msource = source;
|
||||
@ -193,25 +175,27 @@ static void foundCorners(vector<CvPoint2D32f> *srcImagePoints, const Mat& source
|
||||
ss.str("");
|
||||
|
||||
// new coordinate system in the middle of the frame and reversed (camera coordinate system)
|
||||
srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x-source.cols/2,source.rows/2-srcImagePoints_temp.at(i).y);
|
||||
srcImagePoints->at(i) = cvPoint2D32f(srcImagePoints_temp.at(i).x - source.cols / 2,
|
||||
source.rows / 2 - srcImagePoints_temp.at(i).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void createOpenGLMatrixFrom(float *posePOSIT,const CvMatr32f &rotationMatrix, const CvVect32f &translationVector)
|
||||
static void createOpenGLMatrixFrom(float * posePOSIT, const CvMatr32f & rotationMatrix,
|
||||
const CvVect32f & translationVector)
|
||||
{
|
||||
// coordinate system returned is relative to the first 3D input point
|
||||
for (int f = 0; f < 3; f++)
|
||||
for (int c = 0; c < 3; c++)
|
||||
posePOSIT[c * 4 + f] = rotationMatrix[f * 3 + c]; // transposed
|
||||
|
||||
posePOSIT[3] = 0.0;
|
||||
posePOSIT[7] = 0.0;
|
||||
posePOSIT[11] = 0.0;
|
||||
posePOSIT[12] = translationVector[0];
|
||||
posePOSIT[13] = translationVector[1];
|
||||
posePOSIT[14] = translationVector[2];
|
||||
posePOSIT[15] = 1.0;
|
||||
posePOSIT[3] = translationVector[0];
|
||||
posePOSIT[7] = translationVector[1];
|
||||
posePOSIT[11] = translationVector[2];
|
||||
posePOSIT[12] = 0.0f;
|
||||
posePOSIT[13] = 0.0f;
|
||||
posePOSIT[14] = 0.0f;
|
||||
posePOSIT[15] = 1.0f;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -229,14 +213,19 @@ int main(void)
|
||||
Mat source, grayImage;
|
||||
video >> source;
|
||||
|
||||
namedWindow("original", WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO);
|
||||
namedWindow("Original", WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO);
|
||||
namedWindow("POSIT", WINDOW_OPENGL | CV_WINDOW_FREERATIO);
|
||||
resizeWindow("POSIT", source.cols, source.rows);
|
||||
|
||||
displayOverlay("POSIT", "We lost the 4 corners' detection quite often (the red circles disappear)."
|
||||
"This demo is only to illustrate how to use OpenGL callback.\n -- Press ESC to exit.", 10000);
|
||||
displayOverlay("POSIT", "We lost the 4 corners' detection quite often (the red circles disappear).\n"
|
||||
"This demo is only to illustrate how to use OpenGL callback.\n"
|
||||
" -- Press ESC to exit.", 10000);
|
||||
|
||||
float OpenGLMatrix[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
float OpenGLMatrix[] = { 0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0 };
|
||||
setOpenGlContext("POSIT");
|
||||
setOpenGlDrawCallback("POSIT", on_opengl, OpenGLMatrix);
|
||||
|
||||
vector<CvPoint3D32f> modelPoints;
|
||||
@ -256,21 +245,24 @@ int main(void)
|
||||
if (source.empty())
|
||||
break;
|
||||
|
||||
imshow("original", source);
|
||||
imshow("Original", source);
|
||||
|
||||
foundCorners(&srcImagePoints, source, grayImage);
|
||||
cvPOSIT(positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector);
|
||||
createOpenGLMatrixFrom(OpenGLMatrix, rotation_matrix, translation_vector);
|
||||
|
||||
imshow("POSIT",source);
|
||||
updateWindow("POSIT");
|
||||
|
||||
if (video.get(CV_CAP_PROP_POS_AVI_RATIO) > 0.99)
|
||||
video.set(CV_CAP_PROP_POS_AVI_RATIO, 0);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback("POSIT", 0, 0);
|
||||
setOpenGlDrawCallback("POSIT", NULL, NULL);
|
||||
destroyAllWindows();
|
||||
cvReleasePOSITObject(&positObject);
|
||||
|
||||
return 0;
|
||||
delete[]rotation_matrix;
|
||||
delete[]translation_vector;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user