34 #include <opencv2/imgproc/imgproc.hpp> 35 #include <QtCore/QFile> 43 currentImageIndex_(0),
46 qRegisterMetaType<cv::Mat>(
"cv::Mat");
82 return (
int)
capture_.get(CV_CAP_PROP_FRAME_COUNT);
95 return (
int)
capture_.get(CV_CAP_PROP_POS_FRAMES);
106 else if(
capture_.isOpened() && frame < (int)
capture_.get(CV_CAP_PROP_FRAME_COUNT))
108 capture_.set(CV_CAP_PROP_POS_FRAMES, frame);
163 if( Settings::getCamera_2imageWidth() &&
164 Settings::getCamera_3imageHeight() &&
165 Settings::getCamera_2imageWidth() != img.cols &&
166 Settings::getCamera_3imageHeight() != img.rows)
169 cv::resize(img, resampled, cv::Size(Settings::getCamera_2imageWidth(), Settings::getCamera_3imageHeight()));
187 if(Settings::getCamera_6useTcpCamera())
194 cameraTcpServer_ = 0;
198 UINFO(
"CameraTCP: listening to port %d (IP=%s)",
205 QString path = Settings::getCamera_5mediaPath();
209 QString ext = Settings::getGeneral_imageFormats();
212 UDirectory dir(path.toStdString(), ext.toStdString());
213 const std::list<std::string> & fileNames = dir.
getFileNames();
217 for(std::list<std::string>::const_iterator iter = fileNames.begin(); iter!=fileNames.end(); ++iter)
221 UINFO(
"Camera: Reading %d images from directory \"%s\"...", (
int)
images_.size(), path.toStdString().c_str());
224 UWARN(
"Camera: Directory \"%s\" is empty (no images matching the \"%s\" extensions). " 225 "If you want to disable loading automatically this directory, " 226 "clear the Camera/mediaPath parameter. By default, webcam will be used instead of the directory.",
227 path.toStdString().c_str(),
228 ext.toStdString().c_str());
231 else if(!path.isEmpty())
234 capture_.open(path.toStdString().c_str());
237 UWARN(
"Camera: Cannot open file \"%s\". If you want to disable loading " 238 "automatically this video file, clear the Camera/mediaPath parameter. " 239 "By default, webcam will be used instead of the file.", path.toStdString().c_str());
243 UINFO(
"Camera: Reading from video file \"%s\"...", path.toStdString().c_str());
249 capture_.open(Settings::getCamera_1deviceId());
250 if(Settings::getCamera_2imageWidth() && Settings::getCamera_3imageHeight())
252 capture_.set(CV_CAP_PROP_FRAME_WIDTH,
double(Settings::getCamera_2imageWidth()));
253 capture_.set(CV_CAP_PROP_FRAME_HEIGHT,
double(Settings::getCamera_3imageHeight()));
255 UINFO(
"Camera: Reading from camera device %d...", Settings::getCamera_1deviceId());
261 UERROR(
"Camera: Failed to open a capture object!");
282 if(Settings::getCamera_4imageRate())
284 cameraTimer_.setInterval((
int)(1000.0/Settings::getCamera_4imageRate()));
const std::list< std::string > & getFileNames() const
static std::string separator()
void imageReceived(const cv::Mat &image)
int imagesBuffered() const
void moveToFrame(int frame)
QHostAddress getHostAddress() const
virtual void updateImageRate()
unsigned int currentImageIndex_
Camera(QObject *parent=0)
CameraTcpServer * cameraTcpServer_
ULogger class and convenient macros.
cv::VideoCapture capture_
static bool exists(const std::string &dirPath)
int getCurrentFrameIndex()
QList< std::string > images_