00001 00006 //============================================================================= 00007 // Copyright © 2004 Point Grey Research, Inc. All Rights Reserved. 00008 // 00009 // This software is the confidential and proprietary information of Point 00010 // Grey Research, Inc. ("Confidential Information"). You shall not 00011 // disclose such Confidential Information and shall use it only in 00012 // accordance with the terms of the license agreement you entered into 00013 // with Point Grey Research, Inc. (PGR). 00014 // 00015 // PGR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE 00016 // SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 00017 // IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 00018 // PURPOSE, OR NON-INFRINGEMENT. PGR SHALL NOT BE LIABLE FOR ANY DAMAGES 00019 // SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 00020 // THIS SOFTWARE OR ITS DERIVATIVES. 00021 // 00022 //============================================================================= 00023 //============================================================================= 00024 // $Id: triclopsrectify.h,v 2.5 2010/06/24 22:04:18 arturp Exp $ 00025 //============================================================================= 00026 #ifndef TRICLOPSRECTIFY_H 00027 #define TRICLOPSRECTIFY_H 00028 00029 //============================================================================= 00030 // 00031 // This file defines the API for the rectification and camera geometry 00032 // functions of the Triclops Stereo Vision SDK. 00033 // 00034 //============================================================================= 00035 00036 00037 //============================================================================= 00038 // Defines 00039 //============================================================================= 00040 00041 //============================================================================= 00042 // System Includes 00043 //============================================================================= 00044 00045 #include <triclops.h> 00046 00047 #ifdef __cplusplus 00048 extern "C" 00049 { 00050 #endif 00051 00052 //============================================================================= 00053 // Macros 00054 //============================================================================= 00055 00056 00057 //============================================================================= 00058 // Enumerations 00059 //============================================================================= 00060 00061 //============================================================================= 00062 // Types 00063 //============================================================================= 00064 // 00065 // Group = Types 00066 00067 // 00068 // Name: TriclopsRectImgQuality 00069 // 00070 // Description: 00071 // This enumerated type identifies 00072 // 00073 typedef enum TriclopsRectImgQuality 00074 { 00075 TriRectQlty_FAST, 00076 TriRectQlty_STANDARD, 00077 TriRectQlty_ENHANCED_1, 00078 TriRectQlty_ENHANCED_2 00079 } TriclopsRectImgQuality; 00080 00081 //============================================================================= 00082 // Function Prototypes 00083 //============================================================================= 00084 00085 //============================================================================= 00086 // Rectification and Camera Geometry 00087 //============================================================================= 00088 // Group = Rectification and Camera Geometry 00089 00090 // 00091 // Name: triclopsSetSourceResolution 00092 // 00093 // Synopsis: 00094 // Sets the resolution of the raw images that the library will be processing 00095 // later. 00096 // 00097 // Input: 00098 // context - The context. 00099 // nSrcRows - Number of rows in the raw images. 00100 // nSrcCols - Number of columns in the raw images. 00101 // 00102 // Returns: 00103 // TriclopsErrorOk - The operation succeeded. 00104 // InvalidContext - The input context was invalid. 00105 // InvalidSetting - The aspect ratio of the requested image was not 00106 // 4 columns to 3 rows, or was a negative size. 00107 // 00108 // Description: 00109 // This function sets the expected resolution of the raw images. 00110 // This function is provided primarily to support feature based stereo application 00111 // where one is expected to make direct calls to triclopsRectifyPixel() and 00112 // triclopsUnrectifyPixel() on a point by point basis. For regular stereo 00113 // application where an entire image will be rectified every time, the application 00114 // should use triclopsSetResolutionAndPrepare() which in addition to setting 00115 // up both the source and rectification resolution, it also creates the rectification 00116 // table to speed up the full image rectification calls. 00117 // 00118 // See Also: 00119 // triclopsGetSourceResolution(), triclopsRectifyPixel(), triclopsUnrectifyPixel(), 00120 // triclopsSetResolutionAndPrepare() 00121 // 00122 TriclopsError 00123 triclopsSetSourceResolution( TriclopsContext context, 00124 int nSrcRows, 00125 int nSrcCols ); 00126 00127 // 00128 // Name: triclopsSetResolution 00129 // 00130 // Synopsis: 00131 // Sets the resolution of the resultant images. This includes rectified, 00132 // disparity and edge images. 00133 // 00134 // Input: 00135 // context - The context. 00136 // nrows - Number of rows in the output images. 00137 // ncols - Number of columns in the output images. 00138 // 00139 // Returns: 00140 // TriclopsErrorOk - The operation succeeded. 00141 // InvalidContext - The input context was invalid. 00142 // InvalidSetting - The aspect ratio of the requested image was not 00143 // 4 columns to 3 rows, or was a negative size. 00144 // 00145 // Description: 00146 // This function sets the desired resolution of the output images. These 00147 // images include the rectified, disparity and edge images. This resolution 00148 // must maintain the 640x480 columns to rows ratio. If the user wishes to 00149 // have an image of a different aspect ratio, he/she must use Regions Of 00150 // Interest to control the size of the image that is being processed. 00151 // 00152 // See Also: 00153 // triclopsGetResolution(), triclopsGetROIs() 00154 // 00155 TriclopsError 00156 triclopsSetResolution( TriclopsContext context, 00157 int nrows, 00158 int ncols ); 00159 00160 // 00161 // Name: triclopsSetResolutionAndPrepare 00162 // 00163 // Synopsis: 00164 // Sets the resolution of the resultant images. This includes rectified, 00165 // disparity and edge images. 00166 // 00167 // Input: 00168 // context - The context. 00169 // nrows - Number of rows in the output images. 00170 // ncols - Number of columns in the output images. 00171 // nInputRows - Number of rows in the input images. 00172 // nInputCols - Number of columns in the input images. 00173 // 00174 // Returns: 00175 // TriclopsErrorOk - The operation succeeded. 00176 // InvalidContext - The input context was invalid. 00177 // InvalidSetting - The aspect ratio of the requested image was not 4 columns 00178 // to 3 rows, or was of negative size. 00179 // 00180 // Description: 00181 // This function sets the desired resolution of the output images and also 00182 // immediately constructs the rectification tables. For large images, the 00183 // construction of the rectification can take a while. This function allows 00184 // you to control when the construction takes place, otherwise it will occur 00185 // during the first call to triclopsPreprocess(). The resolution of the input 00186 // images must be specified at this time, as this is necessary for the 00187 // construction of the tables. The output images include the rectified, 00188 // disparity and edge images. This requested resolution must maintain the 00189 // 640x480 columns to rows ratio. If the user wishes to have an image of 00190 // a different aspect ratio, he/she must use Regions Of Interest to control 00191 // the size of the image that is being processed. 00192 // For feature based stereo application where rectification of the entire image 00193 // is not needed, one should call triclopsSetResolution() and triclopsSetSourceResolution() 00194 // only (these are much simpler functions), and then simply proceeds to call 00195 // triclopsRectifyPixel() and triclopsUnrectifyPixel() for the small set of feature 00196 // pixels needed. 00197 // 00198 // See Also: 00199 // triclopsGetResolution(), triclopsSetResolution(), triclopsSetSourceResolution(), 00200 // triclopsSetRectify() 00201 // 00202 TriclopsError 00203 triclopsSetResolutionAndPrepare( TriclopsContext context, 00204 int nrows, 00205 int ncols, 00206 int nInputRows, 00207 int nInputCols ); 00208 00209 // 00210 // Name: triclopsGetSourceResolution 00211 // 00212 // Synopsis: 00213 // Retrieves the resolution of the resultant images. This includes rectified, 00214 // disparity and edge images. 00215 // 00216 // Input: 00217 // context - The context. 00218 // 00219 // Output: 00220 // nSrcRows - Number of rows in the raw images. 00221 // nSrcCols - Number of columns in the raw images. 00222 // 00223 // Returns: 00224 // TriclopsErrorOk - The operation succeeded. 00225 // InvalidContext - The input context was invalid. 00226 // 00227 // Description: 00228 // This returns the current resolution for raw images of the given context. 00229 // 00230 // See Also: 00231 // triclopsSetSourceResolution() 00232 // 00233 TriclopsError 00234 triclopsGetSourceResolution( const TriclopsContext context, 00235 int* nSrcRows, 00236 int* nSrcCols ); 00237 00238 // 00239 // Name: triclopsGetResolution 00240 // 00241 // Synopsis: 00242 // Retrieves the resolution of the resultant images. This includes rectified, 00243 // disparity and edge images. 00244 // 00245 // Input: 00246 // context - The context. 00247 // 00248 // Output: 00249 // nrows - Number of rows in the output images. 00250 // ncols - Number of columns in the output images. 00251 // 00252 // Returns: 00253 // TriclopsErrorOk - The operation succeeded. 00254 // InvalidContext - The input context was invalid. 00255 // 00256 // Description: 00257 // This returns the current resolution for output images of the given context. 00258 // 00259 // See Also: 00260 // triclopsSetResolution() 00261 // 00262 TriclopsError 00263 triclopsGetResolution( const TriclopsContext context, 00264 int* nrows, 00265 int* ncols ); 00266 00267 //============================================================================= 00268 // Rectification 00269 //============================================================================= 00270 // 00271 // Group = Rectification 00272 00273 00274 // 00275 // Name: triclopsSetLowpass 00276 // 00277 // Synopsis: 00278 // Turns low-pass filtering before rectification on or off. 00279 // 00280 // Input: 00281 // context - The context. 00282 // on - A Boolean value indicating whether it should be turned on or off. 00283 // 00284 // Returns: 00285 // TriclopsErrorOk - The operation succeeded. 00286 // InvalidContext - The input context was invalid. 00287 // 00288 // See Also: 00289 // triclopsGetLowpass() 00290 // 00291 TriclopsError 00292 triclopsSetLowpass( TriclopsContext context, 00293 TriclopsBool on ); 00294 00295 // 00296 // Name: triclopsGetLowpass 00297 // 00298 // Synopsis: 00299 // Retrieves the state of the low-pass filtering feature. 00300 // 00301 // Input: 00302 // context - The context. 00303 // 00304 // Output: 00305 // on - A pointer to a Boolean variable that will store the current setting. 00306 // 00307 // Returns: 00308 // TriclopsErrorOk - The operation succeeded. 00309 // InvalidContext - The input context was invalid. 00310 // 00311 // See Also: 00312 // triclopsSetLowpass() 00313 // 00314 TriclopsError 00315 triclopsGetLowpass( const TriclopsContext context, 00316 TriclopsBool* on ); 00317 00318 // 00319 // Name: triclopsSetRectify 00320 // 00321 // Synopsis: 00322 // Turns rectification on or off. 00323 // 00324 // Input: 00325 // context - The context. 00326 // on - A Boolean indicating whether rectification should be turned on or 00327 // off. 00328 // 00329 // Returns: 00330 // TriclopsErrorOk - The operation succeeded. 00331 // InvalidContext - The input context was invalid. 00332 // 00333 // See Also: 00334 // triclopsGetRectify(), triclopsSetRectImgQuality(), triclopsGetRectImgQuality() 00335 // 00336 TriclopsError 00337 triclopsSetRectify( TriclopsContext context, 00338 TriclopsBool on ); 00339 00340 // 00341 // Name: triclopsGetRectify 00342 // 00343 // Synopsis: 00344 // Retrieves the state of the rectification feature. 00345 // 00346 // Input: 00347 // context - The context. 00348 // 00349 // Output: 00350 // on - A pointer to a Boolean that will store the current setting. 00351 // 00352 // Returns: 00353 // TriclopsErrorOk - The operation succeeded. 00354 // InvalidContext - The input context was invalid. 00355 // 00356 // See Also: 00357 // triclopsSetRectify(), triclopsSetRectImgQuality(), triclopsGetRectImgQuality() 00358 // 00359 TriclopsError 00360 triclopsGetRectify( const TriclopsContext context, 00361 TriclopsBool* on ); 00362 00363 // 00364 // Name: triclopsSetRectImgQuality 00365 // 00366 // Description: 00367 // Sets the quality of the algorithm to use during image rectification. 00368 // Higher-quality algorithms will generally require more processing time, but 00369 // give more accurate results. Currently available are 00370 // TriRectQlty_STANDARD, our classic rectification algorithm, and 00371 // TriRectQlty_ENHANCED, which uses a more elaborate kernel in the rectification 00372 // process. 00373 // 00374 // Input: 00375 // context - The current TriclopsContext. 00376 // quality - The desired quality of the rectification algorithm to use. 00377 // 00378 // Returns: 00379 // TriclopsErrorOk - The operation succeeded. 00380 // TriclopsErrorInvalidContext - If the context is invalid. 00381 // 00382 // See Also: 00383 // triclopsGetRectImgQuality() 00384 // 00385 TriclopsError 00386 triclopsSetRectImgQuality(TriclopsContext context, TriclopsRectImgQuality quality); 00387 00388 // 00389 // Name: triclopsGetRectImgQuality 00390 // 00391 // Description: 00392 // Gets the quality of the algorithm currently in use for image rectification. 00393 // 00394 // Input: 00395 // context - The current TriclopsContext. 00396 // quality - The quality of the rectification algorithm currently in use. 00397 // 00398 // Returns: 00399 // TriclopsErrorOk - The operation succeeded. 00400 // TriclopsErrorInvalidContext - If the context is invalid. 00401 // 00402 // See Also: 00403 // triclopsSetRectImgQuality() 00404 // 00405 TriclopsError 00406 triclopsGetRectImgQuality(TriclopsContext context, TriclopsRectImgQuality* quality); 00407 00408 // 00409 // Name: triclopsRectifyPackedColorImage 00410 // 00411 // Description: 00412 // This function rectifies a packed color image. 00413 // This function will only rectify a packed TriclopsInput (a TriclopsInput 00414 // of type TriInp_RGB_32BIT_PACKED). It is useful for creating rectified 00415 // color images for display, since bitmap displays commonly require the 00416 // data format to be packed. 00417 // 00418 // Input: 00419 // context - The TriclopsContext to use to rectify the color image. 00420 // nCamera - The camera from which this TriclopsInput originated. 00421 // If the system is a Color Triclops, nCamera should be set to 00422 // TriCam_COLOR. 00423 // input - The color image to be rectified. 00424 // 00425 // Output: 00426 // output - The rectified color image. 00427 // 00428 // Returns: 00429 // TriclopsErrorOk - Upon the successful completion of the operation. 00430 // 00431 TriclopsError 00432 triclopsRectifyPackedColorImage( TriclopsContext context, 00433 TriclopsCamera nCamera, 00434 TriclopsInput* input, 00435 TriclopsPackedColorImage* output ); 00436 00437 // 00438 // Name: triclopsRectifyColorImage 00439 // 00440 // Synopsis: 00441 // Rectifies a TriclopsInput structure into a TriclopsColorImage. 00442 // This function is used for TriclopsInput's that have been 00443 // obtained from a Color Triclops. If the system is 00444 // a Color Triclops, nCamera should be set to TriCam_COLOR. 00445 // 00446 // Input: 00447 // context - The context. 00448 // nCamera - A TriclopsCamera enumerated value indicating which camera 00449 // the input image came from. 00450 // input - The raw color image encoded into a TriclopsInput structure. 00451 // 00452 // Output: 00453 // output - The resultant rectified color image. 00454 // 00455 // Returns: 00456 // TriclopsErrorOk - The operation succeeded. 00457 // InvalidContext - The input context was invalid. 00458 // InvalidRequest - The input raw image had a size of 0. 00459 // InvalidCamera - There is a corruption in the color 00460 // camera calibration data in the calibration file. 00461 // InvalidSettings - The TriclopsInput structure did not have a recognizable 00462 // data type. 00463 // 00464 TriclopsError 00465 triclopsRectifyColorImage( TriclopsContext context, 00466 TriclopsCamera nCamera, 00467 TriclopsInput* input, 00468 TriclopsColorImage* output ); 00469 00470 00471 // 00472 // Name: triclopsRectifyPixel 00473 // 00474 // Synopsis: 00475 // Converts a pixel coordinate location from the unrectified image coordinates 00476 // to rectified image coordinates. 00477 // The source image dimension must have been previously set either via a call 00478 // to triclopsSetSourceResolution() or triclopsSetResolutionAndPrepare(). 00479 // 00480 // Input: 00481 // context - The context. 00482 // camera - The camera for which the pixel should be rectified. 00483 // rowIn - The location of the pixel to rectify. 00484 // colIn - The location of the pixel to rectify. 00485 // 00486 // Output: 00487 // rowOut - The location of the rectified pixel. 00488 // colOut - The location of the rectified pixel. 00489 // 00490 // Returns: 00491 // TriclopsErrorOk - The operation succeeded. 00492 // InvalidContext - The input context was invalid. 00493 // InvalidCamera - The camera argument was invalid. 00494 // TriclopsErrorInvalidSetting - The raw image dimension has not been set 00495 // 00496 // See Also: 00497 // triclopsPreprocess(), triclopsRectifyColorImage(), triclopsSetSourceResolution() 00498 // 00499 TriclopsError 00500 triclopsRectifyPixel( const TriclopsContext context, 00501 TriclopsCamera camera, 00502 float rowIn, 00503 float colIn, 00504 float* rowOut, 00505 float* colOut ); 00506 00507 // 00508 // Name: triclopsUnrectifyPixel 00509 // 00510 // Synopsis: 00511 // Converts a pixel coordinate location from the rectified image coordinates 00512 // to unrectified image coordinates. 00513 // 00514 // Input: 00515 // context - The context. 00516 // camera - The camera for which the pixel should be unrectified. 00517 // rowIn - The location of the pixel to unrectify. 00518 // colIn - The location of the pixel to unrectify. 00519 // 00520 // Output: 00521 // rowOut - The location of the unrectified pixel. 00522 // colOut - The location of the unrectified pixel. 00523 // 00524 // Returns: 00525 // TriclopsErrorOk - The operation succeeded. 00526 // InvalidContext - The input context was invalid. 00527 // InvalidCamera - The camera argument was invalid. 00528 // TriclopsErrorInvalidSetting - The raw image dimension has not been set 00529 // InvalidRequest - The requested rectified location cannot be unrectified 00530 // into a location that is within the proper raw image bounds 00531 // 00532 // Remarks: 00533 // This version will accommodate input rectified pixel locations that are 00534 // outside of the normal rectified image bounds, as long as the corresponding 00535 // unrectified location is within its own image bounds. 00536 // The source image dimension must have been previously set either via a call 00537 // to triclopsSetSourceResolution() or triclopsSetResolutionAndPrepare(). 00538 // 00539 // See Also: 00540 // triclopsRectifyPixel(), triclopsSetSourceResolution() 00541 // 00542 TriclopsError 00543 triclopsUnrectifyPixel( const TriclopsContext context, 00544 TriclopsCamera camera, 00545 float rowIn, 00546 float colIn, 00547 float* rowOut, 00548 float* colOut ); 00549 00550 00551 // 00552 // Name: triclopsPreprocess 00553 // 00554 // Synopsis: 00555 // Does image unpacking, smoothing, rectification and edge detection, 00556 // as specified by parameters. 00557 // 00558 // Input: 00559 // context - The context. 00560 // input - The image to be processed. 00561 // 00562 // Returns: 00563 // TriclopsErrorOk - The operation succeeded. 00564 // InvalidContext - The input context was invalid. 00565 // NotImplemented - TriclopsInput has rowinc < ncols*pixelsize 00566 // 00567 // Description: 00568 // This function does all necessary preprocessing on the input data. It 00569 // unpacks the data, which strips individual channels from 32-bit packed 00570 // data and puts them into 3 TriImg_RAW channels. It applies a low-pass 00571 // filter on these channels if requested, and corrects for lens distortion 00572 // and camera misalignment, saving these images into TriImg_RECTIFIED. 00573 // Finally it performs 2nd derivative Gaussian edge processing on the 00574 // rectified images and saves them into TriImg_EDGE internal images. 00575 // 00576 // See Also: 00577 // triclopsStereo(), triclopsSetResolution(), triclopsSetEdgeCorrelation(), 00578 // triclopsSetRectify(), triclopsSetLowpass() 00579 // 00580 TriclopsError 00581 triclopsPreprocess( TriclopsContext context, 00582 TriclopsInput* input ); 00583 00584 //============================================================================= 00585 // Configuration 00586 //============================================================================= 00587 // 00588 // Group = Configuration 00589 00590 // 00591 // Name: triclopsGetBaseline 00592 // 00593 // Synopsis: 00594 // Retrieves the baseline of the cameras. 00595 // 00596 // Input: 00597 // context - The context. 00598 // 00599 // Output: 00600 // base - The baseline in meters. 00601 // 00602 // Returns: 00603 // TriclopsErrorOk - The operation succeeded. 00604 // InvalidContext - The input context was invalid. 00605 // 00606 // Description: 00607 // This function retrieves the baseline of the cameras in meters. The 00608 // stereo context must have already been read. 00609 // 00610 // See Also: 00611 // triclopsGetDefaultContextFromFile() 00612 // 00613 TriclopsError 00614 triclopsGetBaseline( TriclopsContext context, 00615 float* base ); 00616 00617 // 00618 // Name: triclopsGetFocalLength 00619 // 00620 // Synopsis: 00621 // Retrieves the focal length of the cameras. 00622 // 00623 // Input: 00624 // context - The context. 00625 // 00626 // Output: 00627 // focallength - The focal length in pixels. 00628 // 00629 // Returns: 00630 // TriclopsErrorOk - The operation succeeded. 00631 // InvalidContext - The input context was invalid. 00632 // 00633 // Description: 00634 // This function returns the focal length of the system. The focal length 00635 // is in 'pixels' for the current selected output resolution. All cameras' 00636 // rectified images have the same focal length. The default stereo context 00637 // must have been read before this call can be made. 00638 // 00639 // See Also: 00640 // triclopsGetDefaultContextFromFile(), triclopsSetResolution() 00641 // 00642 TriclopsError 00643 triclopsGetFocalLength( const TriclopsContext context, 00644 float* focallength ); 00645 00646 // 00647 // Name: triclopsGetImageCenter 00648 // 00649 // Synopsis: 00650 // Returns the optical center for pinhole calculations. 00651 // 00652 // Input: 00653 // context - TriclopsContext for the operation. 00654 // 00655 // Output: 00656 // centerRow - A pointer that will contain the row position 00657 // of the image center for the current resolution. 00658 // centerCol - A pointer that will contain the column position 00659 // of the image center for the current resolution. 00660 // 00661 // Returns: 00662 // TriclopsErrorOk - Operation successful. 00663 // TriclopsErrorInvalidContext - Context is not a valid TriclopsContext. 00664 // 00665 // Description: 00666 // It is important that the context already has the resolution set. 00667 // If triclopsSetResolution is not set, the returned value cannot be 00668 // used for calculations. This image center can be used as the position 00669 // in the image plane of the optical center for pinhole camera calculations. 00670 // 00671 // See Also: 00672 // triclopsSetResolution() 00673 // 00674 TriclopsError 00675 triclopsGetImageCenter( TriclopsContext context, 00676 float* centerRow, 00677 float* centerCol ); 00678 00679 00680 #ifdef __cplusplus 00681 } 00682 #endif 00683 00684 #endif // #ifndef TRICLOPSRECTIFY_H