2 #include <boost/thread/thread.hpp>     5 #include "ImiProperties.h"    26                 color_video_started_(0),
    27                 depth_video_started_(0),
    28                 uvc_video_started_(0),
    50                 if (0 != imiInitialize(NULL))
    57                 uint32_t deviceCount = 0;
    61                         ROS_WARN(
"Get No Connected Imidevice!\n");
    64                 ROS_WARN(
"Get %d Connected Imidevice.\n", deviceCount);
    69                         ROS_WARN(
"Open Imidevice Failed!\n");
    75         float cameraParams[4];
    76         uint32_t nLen = 
sizeof(float)*4;
    77         int32_t ret = imiGetDeviceProperty(
pImiDevice, IMI_PROPERTY_COLOR_INTRINSIC_PARAMS, (
void*)cameraParams, &nLen);
    80                 m_fx = cameraParams[0];
    81             m_fy = cameraParams[1];
    82                         m_cx = cameraParams[2];
    83             m_cy = cameraParams[3];
    98                 boost::thread depthThread(
readFrame, 
this);
   108                 cloudPtr->width = pFrame->height * pFrame->width;
   109                 cloudPtr->height = 1;
   111         cloudPtr->header.frame_id = 
"IMI_CloudPoints";
   115                                    "y", 1, sensor_msgs::PointField::FLOAT32,
   116                                    "z", 1, sensor_msgs::PointField::FLOAT32);
   124                 uint16_t* pData = (uint16_t *)pFrame->pData;
   125                 for (
int j=0; j<pFrame->height; j++)
   127                 for (
int i=0; i<pFrame->width; i++)
   129                                 uint16_t dp = pData[j*pFrame->width + i];
   164                                 boost::this_thread::sleep(boost::posix_time::milliseconds(500));
   170             int32_t g_streamNum = 0;
   171             ImiStreamHandle g_streams[2];
   184                         int32_t avStreamIndex;
   185                         if (0 != imiWaitForStreams(g_streams, g_streamNum, &avStreamIndex, 100))
   187                                 boost::this_thread::sleep(boost::posix_time::milliseconds(50));
   191                         if ((avStreamIndex < 0) || ((uint32_t)avStreamIndex >= g_streamNum))
   193                                 ROS_WARN(
"imiWaitForStream returns 0, but channel index abnormal: %d\n", avStreamIndex);
   197                         ImiImageFrame* pFrame = NULL;
   198                         if (0 != imiReadNextFrame(g_streams[avStreamIndex], &pFrame, 0))
   200                                 ROS_WARN(
"imiReadNextFrame Failed, channel index : %d\n", avStreamIndex);
   204                         sensor_msgs::ImagePtr image(
new sensor_msgs::Image);
   210                                 uint64_t device_time = pFrame->timeStamp;
   212                                 double device_time_in_sec = 
static_cast<double>(device_time) / 1000000.0;
   214                                 image->header.stamp.fromSec(device_time_in_sec);
   216                                 image->width = pFrame->width;
   217                                 image->height = pFrame->height;
   219                                 std::size_t data_size = pFrame->size;
   221                                 image->data.resize(data_size);
   222                                 memcpy(&image->data[0], pFrame->pData, data_size);
   224                                 image->is_bigendian = 0;
   228                         if (pFrame->pixelFormat==IMI_PIXEL_FORMAT_IMAGE_RGB24 && pIMi->
colorCallback!=NULL)
   230                 image->header.frame_id = 
"IMI_RGB_Image";
   232                                 image->step = 
sizeof(
unsigned char) * 3 * image->width;
   237                         if (pFrame->pixelFormat == IMI_PIXEL_FORMAT_DEP_16BIT)
   242                                         image->header.frame_id = 
"IMI_DEPTH_Image";
   244                                         image->step = 
sizeof(
unsigned char) * 2 * image->width;
   254                         imiReleaseFrame(&pFrame);
   267                                 boost::this_thread::sleep(boost::posix_time::milliseconds(500));
   271             boost::lock_guard<boost::mutex> lock(pIMi->
uvc_mutex_);
   273             ImiCameraFrame* uvcFrame = NULL;
   274                 int ret = imiCamReadNextFrame(pIMi->
camHandle, &uvcFrame, 40);
   275                         if (ret!=0 || uvcFrame==NULL)
   282                         sensor_msgs::ImagePtr image(
new sensor_msgs::Image);
   285                         uint64_t device_time = uvcFrame->timeStamp;
   287                         double device_time_in_sec = 
