mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-08 12:30:20 +08:00
support color histogram equalization (#1203)
This commit is contained in:
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "rtabmap/core/IMUFilter.h"
|
#include "rtabmap/core/IMUFilter.h"
|
||||||
#include "rtabmap/core/Features2d.h"
|
#include "rtabmap/core/Features2d.h"
|
||||||
#include "rtabmap/core/clams/discrete_depth_distortion_model.h"
|
#include "rtabmap/core/clams/discrete_depth_distortion_model.h"
|
||||||
|
#include <opencv2/imgproc/types_c.h>
|
||||||
#include <opencv2/stitching/detail/exposure_compensate.hpp>
|
#include <opencv2/stitching/detail/exposure_compensate.hpp>
|
||||||
#include <rtabmap/utilite/UTimer.h>
|
#include <rtabmap/utilite/UTimer.h>
|
||||||
#include <rtabmap/utilite/ULogger.h>
|
#include <rtabmap/utilite/ULogger.h>
|
||||||
@@ -542,15 +543,25 @@ void CameraThread::postUpdate(SensorData * dataPtr, CameraInfo * info) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(_histogramMethod && !data.imageRaw().empty())
|
if(_histogramMethod && !data.imageRaw().empty())
|
||||||
{
|
|
||||||
if(data.imageRaw().type() == CV_8UC1)
|
|
||||||
{
|
{
|
||||||
UDEBUG("");
|
UDEBUG("");
|
||||||
UTimer timer;
|
UTimer timer;
|
||||||
cv::Mat image;
|
cv::Mat image;
|
||||||
if(_histogramMethod == 1)
|
if(_histogramMethod == 1)
|
||||||
|
{
|
||||||
|
if(data.imageRaw().type() == CV_8UC1)
|
||||||
{
|
{
|
||||||
cv::equalizeHist(data.imageRaw(), image);
|
cv::equalizeHist(data.imageRaw(), image);
|
||||||
|
}
|
||||||
|
else if(data.imageRaw().type() == CV_8UC3)
|
||||||
|
{
|
||||||
|
cv::Mat channels[3];
|
||||||
|
cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb);
|
||||||
|
cv::split(image, channels);
|
||||||
|
cv::equalizeHist(channels[0], channels[0]);
|
||||||
|
cv::merge(channels, 3, image);
|
||||||
|
cv::cvtColor(image, image, CV_YCrCb2BGR);
|
||||||
|
}
|
||||||
if(!data.depthRaw().empty())
|
if(!data.depthRaw().empty())
|
||||||
{
|
{
|
||||||
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
|
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
|
||||||
@@ -558,14 +569,38 @@ void CameraThread::postUpdate(SensorData * dataPtr, CameraInfo * info) const
|
|||||||
else if(!data.rightRaw().empty())
|
else if(!data.rightRaw().empty())
|
||||||
{
|
{
|
||||||
cv::Mat right;
|
cv::Mat right;
|
||||||
|
if(data.rightRaw().type() == CV_8UC1)
|
||||||
|
{
|
||||||
cv::equalizeHist(data.rightRaw(), right);
|
cv::equalizeHist(data.rightRaw(), right);
|
||||||
|
}
|
||||||
|
else if(data.rightRaw().type() == CV_8UC3)
|
||||||
|
{
|
||||||
|
cv::Mat channels[3];
|
||||||
|
cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb);
|
||||||
|
cv::split(right, channels);
|
||||||
|
cv::equalizeHist(channels[0], channels[0]);
|
||||||
|
cv::merge(channels, 3, right);
|
||||||
|
cv::cvtColor(right, right, CV_YCrCb2BGR);
|
||||||
|
}
|
||||||
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
|
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(_histogramMethod == 2)
|
else if(_histogramMethod == 2)
|
||||||
{
|
{
|
||||||
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(3.0);
|
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(3.0);
|
||||||
|
if(data.imageRaw().type() == CV_8UC1)
|
||||||
|
{
|
||||||
clahe->apply(data.imageRaw(), image);
|
clahe->apply(data.imageRaw(), image);
|
||||||
|
}
|
||||||
|
else if(data.imageRaw().type() == CV_8UC3)
|
||||||
|
{
|
||||||
|
cv::Mat channels[3];
|
||||||
|
cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb);
|
||||||
|
cv::split(image, channels);
|
||||||
|
clahe->apply(channels[0], channels[0]);
|
||||||
|
cv::merge(channels, 3, image);
|
||||||
|
cv::cvtColor(image, image, CV_YCrCb2BGR);
|
||||||
|
}
|
||||||
if(!data.depthRaw().empty())
|
if(!data.depthRaw().empty())
|
||||||
{
|
{
|
||||||
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
|
data.setRGBDImage(image, data.depthRaw(), data.cameraModels());
|
||||||
@@ -573,17 +608,24 @@ void CameraThread::postUpdate(SensorData * dataPtr, CameraInfo * info) const
|
|||||||
else if(!data.rightRaw().empty())
|
else if(!data.rightRaw().empty())
|
||||||
{
|
{
|
||||||
cv::Mat right;
|
cv::Mat right;
|
||||||
|
if(data.rightRaw().type() == CV_8UC1)
|
||||||
|
{
|
||||||
clahe->apply(data.rightRaw(), right);
|
clahe->apply(data.rightRaw(), right);
|
||||||
|
}
|
||||||
|
else if(data.rightRaw().type() == CV_8UC3)
|
||||||
|
{
|
||||||
|
cv::Mat channels[3];
|
||||||
|
cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb);
|
||||||
|
cv::split(right, channels);
|
||||||
|
clahe->apply(channels[0], channels[0]);
|
||||||
|
cv::merge(channels, 3, right);
|
||||||
|
cv::cvtColor(right, right, CV_YCrCb2BGR);
|
||||||
|
}
|
||||||
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
|
data.setStereoImage(image, right, data.stereoCameraModels()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(info) info->timeHistogramEqualization = timer.ticks();
|
if(info) info->timeHistogramEqualization = timer.ticks();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
UWARN("Histogram equalization only supports grayscale images...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_stereoExposureCompensation && !data.imageRaw().empty() && !data.rightRaw().empty())
|
if(_stereoExposureCompensation && !data.imageRaw().empty() && !data.rightRaw().empty())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user