Skip to content

Commit

Permalink
see description
Browse files Browse the repository at this point in the history
- rosbag recording tested, not recording redundant data.
- cv_camera updated
- data logger node working.
- other small changes
  • Loading branch information
NeilNie committed Feb 7, 2019
1 parent 8d9cba1 commit 6a48811
Show file tree
Hide file tree
Showing 37 changed files with 1,130 additions and 350 deletions.
371 changes: 223 additions & 148 deletions .idea/workspace.xml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions cv_camera/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Compiled Object files
*.slo
*.lo
*.o

# Compiled Dynamic libraries
*.so
*.dylib

# Compiled Static libraries
*.lai
*.la
*.a

*~
File renamed without changes.
97 changes: 97 additions & 0 deletions cv_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
cmake_minimum_required(VERSION 2.8.3)
project(cv_camera)

find_package(catkin REQUIRED COMPONENTS
image_transport roscpp cv_bridge sensor_msgs nodelet camera_info_manager roslint)

find_package(OpenCV REQUIRED)

find_package(Boost REQUIRED COMPONENTS system thread)

roslint_cpp()

catkin_package(
INCLUDE_DIRS include
LIBRARIES cv_camera
CATKIN_DEPENDS image_transport roscpp cv_bridge sensor_msgs nodelet camera_info_manager
DEPENDS OpenCV
)

include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)

## Declare a cpp library
add_library(cv_camera src/capture.cpp src/driver.cpp)
add_library(cv_camera_nodelet src/cv_camera_nodelet.cpp)


## Declare a cpp executable
add_executable(cv_camera_node src/cv_camera_node.cpp)
add_dependencies(cv_camera_node cv_camera)
add_dependencies(cv_camera_nodelet cv_camera)

## Specify libraries to link a library or executable target against
target_link_libraries(cv_camera
${catkin_LIBRARIES}
${OpenCV_LIBS}
)

target_link_libraries(cv_camera_nodelet
${catkin_LIBRARIES}
cv_camera
)

target_link_libraries(cv_camera_node
${catkin_LIBRARIES}
cv_camera
)

#############
## Install ##
#############

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
install(TARGETS cv_camera cv_camera_nodelet cv_camera_node
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)

# add xml file
install(FILES cv_camera_nodelets.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)


#############
## Testing ##
#############

roslint_cpp(
src/capture.cpp src/cv_camera_node.cpp src/cv_camera_nodelet.cpp src/driver.cpp
)

