00001 /******************************************************************************* 00002 * ImageGrabber.cpp 00003 * 00004 * (C) 2006 AG Aktives Sehen <agas@uni-koblenz.de> 00005 * Universitaet Koblenz-Landau 00006 ******************************************************************************/ 00007 00008 #include <limits.h> 00009 #include "ImageGrabber.h" 00010 00011 #include "../../Workers/Puma2/Y8UV8ToRGB8Operator.h" 00012 #include "Workers/Math/Math.h" 00013 00014 #include <sstream> 00015 #include <exception> 00016 #include "math.h" 00017 #include "stdlib.h" 00018 00019 //#include "GrabbingDeviceManager.h" 00020 #include "../../Workers/Puma2/PumaException.h" 00021 00022 #define THIS ImageGrabber 00023 00024 using namespace std; 00025 using namespace puma2; 00026 00027 THIS::THIS ( string parentName ) 00028 { 00029 // m_ColorFormatId["RGB8"] = RGB8; 00030 // m_ColorFormatId["UYVY"] = UYVY8; 00031 // m_GrabDataTimer = Timer ( ProfilerEntry::CODE_SEGMENT, parentName, "Grab raw data" ); 00032 // m_GrabImageTimer = Timer ( ProfilerEntry::CODE_SEGMENT, parentName, "Grab RGB image" ); 00033 // m_ScaleYuvDataTimer = Timer ( ProfilerEntry::CODE_SEGMENT, parentName, "YUV422 -> YUV444" ); 00034 // m_YuvToRgbTimer = Timer ( ProfilerEntry::CODE_SEGMENT, parentName, "YUV444 -> RGB" ); 00035 00036 // GrabbingDeviceManager* myManager = GrabbingDeviceManager:: getGrabbingDeviceManager(); 00037 // myManager->scan(); 00038 //TRACE_SYSTEMINFO( "Connected cameras:\n" + myManager->getDeviceList() ) 00039 } 00040 00041 THIS::~THIS() 00042 { 00043 00044 // map<ImageSources::SourceId, GrabbingDevice*>::iterator it; 00045 00046 // //delete devices 00047 // for ( it = m_GrabbingDevices.begin() ; it != m_GrabbingDevices.end(); it++ ) 00048 // { 00049 // stopCamera ( it->first ); 00050 // //NOTE we should delete the grabbing devices here, but this causes the GrabbingDevices to crash for some reasons (possible puma2 bug) 00051 // delete it->second; 00052 // } 00053 00054 } 00055 00056 //bool THIS::setCamera ( ImageSources::SourceId sourceId, Camera cam ) 00057 //{ 00058 // m_Cameras[sourceId] = cam; 00059 // m_Initialized[sourceId] = false; 00060 // return initCamera ( sourceId ); 00061 //} 00062 00063 //bool THIS::stopCamera ( ImageSources::SourceId sourceId ) 00064 //{ 00065 00072 00074 00089 00091 // return true; 00092 //} 00093 00094 00095 00096 //bool THIS::setCameraProperty ( ImageSources::SourceId sourceId, string param, double value, bool isAbsolute ) 00097 //{ 00104 00109 00111 00112 // return true; 00113 //} 00114 00115 00116 //double THIS::getCameraProperty ( ImageSources::SourceId sourceId, string param ) 00117 //{ 00125 00127 00128 // return _property->value; 00129 //} 00130 00131 00132 //void THIS::cleanBuffers() 00133 //{ 00134 // map<ImageSources::SourceId, GrabbingDevice*>::iterator it; 00135 // for ( it = m_GrabbingDevices.begin() ; it != m_GrabbingDevices.end(); it++ ) 00136 // { 00137 // it->second->cleanBuffers(); 00138 // } 00139 //} 00140 00141 00142 //bool THIS::initCamera ( ImageSources::SourceId sourceId ) 00143 //{ 00144 // ostringstream stream; 00145 00146 // stopCamera ( sourceId ); 00147 00148 // stream << "Initializing camera '" << sourceId << "'."; 00149 // stream << "\nDescription: '" << m_Cameras[sourceId].getDeviceDescription() << "'"; 00150 // stream << "\nFormat: " << m_Cameras[sourceId].getFormatId() << "." << m_Cameras[sourceId].getSubFormatId(); 00151 // //stream << "\nCustom properties: '" << m_Cameras[sourceId].getCustomProperties() << "'"; 00152 00153 // stream.str ( "" ); 00154 00155 // //if it has been initialized before, use existing grabbing device 00156 // if ( m_GrabbingDevices.find ( sourceId ) != m_GrabbingDevices.end() ) 00157 // { 00158 00159 // } 00160 // else 00161 // { 00162 // // get instance of GrabbingDeviceManager and scan for new devices 00163 // GrabbingDeviceManager* myManager = GrabbingDeviceManager:: getGrabbingDeviceManager(); 00164 // myManager->scan(); 00165 00166 // //connect to grabbing device (which is identified by a 'device description' string) 00167 // GrabbingDevice *grabbingDevice; 00168 // try 00169 // { 00170 // myManager->connectGrabbingDevice ( &grabbingDevice, m_Cameras[sourceId].getDeviceDescription() ); 00171 // m_GrabbingDevices[sourceId] = grabbingDevice; 00172 // } 00173 // catch ( PumaException pumaException ) 00174 // { 00175 // stream << "connectGrabbingDevice() has thrown exception: " << pumaException.description(); 00176 00177 // stream.str ( "" ); 00178 // return false; 00179 // } 00180 00181 // } 00182 00183 // m_Initialized[sourceId] = true; 00184 00185 00186 00187 // //set image format 00188 // try 00189 // { 00190 // m_GrabbingDevices[sourceId]->setFormat ( m_Cameras[sourceId].getFormatId(), m_Cameras[sourceId].getSubFormatId() ); 00191 // } 00192 // catch ( PumaException pumaException ) 00193 // { 00194 // stream << "setFormat() has thrown exception: " << pumaException.description(); 00195 00196 // stream.str ( "" ); 00197 // return false; 00198 // } 00199 00200 // stream << "Selected format: " << m_Cameras[sourceId].getFormatId() << "." << m_Cameras[sourceId].getSubFormatId(); 00201 // stream << " (" << m_GrabbingDevices[sourceId]->getFrameWidth() << "x" << m_GrabbingDevices[sourceId]->getFrameHeight(); 00202 // stream << ", " << m_GrabbingDevices[sourceId]->getFormatDesc() << ")"; 00203 00204 // stream.str(""); 00205 00206 // //set number of buffers 00207 // try 00208 // { 00209 // m_GrabbingDevices[sourceId]->setNumBuffers ( 2 ); 00210 // } 00211 // catch ( PumaException pumaException ) 00212 // { 00213 // stream << "setNumBuffers() has thrown exception: " << pumaException.description(); 00214 00215 // stream.str ( "" ); 00216 // return false; 00217 // } 00218 00219 00220 00221 // //set custom properties 00222 // std::map<string, double> properties = m_Cameras[sourceId].getCustomProperties(); 00223 // std::map<string, double>::iterator propIt; 00224 // for ( propIt = properties.begin(); propIt != properties.end(); propIt++ ) 00225 // { 00226 // try 00227 // { 00228 // stream.str ( "" ); 00229 // stream << "Setting property " << propIt->first << " = " << propIt->second; 00230 00231 // m_GrabbingDevices[sourceId]->setProperty ( propIt->first , propIt->second, false ); 00232 // } 00233 // catch ( PumaException pumaException ) 00234 // { 00235 // stream << "setProperty(" << propIt->first << propIt->second << ") has thrown exception: " << pumaException.description(); 00236 00237 // stream.str ( "" ); 00238 // //return false; 00239 // } 00240 // } 00241 00242 // // start capture process 00243 // try 00244 // { 00245 // m_GrabbingDevices[sourceId]->startCapture(); 00246 // } 00247 // catch ( PumaException pumaException ) 00248 // { 00249 // stream << "startCapture() has thrown exception: " << pumaException.description(); 00250 00251 // stream.str ( "" ); 00252 // return false; 00253 // } 00254 00255 // usleep ( 50000 ); 00256 00257 // return true; 00258 //} 00259 00260 00261 //bool THIS::checkCamera ( ImageSources::SourceId sourceId ) 00262 //{ 00263 // ostringstream stream; 00264 // if ( m_Cameras.find ( sourceId ) == m_Cameras.end() ) 00265 // { 00266 // stream << "Camera " << ( int ) sourceId << " does not exist!"; 00268 00269 // return false; 00270 // } 00271 // if ( !m_Initialized[sourceId] ) 00272 // { 00273 // stream << "Camera " << ( int ) sourceId << " not initialized!"; 00274 00275 // return false; 00276 // } 00277 // return true; 00278 //} 00279 00280 00281 //bool THIS::grabImageRgb ( ImageSources::SourceId sourceId, ScaleFactor scaling, ImageQuality quality, ColorImageRGB8 &image ) 00282 //{ 00283 // ostringstream stream; 00284 // bool grabSuccess = false; 00285 00286 // if ( !checkCamera ( sourceId ) ) { return false; }; 00287 00288 // stream << "Grabbing RGB camera image " << sourceId << " (" << m_Cameras[sourceId].getDeviceDescription() << ")"; 00289 00290 // stream.str ( "" ); 00291 00292 00293 00294 // ColorImageRGB8 tmpImage; 00295 00296 // switch ( scaling ) 00297 // { 00298 // case FULL: 00299 // grabSuccess = m_GrabbingDevices[sourceId]->grabImage ( tmpImage ); 00300 // break; 00301 00302 // case HALF: 00303 // { 00304 // ColorImageRGB8* fullImage = new ColorImageRGB8(); 00305 // grabSuccess = m_GrabbingDevices[sourceId]->grabImage ( *fullImage ); 00306 00307 // tmpImage.resize( fullImage->getWidth()/2, fullImage->getHeight()/2 ); 00308 00309 // //resize image 00310 // ColorImageRGB8::PixelType** row = fullImage->unsafeRowPointerArray(); 00311 // ColorImageRGB8::PixelType** lowresRow = tmpImage.unsafeRowPointerArray(); 00312 00313 // int lowresHeight=tmpImage.getHeight(); 00314 // int lowresWidth=tmpImage.getWidth(); 00315 00316 // //ptr. to current row in orig. image 00317 // ColorImageRGB8::PixelType* currentRow; 00318 // ColorImageRGB8::PixelType* currentLowresRow; 00319 // int x,y,x2,y2; 00320 // y2=0; 00321 // for( y = 0; y < lowresHeight ; y++ ) { 00322 // currentRow=row[y2]; 00323 // currentLowresRow=lowresRow[y]; 00324 // x2=0; 00325 // for( x = 0; x < lowresWidth ; x++ ) { 00326 // currentLowresRow[x][0]=currentRow[x2][0]; 00327 // currentLowresRow[x][1]=currentRow[x2][1]; 00328 // currentLowresRow[x][2]=currentRow[x2][2]; 00329 // x2+=2; 00330 // } 00331 // y2+=2; 00332 // } 00333 // delete fullImage; 00334 // break; 00335 // } 00336 00337 // case QUARTER: 00338 // { 00339 // ColorImageRGB8* fullImage = new ColorImageRGB8(); 00340 // grabSuccess = m_GrabbingDevices[sourceId]->grabImage ( *fullImage ); 00341 00342 // tmpImage.resize( fullImage->getWidth()/4, fullImage->getHeight()/4 ); 00343 00344 // //resize image 00345 // ColorImageRGB8::PixelType** row = fullImage->unsafeRowPointerArray(); 00346 // ColorImageRGB8::PixelType** lowresRow = tmpImage.unsafeRowPointerArray(); 00347 00348 // int lowresHeight=tmpImage.getHeight(); 00349 // int lowresWidth=tmpImage.getWidth(); 00350 00351 // //ptr. to current row in orig. image 00352 // ColorImageRGB8::PixelType* currentRow; 00353 // ColorImageRGB8::PixelType* currentLowresRow; 00354 // int x,y,x2,y2; 00355 // y2=0; 00356 // for( y = 0; y < lowresHeight ; y++ ) { 00357 // currentRow=row[y2]; 00358 // currentLowresRow=lowresRow[y]; 00359 // x2=0; 00360 // for( x = 0; x < lowresWidth ; x++ ) { 00361 // currentLowresRow[x][0]=currentRow[x2][0]; 00362 // currentLowresRow[x][1]=currentRow[x2][1]; 00363 // currentLowresRow[x][2]=currentRow[x2][2]; 00364 // x2+=4; 00365 // } 00366 // y2+=4; 00367 // } 00368 // delete fullImage; 00369 // break; 00370 // } 00371 // } 00372 00373 // //rotate image if necessary (slow but works) 00374 // if ( m_Cameras[sourceId].getRotateImage() == false ) 00375 // { 00376 // image = tmpImage; 00377 // } 00378 // else 00379 // { 00380 // image.resize( tmpImage.getHeight(), tmpImage.getWidth() ); 00381 // for ( unsigned y=0; y<tmpImage.getHeight(); y++ ) 00382 // { 00383 // for ( unsigned x=0; x<tmpImage.getWidth(); x++ ) 00384 // { 00386 // image[x][y] = tmpImage[y][tmpImage.getWidth()-1-x]; 00388 // } 00389 // } 00390 // } 00391 00392 00393 00394 // if ( !grabSuccess ) 00395 // { 00396 // stream << "grabImage(" << ( int ) sourceId << ") failed."; 00397 00398 // return false; 00399 // } 00400 00401 // return true; 00402 //} 00403 00404 00405 //bool THIS::grabImageYuv ( ImageSources::SourceId sourceId, ScaleFactor scaling, ImageQuality quality, puma2::GrayLevelImage8 &yImage, puma2::ColorImageUV8 &uvImage ) 00406 //{ 00407 // if ( !checkCamera ( sourceId ) ) { return false; }; 00408 00409 // unsigned width = m_GrabbingDevices[sourceId]->getFrameWidth(); 00410 // unsigned height = m_GrabbingDevices[sourceId]->getFrameHeight(); 00411 00412 // unsigned char* buffer; 00413 // unsigned bufferSize = width * height * 2; 00414 // buffer = new unsigned char[bufferSize]; 00415 00416 // if ( !grabDataYuv ( sourceId, buffer ) ) { 00417 00418 // return false; 00419 // } 00420 00421 // bool convertSuccess; 00422 00423 // //rotate image if necessary (slow but works) 00424 // if ( m_Cameras[sourceId].getRotateImage() == false ) 00425 // { 00426 // convertSuccess = yuv422To444 ( quality, width, height, scaling, buffer, yImage, uvImage ); 00427 // } 00428 // else 00429 // { 00430 // puma2::GrayLevelImage8 yImage2; 00431 // puma2::ColorImageUV8 uvImage2; 00432 00433 // convertSuccess = yuv422To444 ( quality, width, height, scaling, buffer, yImage2, uvImage2 ); 00434 00435 // yImage.resize( yImage2.getHeight(), yImage2.getWidth() ); 00436 // uvImage.resize( uvImage2.getHeight(), uvImage2.getWidth() ); 00437 00438 // for ( unsigned y=0; y<yImage2.getHeight(); y++ ) 00439 // { 00440 // for ( unsigned x=0; x<yImage2.getWidth(); x++ ) 00441 // { 00442 // yImage[x][y] = yImage2[yImage2.getHeight()-1-y][x]; 00443 // uvImage[x][y] = uvImage2[uvImage2.getHeight()-1-y][x]; 00444 // } 00445 // } 00446 // } 00447 00448 // delete[] buffer; 00449 00450 // return convertSuccess; 00451 //} 00452 00453 00454 //bool THIS::grabDataYuv ( ImageSources::SourceId sourceId, unsigned char* buffer ) 00455 //{ 00456 00457 // ostringstream stream; 00458 00459 // if ( !checkCamera ( sourceId ) ) { 00460 00461 // return false; 00462 // }; 00463 00464 // stream << "Grabbing YUV camera image " << sourceId << " (" << m_Cameras[sourceId].getDeviceDescription() << ")"; 00465 00466 // stream.str ( "" ); 00467 00468 // //try to grab image data 00469 00470 // m_GrabbingDevices[sourceId]->grabData ( buffer, "UYVY" ); 00471 // m_GrabDataTimer.pauseMeasure(); 00472 00473 // /* 00474 // if ( !grabSuccess ) 00475 // { 00476 // stream << "grabData(" << (int)sourceId << ") failed."; 00477 // TRACE_ERROR(stream.str()); 00478 // delete[] buffer; 00479 // return false; 00480 // } 00481 // */ 00482 // return true; 00483 //} 00484 00485 00486 //bool THIS::yuv422To444 ( ImageQuality quality, int origWidth, int origHeight, ScaleFactor scaling, unsigned char* buffer, puma2::GrayLevelImage8 &yImage, puma2::ColorImageUV8 &uvImage ) 00487 //{ 00488 // puma2::byte** yRow; 00489 // ColorImageUV8::PixelType** uvRow; 00490 // puma2::byte* currentYRow; 00491 // ColorImageUV8::PixelType* currentUvRow; 00492 // unsigned x, y, width, height; 00493 // unsigned rowLength, rowLength2, rowLength3; 00494 // unsigned char* currentPixel; 00495 00496 00497 00498 // rowLength = origWidth * 2; 00499 // rowLength2 = rowLength * 2; 00500 // rowLength3 = rowLength * 3; 00501 00502 00503 // switch ( scaling ) 00504 // { 00505 // case FULL: 00506 // { 00507 // //make sure that output size is a multiple of 2 00508 // width = ( origWidth / 2 ) * 2; 00509 // height = ( origHeight / 2 ) * 2; 00510 // yImage.resize ( width, height ); 00511 // uvImage.resize ( width, height ); 00512 // yRow = yImage.unsafeRowPointerArray(); 00513 // uvRow = uvImage.unsafeRowPointerArray(); 00514 00515 // //convert image 00516 // for ( y = 0; y < height ; y++ ) 00517 // { 00518 // currentYRow = yRow[y]; 00519 // currentUvRow = uvRow[y]; 00520 // currentPixel = buffer + y * rowLength; 00521 // for ( x = 0; x < width - 1 ; x += 2 ) 00522 // { 00523 // currentUvRow[x][1] = currentPixel[2]; 00524 // currentUvRow[x+1][1] = currentPixel[2]; 00525 // currentUvRow[x][0] = currentPixel[0]; 00526 // currentUvRow[x+1][0] = currentPixel[0]; 00527 // currentYRow[x] = currentPixel[1]; 00528 // currentYRow[x+1] = currentPixel[3]; 00529 // currentPixel += 4; 00530 // } 00531 // } 00532 // } 00533 // break; 00534 00535 // case HALF: 00536 // { 00537 // width = origWidth / 2; 00538 // height = origHeight / 2; 00539 // yImage.resize ( width, height ); 00540 // uvImage.resize ( width, height ); 00541 // yRow = yImage.unsafeRowPointerArray(); 00542 // uvRow = uvImage.unsafeRowPointerArray(); 00543 // //convert image 00544 // if ( quality == LOW ) 00545 // { 00546 00547 // for ( y = 0; y < height ; y++ ) 00548 // { 00549 // currentYRow = yRow[y]; 00550 // currentUvRow = uvRow[y]; 00551 // currentPixel = buffer + y * rowLength * 2; 00552 // for ( x = 0; x < width ; x++ ) 00553 // { 00554 // currentUvRow[x][1] = currentPixel[2]; 00555 // currentUvRow[x][0] = currentPixel[0]; 00556 // currentYRow[x] = currentPixel[1]; 00557 // currentPixel += 4; 00558 // } 00559 // } 00560 // } 00561 // else 00562 // { 00563 00564 // for ( y = 0; y < height ; y++ ) 00565 // { 00566 // currentYRow = yRow[y]; 00567 // currentUvRow = uvRow[y]; 00568 // currentPixel = buffer + y * rowLength * 2; 00569 // for ( x = 0; x < width ; x++ ) 00570 // { 00571 // currentUvRow[x][0] = unsigned ( ( currentPixel[0] + currentPixel[rowLength] ) / 2 ); 00572 // currentUvRow[x][1] = unsigned ( ( currentPixel[2] + currentPixel[2+rowLength] ) / 2 ); 00573 // currentYRow[x] = unsigned ( ( currentPixel[1] + currentPixel[3] + currentPixel[1+rowLength] + currentPixel[3+rowLength] ) / 4 ); 00574 // currentPixel += 4; 00575 // } 00576 // } 00577 // } 00578 // } 00579 // break; 00580 00581 // case QUARTER: 00582 // { 00583 // width = origWidth / 4; 00584 // height = origHeight / 4; 00585 // yImage.resize ( width, height ); 00586 // uvImage.resize ( width, height ); 00587 // yRow = yImage.unsafeRowPointerArray(); 00588 // uvRow = uvImage.unsafeRowPointerArray(); 00589 // //convert image 00590 // if ( quality == LOW ) 00591 // { 00592 00593 // for ( y = 0; y < height ; y++ ) 00594 // { 00595 // currentYRow = yRow[y]; 00596 // currentUvRow = uvRow[y]; 00597 // currentPixel = buffer + y * rowLength * 4; 00598 // for ( x = 0; x < width ; x++ ) 00599 // { 00600 // currentUvRow[x][0] = currentPixel[0]; 00601 // currentUvRow[x][1] = currentPixel[2]; 00602 // currentYRow[x] = currentPixel[1]; 00603 // currentPixel += 8; 00604 // } 00605 // } 00606 // } 00607 // else 00608 // { 00609 00610 // for ( y = 0; y < height ; y++ ) 00611 // { 00612 // currentYRow = yRow[y]; 00613 // currentUvRow = uvRow[y]; 00614 // currentPixel = buffer + y * rowLength * 4; 00615 // for ( x = 0; x < width ; x++ ) 00616 // { 00617 // currentUvRow[x][0] = unsigned ( ( currentPixel[0] + currentPixel[4] 00618 // + currentPixel[rowLength] + currentPixel[4+rowLength] 00619 // + currentPixel[rowLength2] + currentPixel[4+rowLength2] 00620 // + currentPixel[rowLength3] + currentPixel[4+rowLength3] ) / 8 ); 00621 // currentUvRow[x][1] = unsigned ( ( currentPixel[2] + currentPixel[6] 00622 // + currentPixel[2+rowLength] + currentPixel[6+rowLength] 00623 // + currentPixel[2+rowLength2] + currentPixel[6+rowLength2] 00624 // + currentPixel[2+rowLength3] + currentPixel[6+rowLength3] ) / 8 ); 00625 // currentYRow[x] = unsigned ( ( currentPixel[1] + currentPixel[3] 00626 // + currentPixel[5] + currentPixel[7] 00627 // + currentPixel[1+rowLength] + currentPixel[3+rowLength] 00628 // + currentPixel[5+rowLength] + currentPixel[7+rowLength] 00629 // + currentPixel[1+rowLength2] + currentPixel[3+rowLength2] 00630 // + currentPixel[5+rowLength2] + currentPixel[7+rowLength2] 00631 // + currentPixel[1+rowLength3] + currentPixel[3+rowLength3] 00632 // + currentPixel[5+rowLength3] + currentPixel[7+rowLength3] ) / 16 ); 00633 // currentPixel += 8; 00634 // } 00635 // } 00636 // } 00637 // } 00638 // break; 00639 00640 // default: 00641 00642 // delete[] buffer; 00643 // return false; 00644 // break; 00645 // } 00646 00647 // m_ScaleYuvDataTimer.pauseMeasure(); 00648 00649 // return true; 00650 //} 00651 00653 //bool THIS::doWhiteBalance ( ImageSources::SourceId sourceId ) 00654 //{ 00655 00656 // //check if the camera exists and is initialized 00657 // if ( m_Cameras.find ( sourceId ) != m_Cameras.end() && m_Initialized[sourceId] ) 00658 // { 00659 // ostringstream stream; 00660 // stream << "Doing whitebalance for camera " << sourceId << " (" << m_Cameras[sourceId].getDeviceDescription() << ")"; 00661 00662 00663 // string paramName = "white_balance_mode"; 00664 // unicap_property_t *whiteProp; 00665 00666 // m_GrabbingDevices[sourceId]->getProperty ( &whiteProp, paramName ); 00667 // whiteProp->flags = UNICAP_FLAGS_ONE_PUSH; 00668 00669 // m_GrabbingDevices[sourceId]->setProperty ( *whiteProp ); 00670 // } 00671 // else 00672 // { 00673 // return false; 00674 // } 00675 00676 // usleep ( 200000 ); 00677 00678 // return true; 00679 //} 00680 00681 00682 //double THIS::zoomToAngle ( double zoom ) 00683 //{ 00684 // double temp; 00685 // temp = 0.0; 00686 00687 // // coefficients 00688 // double a = 4.8216073551172471E+01; 00689 // double b = -5.2152243126025878E-02; 00690 // double c = 1.4976250154467562E-05; 00691 00692 // temp = c; 00693 // temp = temp * zoom + b; 00694 // temp = temp * zoom + a; 00695 // return temp; 00696 //} 00697 00698 //double THIS::angleToZoom ( double angle ) 00699 //{ 00700 // double temp; 00701 // temp = 0.0; 00702 00703 // // coefficients 00704 // double a = 4.8216073551172471E+01; 00705 // double b = -5.2152243126025878E-02; 00706 // double c = 1.4976250154467562E-05; 00707 00708 // temp = - ( b / c ) / 2 - sqrt ( ( ( b * b ) / ( c * c ) ) / 4 - ( a - angle ) / c ); 00709 // return temp; 00710 //} 00711 00712 00714 //{ 00715 // return 2* atan ( tan ( ( 3.1415/180.0 ) *zoomToAngle ( 40.0 )/2 ) /factor ) * ( 180/3.1415 ); 00716 //} 00717 00718 //double THIS::angleToFactor ( double arc ) 00719 //{ 00720 // return tan ( ( 3.1415/180.0 ) *zoomToAngle ( 40.0 ) /2 ) /tan ( ( 3.1415/180.0 ) *arc/2 ); 00721 //}*/ 00722 00723 //bool THIS::setCameraZoomProperty ( ImageSources::SourceId sourceId, float factor, bool isAbsolute ) 00724 //{ 00725 // if ( !isAbsolute ) 00726 // factor *= Math::angleToPercent ( zoomToAngle ( getCameraProperty ( sourceId, "zoom" ) ), zoomToAngle ( 40.0 ) ); 00727 00728 // return setCameraProperty ( sourceId, "zoom", angleToZoom ( Math::percentToAngle ( 1.0 / factor, zoomToAngle ( 40.0 ) ) ), true ); 00729 //} 00730 00731 00732 //void THIS::applySobel ( puma2::GrayLevelImage8* image ) 00733 //{ 00734 // puma2::GrayLevelImage8::PixelType** row = image->unsafeRowPointerArray(); 00735 // unsigned width = image->getWidth(); 00736 // unsigned height = image->getHeight(); 00737 00738 // puma2::GrayLevelImage8* imageCopy = new puma2::GrayLevelImage8 ( width, height ); 00739 // memcpy ( imageCopy->unsafeRowPointerArray() [0], image->unsafeRowPointerArray() [0], width * height ); 00740 00741 // puma2::GrayLevelImage8::PixelType** rowCopy = imageCopy->unsafeRowPointerArray(); 00742 00743 00744 00745 // for ( unsigned y = 1;y < height - 1;++y ) 00746 // for ( unsigned x = 1;x < width - 1;++x ) 00747 // { 00748 // int fx = 3 * rowCopy[y-1][x-1] - 3 * rowCopy[y-1][x+1] + 00749 // 10 * rowCopy[y][x-1] - 10 * rowCopy[y][x+1] + 00750 // 3 * rowCopy[y+1][x-1] - 3 * rowCopy[y+1][x+1]; 00751 // int fy = 3 * rowCopy[y-1][x-1] + 10 * rowCopy[y-1][x] + 3 * rowCopy[y-1][x+1] + 00752 // -3 * rowCopy[y+1][x-1] - 10 * rowCopy[y+1][x] - 3 * rowCopy[y+1][x+1]; 00753 // fx /= 16; 00754 // fy /= 16; 00755 00756 // int strength = abs ( fx ) + abs ( fy ); 00757 // if ( strength > 255 ) 00758 // strength = 255; 00759 // else if ( strength < 0 ) 00760 // strength = 0; 00761 00762 // row[y][x] = strength; 00763 // } 00764 // delete rowCopy; 00765 //} 00766 00767 //long THIS::measureSharpness ( puma2::GrayLevelImage8* image ) 00768 //{ 00769 // puma2::GrayLevelImage8::PixelType** row = image->unsafeRowPointerArray(); 00770 // unsigned width = image->getWidth(); 00771 // unsigned height = image->getHeight(); 00772 00773 // unsigned int sharpness = 0; 00774 // for ( unsigned y = 1;y < height - 1;++y ) 00775 // for ( unsigned x = 1;x < width - 1;++x ) 00776 // { 00777 // int fx = 3 * row[y-1][x-1] - 3 * row[y-1][x+1] + 00778 // 10 * row[y][x-1] - 10 * row[y][x+1] + 00779 // 3 * row[y+1][x-1] - 3 * row[y+1][x+1]; 00780 // int fy = 3 * row[y-1][x-1] + 10 * row[y-1][x] + 3 * row[y-1][x+1] + 00781 // -3 * row[y+1][x-1] - 10 * row[y+1][x] - 3 * row[y+1][x+1]; 00782 // fx /= 4; 00783 // fy /= 4; 00784 00785 // sharpness += abs ( fx ) + abs ( fy ); 00786 // } 00787 // return sharpness; 00788 //} 00789 00790 00791 /*scale RGB images 00792 m_ResizeTimer.startMeasure(); 00793 lowresImage=new ColorImageRGB8(image.getWidth()/2,image.getHeight()/2); 00794 00795 //resize image 00796 ColorImageRGB8::PixelType** row = image.unsafeRowPointerArray(); 00797 ColorImageRGB8::PixelType** lowresRow = lowresImage->unsafeRowPointerArray(); 00798 int lowresHeight=lowresImage->getHeight(); 00799 int lowresWidth=lowresImage->getWidth(); 00800 00801 //ptr. to current row in orig. image 00802 ColorImageRGB8::PixelType* currentRow; 00803 ColorImageRGB8::PixelType* currentLowresRow; 00804 int x,y,x2,y2; 00805 y2=0; 00806 for( y = 0; y < lowresHeight ; y++ ) { 00807 currentRow=row[y2]; 00808 currentLowresRow=lowresRow[y]; 00809 x2=0; 00810 for( x = 0; x < lowresWidth ; x++ ) { 00811 currentLowresRow[x][0]=currentRow[x2][0]; 00812 currentLowresRow[x][1]=currentRow[x2][1]; 00813 currentLowresRow[x][2]=currentRow[x2][2]; 00814 x2+=2; 00815 } 00816 y2+=2; 00817 } 00818 m_ResizeTimer.pauseMeasure(); 00819 */ 00820 00821 00822 #undef THIS 00823