DetectionMetrics icon indicating copy to clipboard operation
DetectionMetrics copied to clipboard

Add support for Recorder Reader

Open vinay0410 opened this issue 6 years ago • 10 comments

See this build log. You will see issues similar to:

/Users/travis/build/JdeRobot/dl-DetectionSuite/DeepLearningSuite/DeepLearningSuiteLib/DatasetConverters/liveReaders/GenericLiveReader.cpp:129:31: warning: adding 'LIVEREADER_IMPLEMENTATIONS' to a string does not append to the string [-Wstring-plus-int]
            LOG(WARNING)<<imp + " is not a valid reader implementation";
                          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/travis/build/JdeRobot/dl-DetectionSuite/DeepLearningSuite/DeepLearningSuiteLib/DatasetConverters/liveReaders/GenericLiveReader.cpp:129:31: note: use array indexing to silence this warning

This error is occurring because a variable of type enum is being appended to a string.

vinay0410 avatar Mar 18 '19 07:03 vinay0410

Okay , will start working on it

sleep-404 avatar Mar 18 '19 07:03 sleep-404

i think we shall replace imp with "recorder" as this is the remaining value of enum imp with value equals to 0

Eng-MohamedHussien avatar Mar 31 '19 09:03 Eng-MohamedHussien

Hi, @teamleader6 your solution will work but is a temporary fix, what if we have multiple values in enum, which are invalid.

I just had a look at the code of RecorderReader.h which isn't currently supported. It wasn't written by me, but after reading it I think we can support it. It is a simple code which reads some images from a path in rgb and depth format.

Using dummy rgb and depth images, see if RecorderReader works. I am changing this issue to add support for already written Recorder Reader if possible. This will also help you to get familiar with the codebase of DetectionSuite.

Feel free to comment below if you face any issues or have any questions.

RecorderReader.cpp is present here.

vinay0410 avatar Mar 31 '19 13:03 vinay0410

@vinay0410 i will work on it

Eng-MohamedHussien avatar Mar 31 '19 14:03 Eng-MohamedHussien

RecorderReader.h:9:10: fatal error: Common/Sample.h: No such file or directory i searched but i didn't found sample.h i don't know is this related to version of c++ or not

Eng-MohamedHussien avatar Apr 04 '19 20:04 Eng-MohamedHussien

It's present here, https://github.com/JdeRobot/dl-DetectionSuite/blob/master/DeepLearningSuite/DeepLearningSuiteLib/Common/Sample.h

RecorderReader.h isn't importing it correctly. Although you need not include it, since it's already present in #include "DatasetConverters/readers/DatasetReader.h" which is included in RecorderReader.h

You may take hint from this file on how it's done https://github.com/JdeRobot/dl-DetectionSuite/blob/master/DeepLearningSuite/DeepLearningSuiteLib/DatasetConverters/liveReaders/CameraReader.h

vinay0410 avatar Apr 05 '19 05:04 vinay0410

test.cpp to support RecorderReader #include #include "RecorderReader.h" int main() { const std::string colorImagePath = "/color_images/"; const std::string depthImagePath = "/depth_images/"; RecorderReader r(colorImagePath,depthImagePath); //std::cout<<r.getNumSamples(); return 0; } g++ test.cpp pkg-config --cflags --libs opencv i get 2 errors after tones of errors at beginning /tmp/cc9i5xOM.o: In function main': test.cpp:(.text+0xad): undefined reference to RecorderReader::RecorderReader(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' test.cpp:(.text+0xc1): undefined reference to `RecorderReader::~RecorderReader()' collect2: error: ld returned 1 exit status

after modifying those files modifying include to the right paths ,..etc

RecorderReader.cpp // // Created by frivas on 16/11/16. //

#include "RecorderReader.h" #include <boost/program_options.hpp> #include <boost/filesystem.hpp> #include <boost/algorithm/string/predicate.hpp> #include "../../Utils/PathHelper.h" #include <boost/algorithm/string/erase.hpp> #include <glog/logging.h> #include "opencv2/opencv.hpp"

RecorderReader::RecorderReader(const std::string &colorImagesPath, const std::string &depthImagesPath):DatasetReader(true), colorPath(colorImagesPath), depthPath(depthImagesPath) { currentIndex=0; syncedData=false; getImagesByIndexes(depthPath,depthIndexes); getImagesByIndexes(colorPath,colorIndexes); }

RecorderReader::RecorderReader(const std::string &dataPath):DatasetReader(true), colorPath(dataPath), depthPath(dataPath) { currentIndex=0; syncedData=true; getImagesByIndexes(dataPath,depthIndexes,"-depth"); getImagesByIndexes(dataPath,colorIndexes,"-rgb"); }

void RecorderReader::getImagesByIndexes(const std::string& path, std::vector& indexes,std::string sufix){ indexes.clear(); if(boost::filesystem::is_directory(path)) {

    boost::filesystem::directory_iterator end_iter;

    for (boost::filesystem::directory_iterator dir_itr(path);
         dir_itr != end_iter; dir_itr++) {

        if (boost::filesystem::is_regular_file(*dir_itr) && dir_itr->path().extension() == ".png") {
            std::string onlyIndexFilename;
            if (not sufix.empty()) {
                std::string filename=dir_itr->path().stem().string();
                if ( ! boost::algorithm::ends_with(filename, sufix)){
                    continue;
                }
                onlyIndexFilename=dir_itr->path().filename().stem().string();
                boost::erase_all(onlyIndexFilename,sufix);
            }
            else{
                onlyIndexFilename=dir_itr->path().filename().stem().string();
            }
            LOG(INFO) << dir_itr->path().string() << std::endl;
            LOG(INFO) << onlyIndexFilename << std::endl;

            indexes.push_back(std::stoi(onlyIndexFilename));
        }
    }
}
if (indexes.empty()){
    DLOG(WARNING) << "No images found in input sample path";
}
std::sort(indexes.begin(), indexes.end());

}

