Skip to content

Commit

Permalink
Added extra parameters for mirroring the image
Browse files Browse the repository at this point in the history
  • Loading branch information
juancamilog committed Jun 23, 2014
1 parent 3d3f8ef commit 467abc5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cfg/UEyeCam.cfg
Expand Up @@ -96,4 +96,10 @@ gen.add("frame_rate", double_t, RECONFIGURE_RUNNING,
gen.add("pixel_clock", int_t, RECONFIGURE_RUNNING,
"Pixel clock (MHz)", 25, 1, 100)


gen.add("flip_upd", bool_t, RECONFIGURE_RUNNING,
"Mirror Upside Down", False)
gen.add("flip_lr", bool_t, RECONFIGURE_RUNNING,
"Mirror Left Right", False)

exit(gen.generate(PACKAGE, "ueye_cam", "UEyeCam"))
16 changes: 16 additions & 0 deletions include/ueye_cam/ueye_cam_driver.hpp
Expand Up @@ -319,6 +319,22 @@ class UEyeCamDriver {
*/
INT setStandbyMode();

/**
* Mirrors the camera image upside down
* \param flip_horizontal Wheter to flip the image upside down or not.
*
* \return IS_SUCCESS if successful, error flag otherwise (see err2str).
*/
INT setMirrorUpsideDown(bool flip_horizontal);

/**
* Mirrors the camera image left to right
* \param flip_vertical Wheter to flip the image left to right or not.
*
* \return IS_SUCCESS if successful, error flag otherwise (see err2str).
*/
INT setMirrorLeftRight(bool flip_vertical);

/**
* Waits for next frame to be available, then returns pointer to frame if successful.
* This function should only be called when the camera is in live capture mode.
Expand Down
23 changes: 23 additions & 0 deletions src/ueye_cam_driver.cpp
Expand Up @@ -810,6 +810,29 @@ INT UEyeCamDriver::setExtTriggerMode() {
return is_err;
};

INT UEyeCamDriver::setMirrorUpsideDown(bool flip_horizontal){
if (!isConnected()) return IS_INVALID_CAMERA_HANDLE;

INT is_err = IS_SUCCESS;
if(flip_horizontal)
is_err = is_SetRopEffect(cam_handle_,IS_SET_ROP_MIRROR_UPDOWN,1,0);
else
is_err = is_SetRopEffect(cam_handle_,IS_SET_ROP_MIRROR_UPDOWN,0,0);

return is_err;
}

INT UEyeCamDriver::setMirrorLeftRight(bool flip_vertical){
if (!isConnected()) return IS_INVALID_CAMERA_HANDLE;

INT is_err = IS_SUCCESS;
if(flip_vertical)
is_err = is_SetRopEffect(cam_handle_,IS_SET_ROP_MIRROR_LEFTRIGHT,1,0);
else
is_err = is_SetRopEffect(cam_handle_,IS_SET_ROP_MIRROR_LEFTRIGHT,0,0);

return is_err;
}

INT UEyeCamDriver::setStandbyMode() {
if (!isConnected()) return IS_INVALID_CAMERA_HANDLE;
Expand Down
30 changes: 26 additions & 4 deletions src/ueye_cam_nodelet.cpp
Expand Up @@ -48,7 +48,7 @@
#include "ueye_cam/ueye_cam_nodelet.hpp"
#include <cstdlib> // needed for getenv()
#include <ros/package.h>
#include <camera_calibration_parsers/parse_ini.h>
#include <camera_calibration_parsers/parse.h>
#include <sensor_msgs/fill_image.h>
#include <sensor_msgs/image_encodings.h>

Expand Down Expand Up @@ -104,6 +104,8 @@ UEyeCamNodelet::UEyeCamNodelet() :
cam_params_.ext_trigger_mode = false;
cam_params_.flash_delay = 0;
cam_params_.flash_duration = DEFAULT_FLASH_DURATION;
cam_params_.flip_upd = false;
cam_params_.flip_lr = false;
};


Expand Down Expand Up @@ -182,7 +184,9 @@ void UEyeCamNodelet::onInit() {
"Ext Trigger Mode:\t" << cam_params_.ext_trigger_mode << endl <<
"Auto Frame Rate:\t" << cam_params_.auto_frame_rate << endl <<
"Frame Rate (Hz):\t" << cam_params_.frame_rate << endl <<
"Pixel Clock (MHz):\t" << cam_params_.pixel_clock << endl
"Pixel Clock (MHz):\t" << cam_params_.pixel_clock << endl <<
"Mirror Image Upside Down:\t" << cam_params_.flip_upd << endl <<
"Mirror Image Left Right:\t" << cam_params_.flip_lr << endl
);
};

Expand Down Expand Up @@ -427,6 +431,18 @@ INT UEyeCamNodelet::parseROSParams(ros::NodeHandle& local_nh) {
}
}
}
if (local_nh.hasParam("flip_upd")) {
local_nh.getParam("flip_upd", cam_params_.flip_upd);
if (cam_params_.flip_upd != prevCamParams.flip_upd) {
hasNewParams = true;
}
}
if (local_nh.hasParam("flip_lr")) {
local_nh.getParam("flip_lr", cam_params_.flip_lr);
if (cam_params_.flip_lr != prevCamParams.flip_lr) {
hasNewParams = true;
}
}

if (hasNewParams) {
// Configure color mode, resolution, and subsampling rate
Expand Down Expand Up @@ -464,6 +480,9 @@ INT UEyeCamNodelet::parseROSParams(ros::NodeHandle& local_nh) {
if ((is_err = setExposure(cam_params_.auto_exposure, cam_params_.exposure)) != IS_SUCCESS) return is_err;
if ((is_err = setWhiteBalance(cam_params_.auto_white_balance, cam_params_.white_balance_red_offset,
cam_params_.white_balance_blue_offset)) != IS_SUCCESS) return is_err;

if ((is_err = setMirrorUpsideDown(cam_params_.flip_upd)) != IS_SUCCESS) return is_err;
if ((is_err = setMirrorLeftRight(cam_params_.flip_lr)) != IS_SUCCESS) return is_err;
}

return is_err;
Expand Down Expand Up @@ -585,6 +604,9 @@ void UEyeCamNodelet::configCallback(ueye_cam::UEyeCamConfig& config, uint32_t le
config.white_balance_blue_offset) != IS_SUCCESS) return;
}

if (setMirrorUpsideDown(cam_params_.flip_upd) != IS_SUCCESS) return;
if (setMirrorLeftRight(cam_params_.flip_lr) != IS_SUCCESS) return;

// NOTE: nothing needs to be done for config.ext_trigger_mode, since frame grabber loop will re-initialize to the right setting

if (config.flash_delay != cam_params_.flash_delay ||
Expand Down Expand Up @@ -1014,15 +1036,15 @@ void UEyeCamNodelet::loadIntrinsicsFile() {
}

std::string dummyCamName;
if (camera_calibration_parsers::readCalibrationIni(cam_intr_filename_, dummyCamName, ros_cam_info_)) {
if (camera_calibration_parsers::readCalibration(cam_intr_filename_, dummyCamName, ros_cam_info_)) {
NODELET_DEBUG_STREAM("Loaded intrinsics parameters for UEye camera " << cam_name_);
}
ros_cam_info_.header.frame_id = "/" + cam_name_;
};


bool UEyeCamNodelet::saveIntrinsicsFile() {
if (camera_calibration_parsers::writeCalibrationIni(cam_intr_filename_, cam_name_, ros_cam_info_)) {
if (camera_calibration_parsers::writeCalibration(cam_intr_filename_, cam_name_, ros_cam_info_)) {
NODELET_DEBUG_STREAM("Saved intrinsics parameters for UEye camera " << cam_name_ <<
" to " << cam_intr_filename_);
return true;
Expand Down

0 comments on commit 467abc5

Please sign in to comment.