00001 /* 00002 * main.cc 00003 * 00004 * Created on: Feb 18, 2010 00005 * Author: uscr 00006 */ 00007 00008 #include <opencv/highgui.h> 00009 #include <opencv/cv.h> 00010 #include <iostream> 00011 #include <pthread.h> 00012 #include <cstdio> 00013 00014 #include "TestrigGUI.h" 00015 #include "DataThreads.h" 00016 00017 extern int serialCon; 00018 extern IplImage * frame; 00019 extern CvCapture * camera; 00020 extern TestrigGUI * myGui; 00021 00022 int main (int argc, char *argv[]) { 00023 00024 //camera = cvCreateCameraCapture(0); 00025 IplImage * gray, * fakeGray; 00026 00027 //Get the font stuffs: 00028 CvFont defaultFont; 00029 cvInitFont (&defaultFont, CV_FONT_HERSHEY_DUPLEX, 0.75, 0.75); 00030 //cvNamedWindow("BeoHawk Testrig - Calibrate Test-Rig", CV_WINDOW_AUTOSIZE ); 00031 00032 //frame = cvQueryFrame (camera); 00033 //gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1); 00034 //fakeGray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 00035 //printf ("Input Camera Image is %dx%d\n", frame->width, frame->height); 00036 /* 00037 //==============================================// 00038 // STEP 1: Center the camera on the thingy // 00039 //==============================================// 00040 00041 while (cvGetWindowHandle("BeoHawk Testrig - Calibrate Test-Rig")) { 00042 frame = cvQueryFrame (camera); 00043 cvCvtColor (frame, gray, CV_RGB2GRAY); 00044 cvCvtColor (gray, fakeGray, CV_GRAY2RGB); 00045 00046 if (!gray) return 1; 00047 00048 cvLine (fakeGray, cvPoint(fakeGray->width/2,0), 00049 cvPoint(fakeGray->width/2, fakeGray->height), CV_RGB(255, 0, 0), 2); 00050 cvLine (fakeGray, cvPoint(0,fakeGray->height/2), 00051 cvPoint(fakeGray->width, fakeGray->height/2), CV_RGB(255, 0, 0), 2); 00052 00053 cvPutText(fakeGray, "Center the test rig in this image,", 00054 cvPoint(50, 30), &defaultFont, CV_RGB(255, 255, 117)); 00055 cvPutText(fakeGray, "and then close this window.", 00056 cvPoint(50, 60), &defaultFont, CV_RGB(255, 255, 117)); 00057 00058 cvShowImage("BeoHawk Testrig - Calibrate Test-Rig", fakeGray); 00059 char c = cvWaitKey(10); 00060 if( c == 27 ) break; 00061 } 00062 00063 cvDestroyAllWindows(); 00064 usleep(30000); 00065 */ 00066 //=========================================// 00067 // STEP 2: Run the GUI, IMU, AR stuffs // 00068 //=========================================// 00069 QApplication gui(argc, argv); 00070 TestrigGUI trg; 00071 myGui = &trg; 00072 trg.show(); 00073 gui.connect(&gui, SIGNAL(lastWindowClosed()), &gui, SLOT(quit())); 00074 00075 //do run threads here 00076 pthread_t imuThread, camThread, guiThread; 00077 pthread_attr_t attr; 00078 void * status; 00079 pthread_attr_init(&attr); 00080 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); 00081 00082 //start em up 00083 initializeDataThreads(); 00084 pthread_create(&imuThread, &attr, runIMUThread, NULL); 00085 pthread_create(&camThread, &attr, runCamThread, NULL); 00086 pthread_create(&guiThread, &attr, runGuiThread, NULL); 00087 00088 gui.exec(); 00089 00090 //do join here 00091 shutdownDataThreads(); 00092 pthread_attr_destroy(&attr); 00093 pthread_join(imuThread, &status); 00094 pthread_join(camThread, &status); 00095 pthread_join(guiThread, &status); 00096 00097 //cvReleaseImage(&gray); 00098 //cvReleaseImage(&fakeGray); 00099 //cvReleaseCapture(&camera); 00100 00101 return 0; 00102 }