@ -4,7 +4,7 @@
# include <iostream>
# include <vector>
# include <opencv/highgui.h>
# include <opencv2/highgui /highgui.hpp >
# if defined WIN32 || defined _WIN32 || defined WINCE
# include <windows.h>
@ -20,8 +20,7 @@
# include <GL/gl.h>
# endif
# include <opencv/cxcore.h>
# include <opencv/cv.h>
# include <opencv2/core/core.hpp>
using namespace std ;
using namespace cv ;
@ -111,12 +110,12 @@ static void initPOSIT(std::vector<CvPoint3D32f> *modelPoints)
modelPoints - > push_back ( cvPoint3D32f ( 0.0f , CUBE_SIZE , 0.0f ) ) ;
}
static void foundCorners ( vector < CvPoint2D32f > * srcImagePoints , IplImage * source , IplImage * grayImage )
static void foundCorners ( vector < CvPoint2D32f > * srcImagePoints , const Mat & source , Mat & grayImage )
{
cvCv tColor ( source , grayImage , CV _RGB2GRAY) ;
cvSmooth ( grayImage , grayImage , CV_GAUSSIAN , 11 ) ;
cvN ormalize( grayImage , grayImage , 0 , 255 , CV _MINMAX) ;
cvThreshold ( grayImage , grayImage , 26 , 255 , CV_ THRESH_BINARY_INV) ; //25
cvtColor ( source , grayImage , COLOR _RGB2GRAY ) ;
GaussianBlur ( grayImage , grayImage , Size ( 11 , 11 ) , 0 , 0 ) ;
n ormalize( grayImage , grayImage , 0 , 255 , NORM _MINMAX) ;
threshold ( grayImage , grayImage , 26 , 255 , THRESH_BINARY_INV ) ; //25
Mat MgrayImage = grayImage ;
//For debug
@ -189,8 +188,8 @@ static void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source,
for ( size_t i = 0 ; i < srcImagePoints_temp . size ( ) ; i + + )
{
ss < < i ;
circle ( Msource , srcImagePoints - > at ( i ) , 5 , CV_RGB ( 255 , 0 , 0 ) ) ;
putText ( Msource , ss . str ( ) , srcImagePoints - > at ( i ) , CV_ FONT_HERSHEY_SIMPLEX, 1 , CV_RGB ( 255 , 0 , 0 ) ) ;
circle ( Msource , srcImagePoints - > at ( i ) , 5 , Scalar ( 0 , 0 , 255 ) ) ;
putText ( Msource , ss . str ( ) , srcImagePoints - > at ( i ) , FONT_HERSHEY_SIMPLEX , 1 , Scalar ( 0 , 0 , 255 ) ) ;
ss . str ( " " ) ;
//new coordinate system in the middle of the frame and reversed (camera coordinate system)
@ -224,19 +223,19 @@ static void createOpenGLMatrixFrom(float *posePOSIT,const CvMatr32f &rotationMat
int main ( void )
{
help ( ) ;
CvCapture * video = cvCaptureFromFile ( " cube4.avi " ) ;
CV_Assert ( video ) ;
VideoCapture video ( " cube4.avi " ) ;
CV_Assert ( video . isOpened ( ) ) ;
IplImage * source = cvCreateImage ( cvGetSize ( cvQueryFrame ( video ) ) , 8 , 3 ) ;
IplImage * grayImage = cvCreateImage ( cvGetSize ( cvQueryFrame ( video ) ) , 8 , 1 ) ;
Mat source , grayImage ;
cvNamedWindow ( " original " , CV_WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO ) ;
cvNamedWindow ( " POSIT " , CV_WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO ) ;
video > > source ;
namedWindow ( " original " , WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO ) ;
namedWindow ( " POSIT " , WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO ) ;
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 ) ;
//For debug
//cvNamedWindow("tempGray",CV_WINDOW_AUTOSIZE);
float OpenGLMatrix [ ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
cvS etOpenGlDrawCallback( " POSIT " , on_opengl , OpenGLMatrix ) ;
s etOpenGlDrawCallback( " POSIT " , on_opengl , OpenGLMatrix ) ;
vector < CvPoint3D32f > modelPoints ;
initPOSIT ( & modelPoints ) ;
@ -251,26 +250,22 @@ int main(void)
vector < CvPoint2D32f > srcImagePoints ( 4 , cvPoint2D32f ( 0 , 0 ) ) ;
while ( cvW aitKey( 33 ) ! = 27 )
while ( w aitKey( 33 ) ! = 27 )
{
source = cvQueryFrame ( video ) ;
cvShowImage ( " original " , source ) ;
video > > 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 ) ;
cvShowImage ( " POSIT " , source ) ;
//For debug
//cvShowImage("tempGray",grayImage);
imshow ( " POSIT " , source ) ;
if ( cvGetCaptureProperty ( video , CV_CAP_PROP_POS_AVI_RATIO ) > 0.99 )
cvSetCaptureProperty ( video , CV_CAP_PROP_POS_AVI_RATIO , 0 ) ;
if ( VideoCapture : : get ( video , CV_CAP_PROP_POS_AVI_RATIO ) > 0.99 )
VideoCapture : : get ( video , CV_CAP_PROP_POS_AVI_RATIO , 0 ) ;
}
cvDestroyAllWindows ( ) ;
cvReleaseImage ( & grayImage ) ;
cvReleaseCapture ( & video ) ;
destroyAllWindows ( ) ;
cvReleasePOSITObject ( & positObject ) ;
return 0 ;