00001
00002
00003
00004
00005
00006
00007
00008 #ifndef AIBOCAM_H
00009 #define AIBOCAM_H
00010
00011
00012
00013 #include <math.h>
00014 #include <stdio.h>
00015
00016
00017 #include <OPENR/ODataFormats.h>
00018 #include <OPENR/OFbkImage.h>
00019 #include <OPENR/OPENRAPI.h>
00020 #include <OPENR/OSyslog.h>
00021 #include <Types.h>
00022
00023 #include "BMP.h"
00024
00026 static const char* const FBK = "PRM:/r1/c1/c2/c3/i1-FbkImageSensor:F1";
00027
00029 static const int NUM_CDT_SEG = 32;
00030
00032 static const double FIELD_VIEW_H = 57.6;
00033 static const double FIELD_VIEW_V = 47.8;
00034
00035
00037 struct CdtData{
00038 int segment;
00039 byte cr_max;
00040 byte cr_min;
00041 byte cb_max;
00042 byte cb_min;
00043 };
00044
00045
00047 enum WHITE_BALANCE{
00048 INDOOR = 1,
00049 DEFAULT = 2,
00050 OUTDOOR = 3
00051 };
00052
00054 enum SHUTTER_SPEED{
00055 SLOW = 1,
00056 MEDIUM = 2,
00057 FAST = 3
00058 };
00059
00061 enum CAM_GAIN{
00062 LOW = 1,
00063 MID = 2,
00064 HIGH = 3
00065 };
00066
00070 enum LAYER{
00071 RAW_Y,
00072 RAW_Cr,
00073 RAW_Cb,
00074 RAW_GradX,
00075 RAW_GradY,
00076 RAW_Mag
00077 };
00078
00102 class AiboCam {
00103
00104 public:
00106 AiboCam();
00107
00109 virtual ~AiboCam();
00110
00114 void OpenPrimitive();
00115
00116
00120
00125 void SetCdtChannels(const int numChannels);
00126
00127
00131 int GetCdtChannels() const;
00132
00133
00140 void SetCdtVectorDataOfPinkBall(const int channel=0);
00141
00142 void SetCdtVectorDataOfPinkBallSpecial(const int channel = 0);
00143
00150 void SetCdtTable(const int channel, const CdtData table[32]);
00151
00161 int GetColorFrequency(OFbkImageVectorData* imageVec, const int channel = 0);
00162
00165 int GetColorFrequency(OFbkImageVectorData* imageVec, const OCdtChannel channel = ocdtCHANNEL0);
00166
00167
00177 bool GetCenter(OFbkImageVectorData* imageVec, int cdtChannel, int &xCenter, int &yCenter);
00178
00188 bool GetCenter(OFbkImageVectorData* imageVec,
00189 int cdtChannel,
00190 int *xCenter, int *yCenter);
00191
00201 bool GetCenter(const OFbkImage& cdtImage,
00202 const int cdtChannel ,
00203 int *xCenter, int *yCenter);
00204
00205
00215 bool GetCenter(const OFbkImage& cdtImage,
00216 const OCdtChannel& cdtChannel ,
00217 int *xCenter, int *yCenter);
00218
00224 void saveCDT(char *fileName, CdtData cdt[32]) const ;
00225
00230 CdtData * loadCDT(char *fileName);
00231
00233
00237
00242 void SetWhiteBalance(WHITE_BALANCE balance);
00243
00248 void SetShutterSpeed(SHUTTER_SPEED speed);
00249
00254 void SetGain(CAM_GAIN gain);
00255
00257
00261
00267 void SaveRawData(char* path,
00268 OFbkImageVectorData* imageVec,
00269 const OFbkImageLayer layer) const;
00270
00276 void SaveBMP(char *path,
00277 OFbkImageVectorData* imageVec,
00278 const OFbkImageLayer layer) const;
00279
00280
00285 void SaveCdtBMP(char *basepath,
00286 OFbkImageVectorData* imageVec) const;
00287
00289
00290
00294
00295
00301 OFbkImage GetYImage(OFbkImageVectorData* imageVec,
00302 const OFbkImageLayer layer);
00303
00309 OFbkImage GetCbImage(OFbkImageVectorData* imageVec,
00310 const OFbkImageLayer layer);
00311
00317 OFbkImage GetCrImage(OFbkImageVectorData* imageVec,
00318 const OFbkImageLayer layer);
00319
00324 OFbkImage GetCdtImage(OFbkImageVectorData* imageVec);
00325
00331 int GetImageWidth(OFbkImage *image) const;
00332
00333
00339 int GetImageHeight(OFbkImage *image) const;
00340
00347 byte * GetImageData(OFbkImageVectorData* imageVec, const OFbkImageLayer layer);
00348
00357 void GetYCrCbData(byte *ycrcbImage,
00358 OFbkImageVectorData* imageVec, const OFbkImageLayer layer) const;
00359
00360
00361
00373
00374
00375
00376
00382 byte * GetImageData(OFbkImage *image);
00383
00384
00387 byte * GetImageData(const OFbkImage& image);
00388
00389
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00419 void RAW2(byte *outImage,
00420 byte *rawImage,
00421 const int width, const int height,
00422 const LAYER l) const;
00423
00424
00425 protected:
00426
00427
00431
00434 void YCrCb2RGB(byte y, byte cr, byte cb, byte* r, byte* g, byte* b) const;
00435
00436
00444 void YCrCb2RGB(byte *rgbImage,
00445 byte *ycrcbImage,
00446 const int width, const int height) const;
00447
00448
00461 void RAW2RGB(byte *rgbImage,
00462 byte *rawImage,
00463 const int width, const int height) const;
00464
00465
00466
00478 void RAW2YCrCb(byte *ycrcbImage,
00479 byte *rawImage,
00480 const int width, const int height) const;
00481
00483
00484
00486 OPrimitiveID FbkID;
00487
00489 OCdtVectorData *CdtVector;
00490
00492 MemoryRegionID CdtVectorID;
00493
00494
00495
00496 };
00497
00498
00499
00500
00501
00502 inline int AiboCam::GetCdtChannels() const
00503 {
00504 return (CdtVector->vectorInfo.numData);
00505 };
00506
00507
00508
00509
00510
00511 inline int AiboCam::GetImageWidth(OFbkImage *image) const
00512 {
00513 return image->Width();
00514 };
00515
00516
00517
00518
00519 inline int AiboCam::GetImageHeight(OFbkImage *image) const
00520 {
00521 return image->Height();
00522 };
00523
00524
00525
00526
00527
00528
00529 inline byte * AiboCam::GetImageData(OFbkImage *image)
00530 {
00531 return image->Pointer();
00532 };
00533
00534
00535
00536
00537 inline byte * AiboCam::GetImageData(const OFbkImage& image)
00538 {
00539 return image.Pointer();
00540 };
00541
00542
00543
00544
00545
00546
00547 inline void AiboCam::YCrCb2RGB(byte y, byte cr, byte cb, byte* r, byte* g, byte* b) const
00548 {
00549
00550 sbyte scr = (sbyte)(cr ^ 0x80);
00551 sbyte scb = (sbyte)(cb ^ 0x80);
00552
00553 double Y = (double)y / 255.0;
00554 double Cr = (double)scr / 128.0;
00555 double Cb = (double)scb / 128.0;
00556
00557 double R = 255.0 * (Y + Cr);
00558 double G = 255.0 * (Y - 0.51*Cr - 0.19*Cb);
00559 double B = 255.0 * (Y + Cb);
00560
00561 if (R > 255.0) {
00562 *r = 255;
00563 } else if (R < 0.0) {
00564 *r = 0;
00565 } else {
00566 *r = (byte)R;
00567 }
00568
00569 if (G > 255.0) {
00570 *g = 255;
00571 } else if (G < 0.0) {
00572 *g = 0;
00573 } else {
00574 *g = (byte)G;
00575 }
00576
00577 if (B > 255.0) {
00578 *b = 255;
00579 } else if (B < 0.0) {
00580 *b = 0;
00581 } else {
00582 *b = (byte)B;
00583 }
00584 };
00585
00586
00587
00588
00589
00590 inline void AiboCam::RAW2YCrCb(byte *ycrcbImage,
00591 byte *rawImage,
00592 const int width, const int height) const
00593 {
00594 byte *dstPtr = ycrcbImage;
00595
00596 byte in1, in2, in3;
00597 byte out1, out2, out3;
00598
00599 int counter = 0;
00600 int line = 0;
00601
00602 dstPtr += 3;
00603 for(int x = 0; x < width*height ; x++){
00604
00605 if(line == width-1){
00606
00607 counter += 5*width+1;
00608
00609 line = 0;
00610 }
00611 else{
00612 counter++;
00613 line++;
00614 }
00615
00616 *dstPtr++ = rawImage[counter];
00617 *dstPtr++ = rawImage[counter+width];
00618 *dstPtr++ = rawImage[counter+width*2];
00619 }
00620 };
00621
00622
00623
00624
00625
00626
00627 inline void AiboCam::RAW2RGB(byte *rgbImage,
00628 byte *rawImage,
00629 const int width, const int height) const
00630 {
00631 byte *dstPtr = rgbImage;
00632
00633 byte in1, in2, in3;
00634 byte out1, out2, out3;
00635
00636 int counter = 0;
00637 int line = 0;
00638
00639 dstPtr += 3;
00640 for(int x = 0; x < width*height ; x++){
00641
00642 if(line == width-1){
00643
00644 counter += 5*width+1;
00645
00646 line = 0;
00647 }
00648 else{
00649 counter++;
00650 line++;
00651 }
00652
00653 in1 = rawImage[counter];
00654 in2 = rawImage[counter+width];
00655 in3 = rawImage[counter+width*2];
00656
00657 YCrCb2RGB(in1, in2, in3, &out1, &out2, &out3);
00658
00659 *dstPtr++ = out1;
00660 *dstPtr++ = out2;
00661 *dstPtr++ = out3;
00662 }
00663 };
00664
00665
00666
00667
00668 inline void AiboCam::YCrCb2RGB(byte *rgbImage,
00669 byte *ycrcbImage,
00670 const int width, const int height) const
00671 {
00672 byte *srcPtr = ycrcbImage;
00673 byte *dstPtr = rgbImage;
00674
00675 byte in1, in2, in3;
00676 byte out1, out2, out3;
00677
00678 for(int x = 0; x < width*height ; x++){
00679
00680 in1 = *srcPtr++;
00681 in2 = *srcPtr++;
00682 in3 = *srcPtr++;
00683
00684 YCrCb2RGB(in1, in2, in3, &out1, &out2, &out3);
00685
00686 *dstPtr++ = out1;
00687 *dstPtr++ = out2;
00688 *dstPtr++ = out3;
00689 }
00690
00691 };
00692
00693
00694
00695
00696
00697 inline void AiboCam::RAW2(byte *outImage,
00698 byte *rawImage,
00699 const int width, const int height,
00700 const LAYER l) const
00701 {
00702 int line = 0;
00703 int add = l*width;
00704
00705 for(int x = 1; x < width*height+1; x++){
00706
00707 if(line == width-1){
00708 add += 5*width+1;
00709 line = 0;
00710 }
00711 else{
00712 add++;
00713 line++;
00714 }
00715
00716 outImage[x] = rawImage[add];
00717 }
00718
00719 };
00720
00721
00722
00723 #endif //define AIBOCAM_H