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
00029
00030
00031
00032
00033 #include "sick_laser/capture_image.h"
00034
00035 using namespace FlyCapture2;
00036
00037 CameraCapture::CameraCapture ()
00038 {
00039 m_videomode_ = VIDEOMODE_1280x960Y8;
00040 m_framerate_ = FRAMERATE_15;
00041 m_wfile_.open ("imagetimestamp.txt");
00042 if (m_wfile_.is_open ())
00043 {
00044 ROS_INFO ("open the file ok!");
00045 }
00046 else
00047 {
00048 ROS_INFO ("open the file fail!");
00049
00050 return;
00051 }
00052 }
00053
00054 CameraCapture::~CameraCapture ()
00055 {
00056
00057 }
00058
00059 void CameraCapture::camPrintBuildInfo ()
00060 {
00061 FC2Version fc2Version;
00062 Utilities::GetLibraryVersion (&fc2Version);
00063 char version[128];
00064
00065 sprintf (version,
00066 "FlyCapture2 library version: %d.%d.%d.%d",
00067 fc2Version.major, fc2Version.minor, fc2Version.type, fc2Version.build);
00068
00069 ROS_INFO ("%s", version);
00070
00071 char timeStamp[512];
00072 sprintf (timeStamp, "Application build date: %s %s", __DATE__, __TIME__);
00073
00074 ROS_INFO ("%s", timeStamp);
00075 }
00076
00077 void CameraCapture::camPrintCameraInfo (CameraInfo * cam_info)
00078 {
00079 ROS_INFO ("\n*** CAMERA INFORMATION ***\n"
00080 "Serial number - %u\n"
00081 "Camera model - %s\n"
00082 "Camera vendor - %s\n"
00083 "Sensor - %s\n"
00084 "Resolution - %s\n"
00085 "Firmware version - %s\n"
00086 "Firmware build time - %s\n\n",
00087 cam_info->serialNumber,
00088 cam_info->modelName,
00089 cam_info->vendorName,
00090 cam_info->sensorInfo, cam_info->sensorResolution, cam_info->firmwareVersion, cam_info->firmwareBuildTime);
00091 }
00092
00093 void CameraCapture::camPrintError (Error error)
00094 {
00095 error.PrintErrorTrace ();
00096 }
00097
00098 void CameraCapture::camConnect ()
00099 {
00100 Error error;
00101 error = m_bus_mgr_.GetCameraFromIndex (0, &m_guid_);
00102
00103 if (error != PGRERROR_OK)
00104 {
00105 camPrintError (error);
00106
00107 return;
00108 }
00109
00110 error = m_cam_.Connect (&m_guid_);
00111 if (error != PGRERROR_OK)
00112 {
00113 camPrintError (error);
00114
00115 return;
00116 }
00117 else
00118 ROS_INFO ("camera is connected!");
00119
00120
00121 error = m_cam_.SetVideoModeAndFrameRate (m_videomode_, m_framerate_);
00122 if (error != PGRERROR_OK)
00123 {
00124 camPrintError (error);
00125
00126 return;
00127 }
00128 else
00129 {
00130 ROS_INFO ("set the camera OK !");
00131 }
00132
00133
00134 CameraInfo camInfo;
00135 error = m_cam_.GetCameraInfo (&camInfo);
00136 if (error != PGRERROR_OK)
00137 {
00138 camPrintError (error);
00139
00140 return;
00141 }
00142
00143 camPrintCameraInfo (&camInfo);
00144
00145 error = m_cam_.StartCapture ();
00146 if (error != PGRERROR_OK)
00147 {
00148 camPrintError (error);
00149
00150 return;
00151 }
00152
00153 }
00154
00155 void CameraCapture::camImageCapture (int img_num)
00156 {
00157 Error error;
00158 Image rawImage;
00159 while (m_cam_.RetrieveBuffer (&rawImage) != PGRERROR_OK)
00160 {
00161
00162 continue;
00163 }
00164
00165
00166 double time_now = ros::Time::now ().toSec ();
00167 char buf[50];
00168 bzero (buf, sizeof (buf));
00169 sprintf (buf, "%lf", time_now);
00170 m_wfile_ << buf << "\n";
00171
00172
00173 Image convertedImage;
00174 error = rawImage.Convert (PIXEL_FORMAT_BGR, &convertedImage);
00175 if (error != PGRERROR_OK)
00176 {
00177 camPrintError (error);
00178
00179 return;
00180 }
00181
00182
00183 char filename[512];
00184 sprintf (filename, "image%d.bmp", img_num);
00185
00186
00187
00188 error = convertedImage.Save (filename);
00189 if (error != PGRERROR_OK)
00190 {
00191 camPrintError (error);
00192
00193 return;
00194 }
00195 else
00196 {
00197 ROS_INFO ("Have saved %d pictures", img_num + 1);
00198 }
00199 }
00200
00201 void CameraCapture::camStopCapture ()
00202 {
00203
00204 Error error;
00205 error = m_cam_.StopCapture ();
00206 if (error != PGRERROR_OK)
00207 {
00208 camPrintError (error);
00209
00210 return;
00211 }
00212
00213
00214 error = m_cam_.Disconnect ();
00215 if (error != PGRERROR_OK)
00216 {
00217 camPrintError (error);
00218
00219 return;
00220 }
00221
00222 m_wfile_.close ();
00223 }