-
Notifications
You must be signed in to change notification settings - Fork 97
Added feature for loading and saving camera_info from/to camera flash memory. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qbranchmaster
wants to merge
2
commits into
srv:indigo
Choose a base branch
from
piappl:indigo
base: indigo
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,8 @@ MonoCamera::MonoCamera(ros::NodeHandle nh, ros::NodeHandle nhp) : nh_(nh), nhp_( | |
| // Set the image publisher before the streaming | ||
| pub_ = it_.advertiseCamera("image_raw", 1); | ||
|
|
||
| memory_loaded_ = false; | ||
|
|
||
| // Set the frame callback | ||
| cam_.setCallback(boost::bind(&avt_vimba_camera::MonoCamera::frameCallback, this, _1)); | ||
|
|
||
|
|
@@ -58,7 +60,12 @@ MonoCamera::MonoCamera(ros::NodeHandle nh, ros::NodeHandle nhp) : nh_(nh), nhp_( | |
| nhp_.param("show_debug_prints", show_debug_prints_, false); | ||
|
|
||
| // Set camera info manager | ||
| info_man_ = boost::shared_ptr<camera_info_manager::CameraInfoManager>(new camera_info_manager::CameraInfoManager(nhp_, frame_id, camera_info_url_)); | ||
| info_man_ = boost::shared_ptr<camera_info_manager::CameraInfoManager>(new camera_info_manager::CameraInfoManager(nh_, frame_id, camera_info_url_)); | ||
|
|
||
| // Service call for setting calibration. | ||
| set_camera_info_srv_ = nhp_.advertiseService("set_camera_info", | ||
| &MonoCamera::setCameraInfo, | ||
| this); | ||
|
|
||
| // Start dynamic_reconfigure & run configure() | ||
| reconfigure_server_.setCallback(boost::bind(&avt_vimba_camera::MonoCamera::configure, this, _1, _2)); | ||
|
|
@@ -132,6 +139,30 @@ void MonoCamera::updateCameraInfo(const avt_vimba_camera::AvtVimbaCameraConfig& | |
| ci.roi.height = config.roi_height; | ||
| ci.roi.width = config.roi_width; | ||
|
|
||
| // Load camera_info from camera memory | ||
| if(!info_man_->isCalibrated() && !memory_loaded_) { | ||
| ROS_WARN("Failed to load camera_info from file. Trying to load camera_info from camera memory ..."); | ||
|
|
||
| UcharVector loaded_data; | ||
| VmbErrorType result = cam_.loadCameraMemory(loaded_data); | ||
| if(result == VmbErrorSuccess) { | ||
| std::string calibration_data; | ||
| for(int i = 0 ; i < loaded_data.size() ; i++) | ||
| calibration_data += loaded_data[i]; | ||
|
|
||
| std::string cam_name = cam_.getCameraName(); | ||
|
|
||
| if(camera_calibration_parsers::parseCalibrationIni(calibration_data, cam_name, ci)) { | ||
| ROS_INFO("Loaded camera_info from camera memory for camera '%s'.", cam_name.c_str()); | ||
| memory_loaded_ = true; | ||
| } | ||
| else | ||
| ROS_WARN("Failed to parse camera_info from camera memory."); | ||
| } | ||
| else | ||
| ROS_WARN("Failed to load camera_info from camera memory."); | ||
| } | ||
|
|
||
| // set the new URL and load CameraInfo (if any) from it | ||
| std::string camera_info_url; | ||
| nhp_.getParam("camera_info_url", camera_info_url); | ||
|
|
@@ -156,4 +187,60 @@ void MonoCamera::updateCameraInfo(const avt_vimba_camera::AvtVimbaCameraConfig& | |
| info_man_->setCameraInfo(ci); | ||
| } | ||
|
|
||
| bool MonoCamera::setCameraInfo(sensor_msgs::SetCameraInfo::Request& req, sensor_msgs::SetCameraInfo::Response& rsp) { | ||
| ROS_INFO("New camera_info received."); | ||
|
|
||
| sensor_msgs::CameraInfo &info = req.camera_info; | ||
|
|
||
| if(info.width != info_man_->getCameraInfo().width || info.height != info_man_->getCameraInfo().height) | ||
| { | ||
| rsp.success = false; | ||
| rsp.status_message = (boost::format("camera_info resolution %ix%i does not match current video setting, camera is running at resolution %ix%i.") | ||
| % info.width % info.height % info_man_->getCameraInfo().width % info_man_->getCameraInfo().height).str(); | ||
| ROS_ERROR("%s", rsp.status_message.c_str()); | ||
| return true; | ||
| } | ||
|
|
||
| std::string cam_name = cam_.getCameraName(); | ||
|
|
||
| std::stringstream ini_stream; | ||
| if(!camera_calibration_parsers::writeCalibrationIni(ini_stream, cam_name, info)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ini format only supports "Plumb Bob" distortion model. To support other polynomial modes, yaml format must be used. Could you change this function for "writeCalibrationYaml" ? |
||
| rsp.status_message = "Error formatting camera_info for storage."; | ||
| rsp.success = false; | ||
| } | ||
| else { | ||
| std::string ini = ini_stream.str(); | ||
|
|
||
| VmbInt64_t lut_size = cam_.getLutMemorySize(); | ||
|
|
||
| if(ini.size() > lut_size / 2) { | ||
| rsp.success = false; | ||
| rsp.status_message = "Unable to write camera_info to camera memory, exceeded storage capacity."; | ||
| } | ||
| else { | ||
| VmbErrorType status; | ||
| UcharVector data; | ||
|
|
||
| for(std::string::iterator it = ini.begin() ; it != ini.end() ; it++) | ||
| data.push_back(*it); | ||
|
|
||
| status = cam_.saveCameraMemory(data); | ||
| if(status != VmbErrorSuccess) { | ||
| rsp.success = false; | ||
| rsp.status_message = "Undefinded write to memory problem."; | ||
| } | ||
| else { | ||
| rsp.success = true; | ||
| info_man_->setCameraInfo(info); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if(!rsp.success) | ||
| ROS_ERROR("%s", rsp.status_message.c_str()); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini format only supports "Plumb Bob" distortion model. To support other polynomial modes, yaml format must be used. Could you change this function for "readCalibrationYml" ?