static_cast<double>(device_time) / 1000000.0;
   289                         image->header.stamp.fromSec(device_time_in_sec);
   293                         image->width = uvcFrame->width;
   294                         image->height = uvcFrame->height;
   296                         std::size_t data_size = uvcFrame->size;
   298                         image->data.resize(data_size);
   299                         memcpy(&image->data[0], uvcFrame->pData, data_size);
   301                         image->is_bigendian = 0;
   304             image->header.frame_id = 
"IMI_UVC_Image";
   306                         image->step = 
sizeof(
unsigned char) * 3 * image->width;
   314                         imiCamReleaseFrame(&uvcFrame);
   348                 sensor_msgs::CameraInfoPtr info = boost::make_shared<sensor_msgs::CameraInfo>();
   351                 info->height = height;
   354                 info->D.resize(5, 0.0);
   367                 info->R[0] = info->R[4] = info->R[8] = 1.0;
   438         boost::lock_guard<boost::mutex> lock(
uvc_mutex_);
   461                         printf(
"already Open Color Stream Success.\n");
   465                 imiSetFrameMode(
pImiDevice, IMI_COLOR_FRAME, &colorframeMode);
   469                         ROS_WARN(
"Open Color Stream Failed!\n");
   473                 printf(
"Open Color Stream Success.\n");
   480         boost::lock_guard<boost::mutex> lock(
uvc_mutex_);
   485                         ROS_WARN(
"already Open UVC Stream Success.\n");
   489                 if (0 != imiCamStartStream(
camHandle, &uvcframeMode))
   491                         ROS_WARN(
"imiCamStartStream Failed!\n");
   495                 printf(
"Open UVC Stream Success.\n");
   506                         printf(
"already Open Depth Stream Success.\n");
   510                 imiSetFrameMode(
pImiDevice, IMI_DEPTH_FRAME, &frameMode);
   512         if (frameMode.resolutionX==640 && frameMode.resolutionY==480)
   529                         ROS_WARN(
"Open Depth Stream Failed!\n");
   533                 printf(
"Open Depth Stream Success.\n");
   581         boost::lock_guard<boost::mutex> lock(
uvc_mutex_);
 ImiDeviceAttribute * pDeviceAttr
static const double imi_fx
static int readUVCFrame(void *lParam)
void setUVCFrameCallback(FrameCallbackFunction callback)
ImiCameraHandle camHandle
FrameCallbackFunction depthCallback
ImiStreamHandle colorHandle
bool hasDepthSensor() const 
static const double imi_cx
void convertToCloudPoint(ImiImageFrame *pFrame)
void setPointCloud2Fields(int n_fields,...)
const std::string getUri() const 
int startDepthStream(ImiFrameMode depthFrameMode)
int startColorStream(ImiFrameMode colorFrameMode)
boost::function< void(sensor_msgs::ImagePtr image)> FrameCallbackFunction
void setCloudPointCallback(CloudCallbackFunction callback)
static const double imi_fy
FrameCallbackFunction colorCallback
CloudCallbackFunction cloudCallback
ImiDeviceHandle pImiDevice
static const double imi_factor
FrameCallbackFunction uvcCallback
boost::mutex device_mutex_
const std::string PLUMB_BOB
int startUVCStream(ImiCameraFrameMode uvcframeMode)
const std::string TYPE_16UC1
uint16_t getUsbVendorId() const 
bool hasColorSensor() const 
void setColorFrameCallback(FrameCallbackFunction callback)
sensor_msgs::CameraInfoPtr getDefaultCameraInfo(int width, int height)
void setDepthFrameCallback(FrameCallbackFunction callback)
static int readFrame(void *lParam)
boost::function< void(boost::shared_ptr< sensor_msgs::PointCloud2 > cloudPtr)> CloudCallbackFunction
uint16_t getUsbProductId() const 
void setPointCloud2FieldsByString(int n_fields,...)
bool hasUVCSensor() const 
static const double imi_cy
ImiStreamHandle depthHandle