Changeset 124 in flair-src


Ignore:
Timestamp:
Jan 12, 2017, 10:39:23 AM (8 years ago)
Author:
Sanahuja Guillaume
Message:

modifs jpeg

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/ReleaseNotes

    r122 r124  
    11* Actual Version:
    22
     3- added lib/FlairCore/src/Semaphore.cpp
    34- added fixed cameras in simulator, see $FLAIR_ROOT/flair-bin/models/indoor_fligh
    45t_arena.xml for an exemple
  • trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.cpp

    r122 r124  
    2626#include <GroupBox.h>
    2727#include <DoubleSpinBox.h>
     28#include <PushButton.h>
    2829#include <FrameworkManager.h>
    2930#include <MetaDualShock3.h>
     
    4950uav->GetVerticalCamera()->SetLogFormat(Camera::LogFormat::JPG);
    5051getFrameworkManager()->AddDeviceToLog(uav->GetVerticalCamera());
    51     greyCameraImage=new CvtColor(uav->GetVerticalCamera(),"gray",CvtColor::Conversion_t::GRAY);
     52       
     53        startOpticalflow=new PushButton(GetButtonsLayout()->NewRow(),"start optical flow");
    5254
    53     uav->GetVerticalCamera()->UseDefaultPlot(greyCameraImage->Output()); // Le defaultPlot de la caméra peut afficher n'importe quoi?
     55        greyCameraImage=new CvtColor(uav->GetVerticalCamera(),"gray",CvtColor::Conversion_t::ToGray);
    5456
    55     //optical flow stack
    56     opticalFlow=new OpticalFlow(greyCameraImage,uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique");
    57     opticalFlowSpeed=new OpticalFlowSpeed(opticalFlow,"vitesse du flux optique");
     57        uav->GetVerticalCamera()->UseDefaultPlot(greyCameraImage->Output()); // Le defaultPlot de la caméra peut afficher n'importe quoi?
    5858
    59     cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
    60     for(int i=0;i<2;i++) {
    61         desc->SetElementName(i,0,opticalFlowSpeed->Output()->Name(i,0));
    62     }
    63     cvmatrix* prev_value=new cvmatrix((const Thread*)this,desc,floatType,uav->ObjectName()); // diamond inheritance
    64     for(int i=0;i<2;i++) {
    65         prev_value->SetValue(i,0,0);
    66     }
     59        //optical flow stack
     60        opticalFlow=new OpticalFlow(greyCameraImage,uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique");
     61        opticalFlowSpeed=new OpticalFlowSpeed(opticalFlow,"vitesse du flux optique");
    6762
    68     opticalFlowSpeedFiltered=new LowPassFilter(opticalFlowSpeed,uav->GetVerticalCamera()->GetLayout()->NewRow(),"passe bas",prev_value);
     63        cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
     64        for(int i=0;i<2;i++) {
     65                        desc->SetElementName(i,0,opticalFlowSpeed->Output()->Name(i,0));
     66        }
     67        cvmatrix* prev_value=new cvmatrix((const Thread*)this,desc,floatType,uav->ObjectName()); // diamond inheritance
     68        for(int i=0;i<2;i++) {
     69                        prev_value->SetValue(i,0,0);
     70        }
     71
     72        opticalFlowSpeedFiltered=new LowPassFilter(opticalFlowSpeed,uav->GetVerticalCamera()->GetLayout()->NewRow(),"passe bas",prev_value);
    6973// delete prev_value?
    7074
    71     getFrameworkManager()->AddDeviceToLog(opticalFlowSpeed);
     75        getFrameworkManager()->AddDeviceToLog(opticalFlowSpeed);
    7276
    73     Tab* opticalFlowTab=new Tab(getFrameworkManager()->GetTabWidget(),"flux optique");
    74     DataPlot1D* xVelocityPlot=new DataPlot1D(opticalFlowTab->NewRow(),"x_velocity",-5,5);
    75     DataPlot1D* yVelocityPlot=new DataPlot1D(opticalFlowTab->LastRowLastCol(),"y_velocity",-5,5);
     77        Tab* opticalFlowTab=new Tab(getFrameworkManager()->GetTabWidget(),"flux optique");
     78        DataPlot1D* xVelocityPlot=new DataPlot1D(opticalFlowTab->NewRow(),"x_velocity",-5,5);
     79        DataPlot1D* yVelocityPlot=new DataPlot1D(opticalFlowTab->LastRowLastCol(),"y_velocity",-5,5);
    7680
    77     xVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(0,0));
    78     xVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(0,0),DataPlot::Blue);
    79     yVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(1,0));
    80     yVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(1,0),DataPlot::Blue);
     81        xVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(0,0));
     82        xVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(0,0),DataPlot::Blue);
     83        yVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(1,0));
     84        yVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(1,0),DataPlot::Blue);
    8185
    82     u_x=new Pid(setupLawTab->At(1,0),"u_x");
    83     u_x->UseDefaultPlot(graphLawTab->NewRow());
    84     u_y=new Pid(setupLawTab->At(1,1),"u_y");
    85     u_y->UseDefaultPlot(graphLawTab->LastRowLastCol());
     86        u_x=new Pid(setupLawTab->At(1,0),"u_x");
     87        u_x->UseDefaultPlot(graphLawTab->NewRow());
     88        u_y=new Pid(setupLawTab->At(1,1),"u_y");
     89        u_y->UseDefaultPlot(graphLawTab->LastRowLastCol());
    8690
    87     opticalFlowGroupBox=new GroupBox(GetJoystick()->GetTab()->NewRow(),"consignes fo");
    88     maxXSpeed=new DoubleSpinBox(opticalFlowGroupBox->NewRow(),"debattement x"," m/s",-5,5,0.1,1);
    89     maxYSpeed=new DoubleSpinBox(opticalFlowGroupBox->LastRowLastCol(),"debattement y"," m/s",-5,5,0.1,1);
     91        opticalFlowGroupBox=new GroupBox(GetJoystick()->GetTab()->NewRow(),"consignes fo");
     92        maxXSpeed=new DoubleSpinBox(opticalFlowGroupBox->NewRow(),"debattement x"," m/s",-5,5,0.1,1);
     93        maxYSpeed=new DoubleSpinBox(opticalFlowGroupBox->LastRowLastCol(),"debattement y"," m/s",-5,5,0.1,1);
    9094
    91     opticalFlowReference=new cvmatrix((const Thread*)this,2,1,floatType);
    92     xVelocityPlot->AddCurve(opticalFlowReference->Element(0,0),DataPlot::Green,"consigne");
    93     yVelocityPlot->AddCurve(opticalFlowReference->Element(1,0),DataPlot::Green,"consigne");
     95        opticalFlowReference=new cvmatrix((const Thread*)this,2,1,floatType);
     96        xVelocityPlot->AddCurve(opticalFlowReference->Element(0,0),DataPlot::Green,"consigne");
     97        yVelocityPlot->AddCurve(opticalFlowReference->Element(1,0),DataPlot::Green,"consigne");
    9498
    95     customReferenceOrientation= new AhrsData(this,"reference");
    96     uav->GetAhrs()->AddPlot(customReferenceOrientation,DataPlot::Yellow);
    97     AddDataToControlLawLog(customReferenceOrientation);
     99        customReferenceOrientation= new AhrsData(this,"reference");
     100        uav->GetAhrs()->AddPlot(customReferenceOrientation,DataPlot::Yellow);
     101        AddDataToControlLawLog(customReferenceOrientation);
    98102}
    99103
     
    107111}
    108112
     113void DemoOpticalFlow::StartOpticalFlow(void) {
     114        if (SetOrientationMode(OrientationMode_t::Custom)) {
     115                        Thread::Info("(Re)entering optical flow mode\n");
     116                        u_x->Reset();
     117                        u_y->Reset();
     118        } else {
     119                        Thread::Warn("Could not enter optical flow mode\n");
     120        }
     121}
     122
     123void DemoOpticalFlow::ExtraCheckPushButton(void) {
     124        if(startOpticalflow->Clicked()) {
     125        //StartOpticalFlow();
     126                                GetUav()->GetVerticalCamera()->SavePictureToFile("./toto.jpg");
     127                               
     128        }
     129}
     130
    109131void DemoOpticalFlow::ExtraCheckJoystick(void) {
    110132    static bool wasOpticalFlowModeButtonPressed=false;
     
    113135        if (!wasOpticalFlowModeButtonPressed) {
    114136            wasOpticalFlowModeButtonPressed=true;
    115             if (SetOrientationMode(OrientationMode_t::Custom)) {
    116                 Thread::Info("(Re)entering optical flow mode\n");
    117                 u_x->Reset();
    118                 u_y->Reset();
    119             } else {
    120                 Thread::Warn("Could not enter optical flow mode\n");
    121             }
     137            StartOpticalFlow();
    122138        }
    123139    } else {
  • trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.h

    r122 r124  
    2525        class GroupBox;
    2626        class DoubleSpinBox;
     27        class PushButton;
    2728    }
    2829    namespace filter {
     
    4647        void SignalEvent(Event_t event);
    4748        void ExtraCheckJoystick(void);
     49                                void ExtraCheckPushButton(void);
    4850        const flair::core::AhrsData *GetReferenceOrientation(void);
    4951
     
    5961        flair::filter::OpticalFlow *opticalFlow;
    6062        flair::filter::OpticalFlowSpeed *opticalFlowSpeed;
     63                                flair::gui::PushButton *startOpticalflow,*stopOpticalflow;
     64                                void StartOpticalFlow(void);
    6165};
    6266
  • trunk/lib/FlairCore/src/cvimage.cpp

    r15 r124  
    3636      img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
    3737      break;
    38     case Type::Format::GRAY:
     38    case Type::Format::Gray:
    3939      img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
    4040      break;
     
    5555      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
    5656      break;
    57     case Type::Format::GRAY:
     57    case Type::Format::Gray:
    5858      img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);
    5959      break;
  • trunk/lib/FlairCore/src/cvimage.h

    r15 r124  
    3939      UYVY, /*!< UYVY 16 bits */
    4040      BGR,  /*!< BGR 24 bits */
    41       GRAY, /*!< gray 8 bits */
     41      Gray, /*!< gray 8 bits */
    4242    };
    4343    Type(uint16_t _width, uint16_t _height, Format _format)
     
    4747      size_t pixelSize;
    4848      switch (format) {
    49       case Format::GRAY:
     49      case Format::Gray:
    5050        pixelSize = 1;
    5151        break;
  • trunk/lib/FlairSensorActuator/src/Camera.cpp

    r123 r124  
    116116void Camera::ProcessUpdate(core::io_data* data) {
    117117        if(getFrameworkManager()->IsLogging() && getFrameworkManager()->IsDeviceLogged(this)) {
    118                 switch(logFormat) {
    119                         case LogFormat::JPG:
    120                                         IplImage *img=((cvimage*)data)->img;
    121                                         string filename=getFrameworkManager()->GetLogPath()+"/"+ObjectName()+"_"+std::to_string(data->DataTime())+".jpg";
    122                                         saveToJpeg(img,filename);
    123                                 break;
     118                if(logFormat==LogFormat::JPG) {
     119                        data->GetMutex();
     120                        IplImage *img=((cvimage*)data)->img;
     121                        string filename=getFrameworkManager()->GetLogPath()+"/"+ObjectName()+"_"+std::to_string(data->DataTime())+".jpg";
     122                        switch(((cvimage*)data)->GetDataType().GetFormat()) {
     123                                case cvimage::Type::Format::Gray:
     124                                        saveToJpeg(img,filename,PictureFormat_t::Gray,PictureFormat_t::Gray);
     125                                        break;
     126                                case cvimage::Type::Format::BGR:
     127                                        saveToJpeg(img,filename,PictureFormat_t::RGB,PictureFormat_t::RGB);
     128                                        break;
     129                                case cvimage::Type::Format::UYVY:
     130                                        saveToJpeg(img,filename,PictureFormat_t::UYVY,PictureFormat_t::UYVY);
     131                                        break;
     132                                default:
     133                                        Warn("cannot log to this format\n");
     134                                        break;
     135                        }
     136                        data->ReleaseMutex();
    124137                }
    125138        }
     
    127140}
    128141
    129 void Camera::SaveToFile(string filename) const {
     142void Camera::SavePictureToFile(std::string filename) const {
     143        string::size_type idx = filename.rfind('.');
     144
     145        if(idx != std::string::npos) {
     146                Printf("saving %s\n", filename.c_str());
     147                std::string extension = filename.substr(idx+1);
     148               
     149                output->GetMutex();
     150                if(extension=="jpg") {
     151                        if(output->GetDataType().GetFormat()==cvimage::Type::Format::Gray) saveToJpeg(output->img,filename,PictureFormat_t::Gray,PictureFormat_t::Gray);
     152                        if(output->GetDataType().GetFormat()==cvimage::Type::Format::BGR) saveToJpeg(output->img,filename,PictureFormat_t::RGB,PictureFormat_t::RGB);
     153                        if(output->GetDataType().GetFormat()==cvimage::Type::Format::UYVY) saveToJpeg(output->img,filename,PictureFormat_t::UYVY,PictureFormat_t::UYVY);
     154                } else {
     155                        cvSaveImage(filename.c_str(),output->img);
     156                }
     157                output->ReleaseMutex();
     158                       
     159        } else {
     160                Warn("saving %s no file extension!\n", filename.c_str());
     161        }
     162}
     163
     164void Camera::SaveRawPictureToFile(string filename) const {
    130165  Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
    131166  std::ofstream pFile;
  • trunk/lib/FlairSensorActuator/src/Camera.h

    r122 r124  
    9292
    9393  /*!
     94  * \brief Save raw picture to file
     95  *
     96  * \param filename filename
     97  */
     98  void SaveRawPictureToFile(std::string filename) const;
     99       
     100        /*!
    94101  * \brief Save picture to file
    95102  *
    96103  * \param filename filename
    97104  */
    98   void SaveToFile(std::string filename) const;
     105  void SavePictureToFile(std::string filename) const;
    99106
    100107  /*!
  • trunk/lib/FlairSensorActuator/src/V4LCamera.cpp

    r15 r124  
    4343    Thread::Err("cvCaptureFromCAM error\n");
    4444
    45   if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width) < 0)
     45  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width)<0)
    4646    Thread::Err("cvSetCaptureProperty error\n");
    47   if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height) < 0)
     47  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height)<0)
    4848    Thread::Err("cvSetCaptureProperty error\n");
    4949
    5050  if (format == cvimage::Type::Format::UYVY) {
    51     if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY) <
    52         0)
     51    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY)<0)
    5352      Thread::Err("cvSetCaptureProperty error\n");
    5453  } else if (format == cvimage::Type::Format::YUYV) {
  • trunk/lib/FlairVisionFilter/src/CvtColor.cpp

    r122 r124  
    2525
    2626    switch(conversion) {
    27     case Conversion_t::GRAY:
     27    case Conversion_t::ToGray:
    2828        try{
    2929            cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
    30             output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::GRAY,"conversion",true,2);
     30            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::Gray,"conversion",true,2);
    3131
    3232        } catch(std::bad_cast& bc) {
     
    6161
    6262    switch(conversion) {
    63     case Conversion_t::GRAY:
     63    case Conversion_t::ToGray:
    6464        switch(((cvimage*)data)->GetDataType().GetFormat()) {
    6565        case cvimage::Type::Format::YUYV:
  • trunk/lib/FlairVisionFilter/src/CvtColor.h

    r122 r124  
    3939            */
    4040            enum class Conversion_t {
    41                 BGR,/*!< BGR 24 bits */
    42                 GRAY,/*!< gray 8 bits */
     41                ToBGR,/*!< BGR 24 bits */
     42                ToGray,/*!< gray 8 bits */
    4343                } ;
    4444
  • trunk/lib/FlairVisionFilter/src/HoughLines.cpp

    r122 r124  
    5353    try{
    5454        cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
    55         if(imageType.GetFormat()!=cvimage::Type::Format::GRAY) {
    56             Err("input image is not grey\n");
     55        if(imageType.GetFormat()!=cvimage::Type::Format::Gray) {
     56            Err("input image is not gray\n");
    5757        }
    5858    } catch(std::bad_cast& bc) {
  • trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp

    r122 r124  
    3232    try{
    3333        cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
    34         if(imageType.GetFormat()==cvimage::Type::Format::GRAY) {
     34        if(imageType.GetFormat()==cvimage::Type::Format::Gray) {
    3535            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
    3636        } else {
    37             Err("input image is not grey\n");
     37            Err("input image is not gray\n");
    3838        }
    3939    } catch(std::bad_cast& bc) {
  • trunk/lib/FlairVisionFilter/src/Sobel.cpp

    r122 r124  
    3434    try{
    3535        cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
    36         if(imageType.GetFormat()==cvimage::Type::Format::GRAY) {
     36        if(imageType.GetFormat()==cvimage::Type::Format::Gray) {
    3737            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
    3838        } else {
    39             Err("input image is not grey\n");
     39            Err("input image is not gray\n");
    4040        }
    4141
  • trunk/lib/FlairVisionFilter/src/VisionFilter.cpp

    r123 r124  
    99}
    1010
    11 void saveToJpeg(IplImage* src_img,std::string filename,unsigned char compression_level) {
     11void saveToJpeg(IplImage* src_img,std::string filename,PictureFormat_t input_format,PictureFormat_t output_format,unsigned char compression_level) {
    1212        if(!cvSaveImage(filename.c_str(),src_img)) printf("Could not save.\n");
    1313}
  • trunk/lib/FlairVisionFilter/src/VisionFilter.h

    r123 r124  
    1212void CloseVisionFilter(void);
    1313
    14 void saveToJpeg(IplImage* src_img,std::string filename,unsigned char compression_level=95);
     14enum class PictureFormat_t {
     15                Gray,/*!< gray 8 bits */
     16                                                                RGB,/*!< rgb 24 bits */
     17                                                                UYVY,/*!< YUV 4:2:2 planer */
     18                } ;
     19                                                               
     20void saveToJpeg(IplImage* src_img,std::string filename,PictureFormat_t input_format,PictureFormat_t output_format,unsigned char compression_level=95);
  • trunk/lib/FlairVisionFilter/src/unexported/compile_info.h

    r123 r124  
    55
    66#define USER "gsanahuj@gsanahuj-Latitude-E6420"
    7 #define DATE "mardi 10 janvier 2017, 15:56:33 (UTC+0100)"
     7#define DATE "jeudi 12 janvier 2017, 09:32:25 (UTC+0100)"
    88#define GCC_REV "4.9.1"
    99#define GCC_PATH "/opt/robomap3/1.7.3/armv7a-neon/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
    1010#define SVN_PATH "/home/gsanahuj/HDS/igep/flair-src_svn/trunk/lib/FlairVisionFilter"
    11 #define SVN_REV "122M"
     11#define SVN_REV "122:123M"
    1212
    1313inline void compile_info(std::string name) {
Note: See TracChangeset for help on using the changeset viewer.