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
00029
00030
00031
00032
00033
00034
00036
00037 #include <laser_cb_detector/cv_laser_bridge.h>
00038
00039 using namespace laser_cb_detector;
00040
00041 bool CvLaserBridge::fromIntensity(const calibration_msgs::DenseLaserSnapshot& snapshot, float min_val, float max_val)
00042 {
00043 if (snapshot.num_scans * snapshot.readings_per_scan != snapshot.intensities.size())
00044 {
00045 ROS_ERROR("Got malformed snapshot. Expected [%u x %u]=%u, but snapshot.intensities.size()=%u",
00046 snapshot.num_scans, snapshot.readings_per_scan,
00047 snapshot.num_scans * snapshot.readings_per_scan,
00048 snapshot.intensities.size());
00049 return false;
00050 }
00051
00052 fromSnapshot(snapshot, snapshot.intensities, min_val, max_val);
00053 return true;
00054 }
00055
00056 bool CvLaserBridge::reallocIfNeeded(IplImage** img, CvSize sz)
00057 {
00058 int depth = IPL_DEPTH_8U;
00059 int channels = 1;
00060
00061 if ((*img) != 0)
00062 {
00063 if ((*img)->width != sz.width ||
00064 (*img)->height != sz.height ||
00065 (*img)->depth != depth ||
00066 (*img)->nChannels != channels)
00067 {
00068 cvReleaseImage(img);
00069 *img = 0;
00070 }
00071 }
00072
00073 if (*img == 0)
00074 {
00075 *img = cvCreateImage(sz, depth, channels);
00076 return true;
00077 }
00078 return false;
00079 }
00080
00081 void CvLaserBridge::fromSnapshot(const calibration_msgs::DenseLaserSnapshot& snapshot, const std::vector<float>& src, float min_val, float max_val)
00082 {
00083 assert(snapshot.num_scans * snapshot.readings_per_scan == src.size());
00084
00085 CvMat cvmHeader;
00086
00087 IplImage source_image;
00088
00089 cvInitMatHeader(&cvmHeader, snapshot.num_scans, snapshot.readings_per_scan, CV_32FC1, const_cast<float*>(&(src[0])));
00090 cvGetImage(&cvmHeader, &source_image);
00091
00092 reallocIfNeeded(&dest_image_, cvSize(source_image.width, source_image.height) );
00093
00094 double range = (max_val - min_val);
00095 double scale = 255/range;
00096 double shift = -min_val * 255/range;
00097
00098 ROS_DEBUG("Scale: %f Shift: %f\n", scale, shift);
00099
00100 cvConvertScale(&source_image, dest_image_, scale, shift);
00101 }