Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/core/Camera.h"
00029
00030 #include <rtabmap/utilite/UEventsManager.h>
00031 #include <rtabmap/utilite/UConversion.h>
00032 #include <rtabmap/utilite/UStl.h>
00033 #include <rtabmap/utilite/UConversion.h>
00034 #include <rtabmap/utilite/UFile.h>
00035 #include <rtabmap/utilite/UDirectory.h>
00036 #include <rtabmap/utilite/UTimer.h>
00037
00038 #include <opencv2/imgproc/imgproc.hpp>
00039
00040 #include <iostream>
00041 #include <cmath>
00042
00043 namespace rtabmap
00044 {
00045
00046 Camera::Camera(float imageRate, const Transform & localTransform) :
00047 _imageRate(imageRate),
00048 _localTransform(localTransform),
00049 _targetImageSize(0,0),
00050 _frameRateTimer(new UTimer()),
00051 _seq(0)
00052 {
00053 }
00054
00055 Camera::~Camera()
00056 {
00057 UDEBUG("");
00058 delete _frameRateTimer;
00059 UDEBUG("");
00060 }
00061
00062 SensorData Camera::takeImage(CameraInfo * info)
00063 {
00064 bool warnFrameRateTooHigh = false;
00065 float actualFrameRate = 0;
00066 if(_imageRate>0)
00067 {
00068 int sleepTime = (1000.0f/_imageRate - 1000.0f*_frameRateTimer->getElapsedTime());
00069 if(sleepTime > 2)
00070 {
00071 uSleep(sleepTime-2);
00072 }
00073 else if(sleepTime < 0)
00074 {
00075 warnFrameRateTooHigh = true;
00076 actualFrameRate = 1.0/(_frameRateTimer->getElapsedTime());
00077 }
00078
00079
00080 while(_frameRateTimer->getElapsedTime() < 1.0/double(_imageRate)-0.000001)
00081 {
00082
00083 }
00084
00085 double slept = _frameRateTimer->getElapsedTime();
00086 _frameRateTimer->start();
00087 UDEBUG("slept=%fs vs target=%fs", slept, 1.0/double(_imageRate));
00088 }
00089
00090 UTimer timer;
00091 SensorData data = this->captureImage(info);
00092 double captureTime = timer.ticks();
00093 if(warnFrameRateTooHigh)
00094 {
00095 UWARN("Camera: Cannot reach target image rate %f Hz, current rate is %f Hz and capture time = %f s.",
00096 _imageRate, actualFrameRate, captureTime);
00097 }
00098 else
00099 {
00100 UDEBUG("Time capturing image = %fs", captureTime);
00101 }
00102 if(info)
00103 {
00104 info->id = data.id();
00105 info->stamp = data.stamp();
00106 info->timeCapture = captureTime;
00107 }
00108 return data;
00109 }
00110
00111 }