48 #include <cvb/cvb/device_factory.hpp> 49 #include <cvb/cvb/utilities/system_info.hpp> 50 #include <cvb/cvb/driver/stream.hpp> 54 #include <opencv2/highgui/highgui.hpp> 55 #include <cv_bridge/cv_bridge.h> 57 #include <sensor_msgs/CameraInfo.h> 63 void callback(
const sensor_msgs::ImageConstPtr& image)
65 std::cout <<
"received an image" << std::endl;
69 sensor_msgs::Image
toImageMsg(
const Cvb::ImagePtr& cvbImg)
72 sensor_msgs::Image rosImg;
73 rosImg.header.frame_id =
"camera";
74 rosImg.height = cvbImg->Height();
75 rosImg.width = cvbImg->Width();
77 rosImg.is_bigendian =
false;
79 auto dataAccess = cvbImg->Plane(0).LinearAccess();
81 rosImg.step = dataAccess.YInc();
84 size_t size = rosImg.width * 3 * rosImg.height;
85 unsigned char * start =
reinterpret_cast<unsigned char*
>(dataAccess.BasePtr());
86 rosImg.data = std::vector<unsigned char>(start, start + size);
93 int main(
int argc,
char **argv)
99 std::cout <<
"changes here " << std::endl;
105 std::string camera_name;
106 std::string camera_info_url;
107 nh_.
getParam(
"camera_name", camera_name);
108 nh_.
getParam(
"camera_info_url", camera_info_url);
113 _camera_info_manager = &cinfo_manager;
119 ROS_WARN_STREAM(
"[" << camera_name <<
"] name not valid" <<
" for camera_info_manger");
122 if (_camera_info_manager->
validateURL(camera_info_url))
126 ROS_WARN(
"camera_info_url does not contain calibration data." );
130 ROS_WARN(
"Camera is not calibrated. Using default values." );
142 std::cout <<
" Try " << std::endl;
143 auto stream = Cvb::DeviceFactory::Open(Cvb::ExpandPath(CVB_LIT(
"%CVB%/drivers/GenICam.vin")))->Stream();
146 sensor_msgs::Image image;
147 sensor_msgs::Image imageRos;
148 cv_bridge::CvImagePtr frame;
155 auto waitResult = stream->WaitFor(std::chrono::milliseconds(10000));
156 if (waitResult.Status == Cvb::WaitStatus::Ok)
160 Input = frame->image;
162 cv::Rect cropArea(195, 0 , 1546, 1216);
163 cropped = Input(cropArea);
164 cv::resize(cropped, Output, cv::Size(), 1, 1);
165 cv_bridge::CvImage resizeRos;
166 resizeRos.encoding =
"rgb8";
167 resizeRos.image = Output;
168 sensor_msgs::ImagePtr imagePtr = resizeRos.toImageMsg();
171 resizeRos.toImageMsg(imageRos);
184 throw std::runtime_error(std::string(
"cvb acq error ") + std::to_string(static_cast<int>(waitResult.Status)));
190 catch (
const std::exception& error)
192 std::cout << error.what() << std::endl;
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
sensor_msgs::CameraInfo getCameraInfo(void)
void publish(const boost::shared_ptr< M > &message) const
bool loadCameraInfo(const std::string &url)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
camera_info_manager::CameraInfoManager * _camera_info_manager
void callback(const sensor_msgs::ImageConstPtr &image)
bool validateURL(const std::string &url)
void publish(const sensor_msgs::Image &message) const
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
sensor_msgs::CameraInfo _camera_info
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_STREAM_ONCE(args)
ROSCPP_DECL void spinOnce()
bool setCameraName(const std::string &cname)
sensor_msgs::Image toImageMsg(const Cvb::ImagePtr &cvbImg)