if (CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest_gtest(test_cv_camera test/cv_camera.test
test/test_cv_camera.cpp)
target_link_libraries(test_cv_camera ${PROJECT_NAME} ${catkin_LIBRARIES})

add_rostest_gtest(test_cv_camera_no_yaml test/no_yaml.test
test/test_cv_camera_no_yaml.cpp)
target_link_libraries(test_cv_camera_no_yaml ${PROJECT_NAME} ${catkin_LIBRARIES})
endif()
File renamed without changes.
12 changes: 0 additions & 12 deletions ros/src/sensors/cv_camera/README.md → cv_camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ If no calibration data is set, it has dummy values except for width and height.
* ~image_height (int) try to set capture image height.
* ~camera_info_url (string) url of camera info yaml.
* ~file (string: default "") if not "" then use movie file instead of device.
* ~rescale_camera_info (bool: default false) rescale camera calibration info automatically.

supports CV_CAP_PROP_*, by below params.

Expand Down Expand Up @@ -65,14 +64,3 @@ Nodelet
-------------------

This node works as nodelet (cv_camera/CvCameraNodelet).

Contributors
--------------------

PR is welcome. I'll review your code to keep consistency, be patient.

* Oleg Kalachev
* Mikael Arguedas
* Maurice Meedendorp
* Max Schettler
* Lukas Bulwahn
10 changes: 10 additions & 0 deletions cv_camera/cv_camera_nodelets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library path="lib/libcv_camera_nodelet">

<class name="cv_camera/CvCameraNodelet"
type="cv_camera::CvCameraNodelet" base_class_type="nodelet::Nodelet">
<description>
OpenCV camera driver nodelet.
</description>
</class>

</library>
210 changes: 210 additions & 0 deletions cv_camera/include/cv_camera/capture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
// Copyright [2015] Takashi Ogura<t.ogura@gmail.com>

#ifndef CV_CAMERA_CAPTURE_H
#define CV_CAMERA_CAPTURE_H

#include "cv_camera/exception.h"
#include <string>

#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/CameraInfo.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/highgui/highgui.hpp>
#include <camera_info_manager/camera_info_manager.h>

/**
* @brief namespace of this package
*/
namespace cv_camera
{

/**
* @brief captures by cv::VideoCapture and publishes to ROS topic.
*
*/
class Capture
{
public:
/**
* @brief costruct with ros node and topic settings
*
* @param node ROS node handle for advertise topic.
* @param topic_name name of topic to publish (this may be image_raw).
* @param buffer_size size of publisher buffer.
* @param frame_id frame_id of publishing messages.
*/
Capture(ros::NodeHandle& node,
const std::string& topic_name,
int32_t buffer_size,
const std::string& frame_id);

/**
* @brief Open capture device with device ID.
*
* @param device_id id of camera device (number from 0)
* @throw cv_camera::DeviceError device open failed
*
*/
void open(int32_t device_id);

/**
* @brief Open capture device with device name.
*
* @param device_path path of the camera device
* @throw cv_camera::DeviceError device open failed
*/
void open(const std::string& device_path);

/**
* @brief Load camera info from file.
*
* This loads the camera info from the file specified in the camera_info_url parameter.
*/
void loadCameraInfo();

/**
* @brief Open default camera device.
*
* This opens with device 0.
*
* @throw cv_camera::DeviceError device open failed
*/
void open();

/**
* @brief open video file instead of capture device.
*/
void openFile(const std::string& file_path);

/**
* @brief capture an image and store.
*
* to publish the captured image, call publish();
* @return true if success to capture, false if not captured.
*/
bool capture();

/**
* @brief Publish the image that is already captured by capture().
*
*/
void publish();

/**
* @brief accessor of CameraInfo.
*
* you have to call capture() before call this.
*
* @return CameraInfo
*/
inline const sensor_msgs::CameraInfo& getInfo() const
{
return info_;
}

/**
* @brief accessor of cv::Mat
*
* you have to call capture() before call this.
*
* @return captured cv::Mat
*/
inline const cv::Mat& getCvImage() const
{
return bridge_.image;
}

/**
* @brief accessor of ROS Image message.
*
* you have to call capture() before call this.
*
* @return message pointer.
*/
inline const sensor_msgs::ImagePtr getImageMsgPtr() const
{
return bridge_.toImageMsg();
}

/**
* @brief try capture image width
* @return true if success
*/
inline bool setWidth(int32_t width)
{
return cap_.set(CV_CAP_PROP_FRAME_WIDTH, width);
}

/**
* @brief try capture image height
* @return true if success
*/
inline bool setHeight(int32_t height)
{
return cap_.set(CV_CAP_PROP_FRAME_HEIGHT, height);
}

/**
* @brief set CV_PROP_*
* @return true if success
*/
bool setPropertyFromParam(int property_id, const std::string &param_name);

private:
/**
* @brief node handle for advertise.
*/
ros::NodeHandle node_;

/**
* @brief ROS image transport utility.
*/
image_transport::ImageTransport it_;

/**
* @brief name of topic without namespace (usually "image_raw").
*/
std::string topic_name_;

/**
* @brief header.frame_id for publishing images.
*/
std::string frame_id_;
/**
* @brief size of publisher buffer
*/
int32_t buffer_size_;

/**
* @brief image publisher created by image_transport::ImageTransport.
*/
image_transport::CameraPublisher pub_;

/**
* @brief capture device.
*/
cv::VideoCapture cap_;

/**
* @brief this stores last captured image.
*/
cv_bridge::CvImage bridge_;

/**
* @brief this stores last captured image info.
*
* currently this has image size (width/height) only.
*/
sensor_msgs::CameraInfo info_;

/**
* @brief camera info manager
*/
camera_info_manager::CameraInfoManager info_manager_;
};

} // namespace cv_camera

#endif // CV_CAMERA_CAPTURE_H

0 comments on commit 6a48811

Please sign in to comment.