bool ClassificationDataStream::addSample(const UINT classLabel,const MatrixFloat &sample){ if( numDimensions != sample.getNumCols() ){ errorLog << "addSample(const UINT classLabel, const MatrixFloat &sample) - the number of columns in the sample (" << sample.getNumCols() << ") does not match the number of dimensions of the dataset (" << numDimensions << ")" << std::endl; return false; } bool searchForNewClass = true; if( trackingClass ){ if( classLabel != lastClassID ){ //The class ID has changed so update the time series tracker timeSeriesPositionTracker[ timeSeriesPositionTracker.size()-1 ].setEndIndex( totalNumSamples-1 ); }else searchForNewClass = false; } if( searchForNewClass ){ bool newClass = true; //Search to see if this class has been found before for(UINT k=0; k<classTracker.size(); k++){ if( classTracker[k].classLabel == classLabel ){ newClass = false; classTracker[k].counter += sample.getNumRows(); } } if( newClass ){ ClassTracker newCounter(classLabel,1); classTracker.push_back( newCounter ); } //Set the timeSeriesPositionTracker start position trackingClass = true; lastClassID = classLabel; TimeSeriesPositionTracker newTracker(totalNumSamples,0,classLabel); timeSeriesPositionTracker.push_back( newTracker ); } ClassificationSample labelledSample( numDimensions ); for(UINT i=0; i<sample.getNumRows(); i++){ data.push_back( labelledSample ); data.back().setClassLabel( classLabel ); for(UINT j=0; j<numDimensions; j++){ data.back()[j] = sample[i][j]; } } totalNumSamples += sample.getNumRows(); return true; }
bool Registry::registerTrackerType(std::string name, std::shared_ptr<NewTrackerFactory> f) { if (m_typeByString.find(name) != m_typeByString.end()) { //throw std::invalid_argument("Tracker with same name already registered"); Q_EMIT trackerIsAlreadyLoaded(name); return false; } else { const TrackerType type = getNextId(); m_typeByString.emplace(name, type); m_stringByType.emplace(type, name); m_trackerByType.emplace(type, f); Q_EMIT newTracker(type); return true; } }
bool TimeSeriesClassificationDataStream::addSample(const UINT classLabel,const VectorDouble &sample){ if( numDimensions != sample.size() ){ errorLog << "addSample(const UINT classLabel, vector<double> sample) - the size of the new sample (" << sample.size() << ") does not match the number of dimensions of the dataset (" << numDimensions << ")" << endl; return false; } bool searchForNewClass = true; if( trackingClass ){ if( classLabel != lastClassID ){ //The class ID has changed so update the time series tracker timeSeriesPositionTracker[ timeSeriesPositionTracker.size()-1 ].setEndIndex( totalNumSamples-1 ); }else searchForNewClass = false; } if( searchForNewClass ){ bool newClass = true; //Search to see if this class has been found before for(UINT k=0; k<classTracker.size(); k++){ if( classTracker[k].classLabel == classLabel ){ newClass = false; classTracker[k].counter++; } } if( newClass ){ ClassTracker newCounter(classLabel,1); classTracker.push_back( newCounter ); } //Set the timeSeriesPositionTracker start position trackingClass = true; lastClassID = classLabel; TimeSeriesPositionTracker newTracker(totalNumSamples,0,classLabel); timeSeriesPositionTracker.push_back( newTracker ); } ClassificationSample labelledSample(classLabel,sample); data.push_back( labelledSample ); totalNumSamples++; return true; }
void rgb_pcl::getTracker(std::vector<PointCloudPtr> object_clouds, Mat displayImage){ //Assign tracker to the clouds for(unsigned int count1 = 0; count1 < trackerList.size(); count1++){ cv::Point3d position(0, 0, 0); double maxScore = 0; int id_cloud = -1; cv::Point3d pos_tracker; int size_tracker; double hue_tracker; for(unsigned int count2 = 0; count2 < object_clouds.size(); count2 ++){ int size = object_clouds[count2]->points.size(); cv::Point3d position(0, 0, 0); double hue = 0; getCloudFeatures(position, hue, object_clouds[count2]); double score = trackerList[count1].isRecognized(position, 0, size); if(score > maxScore){ maxScore = score; id_cloud = count2; pos_tracker = position; size_tracker = size; hue_tracker = hue; } } if(id_cloud != -1){ trackerList[count1].updateTracker(pos_tracker, hue_tracker, size_tracker, object_clouds[id_cloud]); object_clouds.erase(object_clouds.begin()+id_cloud); } } // cout<<trackerList.size()<<endl; //Create new tracker for the remaining clouds for(auto cloudCluster: object_clouds){ int size = object_clouds[0]->points.size(); cv::Point3d position(0, 0, 0); double hue = 0; getCloudFeatures(position, hue, cloudCluster); track_3d newTracker(position, hue, size); trackerList.push_back(newTracker); } //Delete lost tracker and display tracked clouds for(unsigned int count = 0; count < trackerList.size(); count ++){ trackerList[count].step(); if(!trackerList[count].isAlive()){ trackerList.erase(trackerList.begin()+count); count --; }else if(trackerList[count].isFound() && !trackerList[count].isGone()){ #if DISPLAY drawTrackers(displayImage, trackerList[count], to_string(count)); #endif } } }