int sortCallback(const void * aa, const void * bb) { const struct dirent ** a = (const struct dirent **)aa; const struct dirent ** b = (const struct dirent **)bb; return uStrNumCmp((*a)->d_name, (*b)->d_name); }
cv::Mat CameraImages::captureImage() { UDEBUG(""); cv::Mat img; if(_dir->isValid()) { if(_refreshDir) { _dir->update(); } if(_startAt == 0) { const std::list<std::string> & fileNames = _dir->getFileNames(); if(fileNames.size()) { if(_lastFileName.empty() || uStrNumCmp(_lastFileName,*fileNames.rbegin()) < 0) { _lastFileName = *fileNames.rbegin(); std::string fullPath = _path + _lastFileName; img = cv::imread(fullPath.c_str()); } } } else { std::string fileName; std::string fullPath; fileName = _dir->getNextFileName(); if(fileName.size()) { fullPath = _path + fileName; while(++_count < _startAt && (fileName = _dir->getNextFileName()).size()) { fullPath = _path + fileName; } if(fileName.size()) { ULOGGER_DEBUG("Loading image : %s", fullPath.c_str()); #if CV_MAJOR_VERSION >=2 and CV_MINOR_VERSION >=4 img = cv::imread(fullPath.c_str(), cv::IMREAD_UNCHANGED); #else img = cv::imread(fullPath.c_str(), -1); #endif UDEBUG("width=%d, height=%d, channels=%d, elementSize=%d, total=%d", img.cols, img.rows, img.channels(), img.elemSize(), img.total()); // FIXME : it seems that some png are incorrectly loaded with opencv c++ interface, where c interface works... if(img.depth() != CV_8U) { // The depth should be 8U UWARN("Cannot read the image correctly, falling back to old OpenCV C interface..."); IplImage * i = cvLoadImage(fullPath.c_str()); img = cv::Mat(i, true); cvReleaseImage(&i); } } } } } else { UWARN("Directory is not set, camera must be initialized."); } unsigned int w; unsigned int h; this->getImageSize(w, h); if(!img.empty() && w && h && w != (unsigned int)img.cols && h != (unsigned int)img.rows) { cv::Mat resampled; cv::resize(img, resampled, cv::Size(w, h)); img = resampled; } return img; }
int sortCallback( const dirent ** a, const dirent ** b) { return uStrNumCmp((*a)->d_name, (*b)->d_name); }
bool sortCallback(const std::string & a, const std::string & b) { return uStrNumCmp(a,b) < 0; }