std::string RecorderReader::getPathByIndex(const std::string& path, int id,std::string sufix){ std::stringstream ss; ss << id << sufix << ".png"; std::string pathCompleted = PathHelper::concatPaths(path, ss.str()); return pathCompleted; }

int RecorderReader::closest(std::vector const& vec, int value) { auto const it = std::lower_bound(vec.begin(), vec.end(), value); if (it == vec.end()) { return -1; }

return *it;

}

bool RecorderReader::getNextSample(Sample &sample) { if (this->currentIndex < this->depthIndexes.size()){ int indexValue = this->depthIndexes[currentIndex]; LOG(INFO)<<"Time stamp: " + std::to_string(indexValue);

    cv::Mat colorImage= cv::imread(getPathByIndex(this->colorPath,closest(colorIndexes,indexValue),this->syncedData?"-rgb":""));

// if (!this->syncedData) cv::cvtColor(colorImage,colorImage,cv::COLOR_RGB2BGR);

    sample.setColorImage(colorImage);
    sample.setDepthImage(getPathByIndex(this->depthPath,indexValue,this->syncedData?"-depth":""));
    this->currentIndex++;
    return true;
}
return false;

}

int RecorderReader::getNumSamples() { return (int)this->depthIndexes.size(); }

RecorderReader::~RecorderReader(){

} RecorderReader.h // Created by frivas on 16/11/16. //

#ifndef SAMPLERGENERATOR_RECORDERCONVERTER_H #define SAMPLERGENERATOR_RECORDERCONVERTER_H

#include #include //#include <Common/Sample.h> #include "../readers/DatasetReader.h"

class RecorderReader: public DatasetReader { public: RecorderReader(const std::string& colorImagesPath, const std::string& depthImagesPath); explicit RecorderReader(const std::string& dataPath); bool getNextSample(Sample &sample) override; int getNumSamples(); ~RecorderReader(); // virtual bool getNextSample(Sample &sample);

private: const std::string& depthPath; const std::string& colorPath; bool syncedData; int currentIndex; std::vector depthIndexes; std::vector colorIndexes;

void getImagesByIndexes(const std::string& path, std::vector<int>& indexes, std::string sufix="");
std::string getPathByIndex(const std::string& path,int id, std::string sufix="");
int closest(std::vector<int> const& vec, int value);


    };

    typedef  boost::shared_ptr<RecorderReader> RecorderReaderPtr;

#endif //SAMPLERGENERATOR_RECORDERCONVERTER_H

DatasetReader.h // // Created by frivas on 22/01/17. //

#ifndef SAMPLERGENERATOR_DATASETREADER_H #define SAMPLERGENERATOR_DATASETREADER_H

#include

#include "../../Common/Sample.h" #include <boost/shared_ptr.hpp> #include "../../Common/EvalMatrix.h" #include <glog/logging.h>

class DatasetReader { public: DatasetReader(const bool imagesRequired); virtual bool getNextSample(Sample &sample); virtual bool getNextSamples(std::vector<Sample> &samples, int size ); void filterSamplesByID(std::vectorstd::string filteredIDS); void overWriteClasses(const std::string& from, const std::string& to); int getNumberOfElements(); void resetReaderCounter(); void decrementReaderCounter(const int decrement_by = 1); void incrementReaderCounter(const int increment_by = 1); bool getSampleBySampleID(Sample** sample, const std::string& sampleID); bool getSampleBySampleID(Sample** sample, const long long int sampleID); void printDatasetStats(); virtual bool appendDataset(const std::string& datasetPath, const std::string& datasetPrefix=""); void addSample(Sample sample); std::string getClassNamesFile(); virtual ~DatasetReader();

protected: std::vector<Sample> samples; //std::string datasetPath; int readerCounter; std::string classNamesFile; std::vectorstd::string classNames; bool imagesRequired; unsigned int skip_count = 10; //max Number of annotations that can be skipped if Corresponding images weren't found };

typedef boost::shared_ptr<DatasetReader> DatasetReaderPtr;

#endif //SAMPLERGENERATOR_DATASETREADER_H

Eng-MohamedHussien avatar Apr 05 '19 13:04 Eng-MohamedHussien

You are supposed to integrate this with DetectionSuite and then build using the steps mentioned

vinay0410 avatar Apr 05 '19 15:04 vinay0410

i solved another problem and the problem was in building and i builded well after modifications i did like you said i want ask how can i test RecorderReader now or just you want fixing errors and make pull request with final modifications in files

Eng-MohamedHussien avatar Apr 05 '19 16:04 Eng-MohamedHussien

It is a simple code which reads some images from a path in rgb and depth format.

Using dummy rgb and depth images, see if RecorderReader works.

vinay0410 avatar Apr 05 '19 17:04 vinay0410