I have a working rostest which I was running against a bagfile of image data. Earlier I had stored it in my git package but since its a big file I am thinking of storing the bag file in cloud and downloading while running the test. I came across catkin_download_test_data()
to add in CMakelist to do the same but unable to understand how I should modify my rostest to use that. Currently following is the test -
#include "test/test_toll_detector.h"
const auto packagePath = ros::package::getPath("toll_detection");
const auto bagFilePath = packagePath + "/test/bag/toll_detect.bag";
const auto inputImageTopic = "/camera_1/image_raw";
static cv::Mat readFrameFromBag(const std::string& bagFilePath, const std::string& topic) {
rosbag::Bag bag;
bag.open(bagFilePath, rosbag::bagmode::Read);
std::vector<std::string> topics = {topic};
rosbag::View view(bag, rosbag::TopicQuery(topics));
cv::Mat frame;
for (const rosbag::MessageInstance& m : view) {
sensor_msgs::Image::ConstPtr imgMsg = m.instantiate<sensor_msgs::Image>();
frame = ImageConverter::convertToCvMat(imgMsg);
break;
}
bag.close();
return frame;
}
TEST_F(TollDetectorTest, HappyCase) {
cv::Mat frame = readFrameFromBag(bagFilePath, inputImageTopic);
cv::Mat image;
m_HSVFilter_.apply(frame, image);
std::vector<cv::Rect> tolls = m_TollDetector_.detect(image);
ASSERT_FALSE(tolls.empty());
}
In the CMakelists I am adding -
if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
include_directories(${catkin_INCLUDE_DIRS})
catkin_download_test_data(
${PROJECT_NAME}_toll_detector.bag
https://<link-to-bag-file>
DESTINATION ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/test
MD5 bce3b89df952233e90fd5f9353fgh2086)
add_rostest(test/test_all.test DEPENDENCIES ${PROJECT_NAME}_toll_detector.bag)
catkin_add_gtest(tests_toll_detector
test/test_main.cpp
test/test_toll_detector.cpp
)
target_link_libraries(tests_toll_detector
${catkin_LIBRARIES}
)
endif()
Instead of using packagePath
to the rosbag file, how can I modify the code so that I can use catkin_download_test_data()
to download the bag file and use the data?