Changeset 4495 for trunk/MagicSoft/AMC
- Timestamp:
- 08/04/04 16:56:04 (20 years ago)
- Location:
- trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/videoframe.cpp
r4174 r4495 33 33 #include <qtimer.h> 34 34 #include <qimage.h> 35 36 #define HEADERSIZE 15 37 38 extern int g_iRefX, g_iRefY; 39 35 #include <kapp.h> 36 37 extern KApplication* g_theApp; 38 extern double g_dRefX, g_dRefY; 40 39 41 40 VideoFrame::VideoFrame( QWidget *parent, const char *name, AMCFrameGrabber* p_pFG ) … … 47 46 qDebug("Creating Image arrays"); 48 47 m_pImage = new QImage( MY_WIDTH, MY_HEIGHT, MY_DEPTH*8 ); 49 m_darkFrame = new QByteArray( BUFSIZE ); 48 m_pRawImage = new QImage( MY_WIDTH, MY_HEIGHT, MY_DEPTH*8 ); 49 m_pDarkFrame = new QByteArray( BUFSIZE ); 50 50 51 51 m_iFrame = 0; … … 55 55 56 56 m_ix = m_iy = -1; 57 m_ iRefX = m_iRefY = -1;58 m_ iCenterX = m_iCenterY = 1;57 m_dRefX = m_dRefY = -1.; 58 m_dCenterX = m_dCenterY = -1.; 59 59 m_pCalibDlg = 0; 60 // m_qlSpots.setAutoDelete( true ); 60 m_qlSpotList.setAutoDelete( true ); 61 m_qlSpots.setAutoDelete( true ); 61 62 62 63 qDebug("Creating VideoThread"); … … 64 65 m_pVideoThread->init( BUFSIZE ); 65 66 qDebug("Creating SpotThread"); 66 m_pSpotThread = new VideoSpotThread( this, m_pImage, (uchar*) m_darkFrame->data() ); 67 m_pSpotThread = new VideoSpotThread( this, m_pRawImage, (uchar*) m_pDarkFrame->data() ); 68 qDebug("Starting SpotThread"); 69 m_pSpotThread->start(); 67 70 qDebug("Starting VideoThread"); 68 qDebug("Thread for VideoFrame when starting VideoThread PID: %d - PPID: %d", getpid(), getppid() );69 71 m_pVideoThread->start(); 70 72 } … … 72 74 VideoFrame::~VideoFrame() 73 75 { 74 qDebug("Stoping video thread"); 75 m_pVideoThread->stop(); 76 m_pVideoThread->wait( ); 76 // Stop all runing threads 77 halt( true ); 77 78 qDebug("deleting video thread"); 78 79 delete m_pVideoThread; 79 qDebug("Stoping spot thread");80 m_pSpotThread->wait();81 80 qDebug("deleting spot thread"); 82 81 delete m_pSpotThread; 83 delete m_darkFrame; 82 83 qDebug("Deleting image and dark frame buffers"); 84 delete m_pDarkFrame; 84 85 delete m_pImage; 85 m_qlSpots.clear();86 delete m_pRawImage; 86 87 } 87 88 … … 95 96 96 97 // Overlay camera center if it was determined from the LEDs 97 if( m_ iCenterX > 1)98 if( m_dCenterX > 0 ) 98 99 { 99 100 windowPainter->setPen( Qt::white ); 100 windowPainter->drawEllipse( m_ iCenterX-2, m_iCenterY-2, 5, 5);101 windowPainter->drawEllipse( m_ iCenterX-4, m_iCenterY-4, 9, 9);101 windowPainter->drawEllipse( m_dCenterX-2., m_dCenterY-2., 5, 5); 102 windowPainter->drawEllipse( m_dCenterX-4., m_dCenterY-4., 9, 9); 102 103 } 103 104 … … 111 112 } 112 113 114 // Overlay Leds 115 windowPainter->setPen( Qt::yellow ); 116 for( VideoSpot* pActualSpot = m_qlLEDs.first(); 117 pActualSpot; pActualSpot = m_qlLEDs.next() ) 118 { 119 if( pActualSpot->isValid() ) 120 windowPainter->drawRect( pActualSpot->getX()-4, pActualSpot->getY()-4, 9, 9); 121 } 122 windowPainter->drawEllipse( LED1_X-4, LED1_Y-4, 9, 9); 123 windowPainter->drawEllipse( LED2_X-4, LED2_Y-4, 9, 9); 124 windowPainter->drawEllipse( LED3_X-4, LED3_Y-4, 9, 9); 125 windowPainter->drawEllipse( LED4_X-4, LED4_Y-4, 9, 9); 126 127 // Draw the calibration pointa and the regression fits. 113 128 if( m_pCalibDlg != 0 ) 114 129 { … … 127 142 if( pRegression->isValid() ) 128 143 { 129 iX1 = (int) (( 0. - pRegression->getAxis()) / pRegression->getSlope()); 130 iX2 = (int) (( 479. - pRegression->getAxis()) / pRegression->getSlope()); 131 windowPainter->drawLine( iX1, 0, iX2, 479 ); 144 if( ! pRegression->getReversed() ) { 145 iX1 = (int) (( 0. - pRegression->getAxis()) / pRegression->getSlope()); 146 iX2 = (int) (( 479. - pRegression->getAxis()) / pRegression->getSlope()); 147 windowPainter->drawLine( iX1, 0, iX2, 479 ); 148 } 149 else 150 { 151 iX1 = (int) pRegression->getAxis(); 152 iX2 = (int) ( pRegression->getAxis() + 479 * pRegression->getSlope() ); 153 windowPainter->drawLine( iX1, 0, iX2, 479 ); 154 } 132 155 } 133 156 … … 135 158 if( pRegression->isValid() ) 136 159 { 137 iX1 = (int) (( 0. - pRegression->getAxis() ) / pRegression->getSlope()); 138 iX2 = (int) (( 479. - pRegression->getAxis() ) / pRegression->getSlope()); 139 windowPainter->drawLine( iX1, 0, iX2, 479 ); 160 if( ! pRegression->getReversed() ) 161 { 162 iX1 = (int) (( 0. - pRegression->getAxis()) / pRegression->getSlope()); 163 iX2 = (int) (( 479. - pRegression->getAxis()) / pRegression->getSlope()); 164 windowPainter->drawLine( iX1, 0, iX2, 479 ); 165 } 166 else 167 { 168 iX1 = (int) pRegression->getAxis(); 169 iX2 = (int) ( pRegression->getAxis() + 479 * pRegression->getSlope() ); 170 windowPainter->drawLine( iX1, 0, iX2, 479 ); 171 // qDebug( "Drawing line: (%d,%d) - (%d,%d)", iX1, 0, iX2, 479 ); 172 } 140 173 } 141 174 … … 144 177 // Draw a blue cross for the global reference point 145 178 windowPainter->setPen( Qt::blue ); 146 windowPainter->drawLine( g_ iRefX-4, g_iRefY, g_iRefX+4, g_iRefY);147 windowPainter->drawLine( g_ iRefX, g_iRefY-4, g_iRefX, g_iRefY+4);179 windowPainter->drawLine( g_dRefX-4., g_dRefY, g_dRefX+4., g_dRefY); 180 windowPainter->drawLine( g_dRefX, g_dRefY-4., g_dRefX, g_dRefY+4.); 148 181 149 182 // Draw a green rectangle showing the reference point for this panel 150 if( m_ iRefX > 0)183 if( m_dRefX > 0) 151 184 { 152 185 windowPainter->setPen( Qt::green ); 153 if( m_ iCenterX > 1)186 if( m_dCenterX > 1.0 ) 154 187 { 155 188 // Adapt spot for shift of camera center. 156 int iDx, iDy;157 iDx = m_iCenterX - CAMERA_X;158 iDy = m_iCenterY - CAMERA_Y;159 windowPainter->drawRect( m_ iRefX+iDx-4, m_iRefY+iDy-4, 9, 9);189 double dDx, dDy; 190 dDx = m_dCenterX - CAMERA_X; 191 dDy = m_dCenterY - CAMERA_Y; 192 windowPainter->drawRect( m_dRefX+dDx-4., m_dRefY+dDy-4., 9., 9. ); 160 193 } else 161 windowPainter->drawRect( m_ iRefX-4, m_iRefY-4, 9, 9);194 windowPainter->drawRect( m_dRefX-4., m_dRefY-4., 9., 9. ); 162 195 } 163 196 … … 194 227 if( pActualSpot->isValid() ) 195 228 { 196 str.sprintf("% d %d\n", pActualSpot->getX(), pActualSpot->getY() );229 str.sprintf("%6.2f %6.2f %d\n", pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel() ); 197 230 stream << str; 198 231 } … … 206 239 if( pActualSpot->isValid() ) 207 240 { 208 str.sprintf("% d %d\n", pActualSpot->getX(), pActualSpot->getY() );241 str.sprintf("%6.2f %6.2f %d\n", pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel() ); 209 242 stream << str; 210 243 } … … 220 253 uchar* pFrame = m_pImage->bits(); 221 254 m_pVideoThread->getLastFrame( pFrame ); 222 uchar* pDark = m_ darkFrame->data();255 uchar* pDark = m_pDarkFrame->data(); 223 256 224 257 for(int ind=0; ind< (MY_HEIGHT * MY_WIDTH * MY_DEPTH); ind++, pDark++, pFrame++ ) … … 234 267 void VideoFrame::clearDarks() 235 268 { 236 m_ darkFrame->fill(0);269 m_pDarkFrame->fill(0); 237 270 m_iDarks = 0; 238 271 } … … 299 332 if( event->button() == RightButton ) 300 333 { 301 g_ iRefX = event->x();302 g_ iRefY = event->y();303 emit gref( g_ iRefX, g_iRefY );334 g_dRefX = event->x(); 335 g_dRefY = event->y(); 336 emit gref( g_dRefX, g_dRefY ); 304 337 } 305 338 } … … 307 340 void VideoFrame::customEvent(QCustomEvent *e) 308 341 { 309 if ( e->type() == THREAD_END_EVENT ) 310 { 342 if ( e->type() == THREAD_SPOT_EVENT ) 343 { 344 g_theApp->processEvents(); 345 m_pSpotThread->getSpotList( &m_qlSpotList ); 346 m_pSpotThread->getFrame( m_pImage->bits() ); 347 m_iGoodFrame++; 311 348 repaint( FALSE ); 349 312 350 calcCenter(); 313 351 if( m_qlSpots.count() == 1) … … 318 356 else 319 357 emit spot( -1, -1 ); 358 g_theApp->processEvents(); 359 320 360 } 321 361 if ( e->type() == THREAD_FRAME_EVENT ) 322 362 { 323 363 m_iFrame++; 324 if( ! m_pSpotThread-> running() )325 { 326 m_ iGoodFrame++;327 m_p VideoThread->getLastFrame( m_pImage->bits());328 m_pSpotThread->start();329 } 330 // else331 // qDebug("Dropping Frame");364 if( ! m_pSpotThread->isActive() ) 365 { 366 m_pVideoThread->getLastFrame( m_pRawImage->bits() ); 367 m_pSpotThread->wake(); 368 } 369 //else 370 // qDebug("Dropping Frame"); 371 g_theApp->processEvents(); 332 372 } 333 373 } … … 349 389 if ( p_zStop == true ) 350 390 { 391 qDebug("Stoping video thread"); 351 392 m_pVideoThread->stop(); 352 393 m_pVideoThread->wait(); // Wait for video thread to finish 394 qDebug("Stoping videospot thread"); 395 m_pSpotThread->stop(); 396 m_pSpotThread->wake(); 353 397 m_pSpotThread->wait(); // Wait for spot thread to finish 354 398 } 355 399 else 400 { 401 qDebug("Starting video thread"); 402 m_pSpotThread->start(); 403 qDebug("Starting videospot thread"); 356 404 m_pVideoThread->start(); 405 } 357 406 } 358 407 … … 365 414 int iNumLEDs = 0; 366 415 367 m_ iCenterX = m_iCenterY = 1;416 m_dCenterX = m_dCenterY = -1.; 368 417 m_qlLEDs.clear(); 369 418 m_qlSpots.clear(); 370 419 371 QList<VideoSpot>& qlSpotList = m_pSpotThread->getSpotList(); 372 for( VideoSpot* pActualSpot = qlSpotList.first(); 373 pActualSpot; pActualSpot = qlSpotList.next() ) 420 for( VideoSpot* pActualSpot = m_qlSpotList.first(); 421 pActualSpot; pActualSpot = m_qlSpotList.next() ) 374 422 { 375 423 // Check if this spot is compatible with the spot of the … … 380 428 dY1 = pActualSpot->getY() + (CAMERA_Y - LED1_Y); 381 429 dX += dX1; dY += dY1; 382 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY() ) );430 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel()) ); 383 431 iNumLEDs++; 384 432 } … … 390 438 dY2 = pActualSpot->getY() + (CAMERA_Y - LED2_Y); 391 439 dX += dX2; dY += dY2; 392 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY() ) );440 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel()) ); 393 441 iNumLEDs++; 394 442 } … … 400 448 dY3 = pActualSpot->getY() + (CAMERA_Y - LED3_Y); 401 449 dX += dX3; dY += dY3; 402 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY() ) );450 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel()) ); 403 451 iNumLEDs++; 404 452 } … … 410 458 dY4 = pActualSpot->getY() + (CAMERA_Y - LED4_Y); 411 459 dX += dX4; dY += dY4; 412 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY() ) );460 m_qlLEDs.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel()) ); 413 461 iNumLEDs++; 414 462 } 415 463 else 416 m_qlSpots.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY() ) );464 m_qlSpots.append( new VideoSpot( pActualSpot->getX(), pActualSpot->getY(), pActualSpot->getNumPixel()) ); 417 465 } 418 466 if( iNumLEDs != 0) 419 467 { 420 m_ iCenterX = (int) rint(dX / iNumLEDs);421 m_ iCenterY = (int) rint(dY / iNumLEDs);468 m_dCenterX = dX / iNumLEDs; 469 m_dCenterY = dY / iNumLEDs; 422 470 // qDebug("Center %d %d", m_iCenterX, m_iCenterY); 423 471 } 424 qDebug("Center at: %d %d -- with %d LEDs",m_iCenterX, m_iCenterY, iNumLEDs );425 } 472 // qDebug("Center at: %5.1f %5.1f -- with %d LEDs",m_dCenterX, m_dCenterY, iNumLEDs ); 473 } -
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/videoframe.h
r3401 r4495 50 50 void saveFrame(); 51 51 /** Set the reference position */ 52 void setRef( int p_iX, int p_iY ) { m_iRefX = p_iX; m_iRefY = p_iY; };52 void setRef( double p_dX, double p_dY ) { m_dRefX = p_dX; m_dRefY = p_dY; }; 53 53 /** Set list of spots used to calibrate panel movement */ 54 54 void setCalibDlg( CalibratePanelDialog* p_pDlg ) { m_pCalibDlg = p_pDlg; }; … … 72 72 QImage* m_pImage; 73 73 /** */ 74 QByteArray* m_darkFrame; 74 QImage* m_pRawImage; 75 /** */ 76 QByteArray* m_pDarkFrame; 75 77 /** */ 76 78 CalibratePanelDialog* m_pCalibDlg; … … 85 87 /** */ 86 88 QPoint m_qpRef; 89 /** List of spots found in frame. */ 90 QList<VideoSpot> m_qlSpotList; 87 91 /** List of spots found in frame. In this list the spots from the camera LEDs are removed */ 88 92 QList<VideoSpot> m_qlSpots; … … 96 100 int m_iy; 97 101 /** */ 98 int m_iRefX;102 double m_dRefX; 99 103 /** */ 100 int m_iRefY;104 double m_dRefY; 101 105 /** */ 102 int m_iCenterX;106 double m_dCenterX; 103 107 /** */ 104 int m_iCenterY;108 double m_dCenterY; 105 109 /** */ 106 110 int m_iFrame; … … 130 134 signals: // Signals 131 135 /** Signal emitted when we find a spot. */ 132 void spot( int p_iX, int p_iY );136 void spot( double p_dX, double p_dY ); 133 137 /** Signal emitted when we set a global reference. */ 134 void gref( int p_iX, int p_iY );138 void gref( double p_dX, double p_dY ); 135 139 /** Signal emitted whit the number of grabbed frames per second. */ 136 140 void framesGrabbed( int p_iFrames );
Note:
See TracChangeset
for help on using the changeset viewer.