test_cv_camera.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <sensor_msgs/CameraInfo.h>
00003 #include <sensor_msgs/Image.h>
00004 #include <gtest/gtest.h>
00005 
00006 sensor_msgs::Image g_image;
00007 sensor_msgs::CameraInfo g_camera_info;
00008 
00009 void ImageCallback(const sensor_msgs::Image::ConstPtr& image)
00010 {
00011   g_image = *image;
00012 }
00013 
00014 void InfoCallback(const sensor_msgs::CameraInfo::ConstPtr& info)
00015 {
00016   g_camera_info = *info;
00017 }
00018 
00019 TEST(CvCameraNode, getImage)
00020 {
00021   ros::NodeHandle node;
00022   ros::Subscriber sub = node.subscribe("/cv_camera_node/image_raw",
00023                                        1,
00024                                        &ImageCallback);
00025   ros::Rate r(10.0);
00026   while (sub.getNumPublishers() == 0) {
00027     r.sleep();
00028   }
00029   while (g_image.header.frame_id == "") {
00030     ros::spinOnce();
00031     r.sleep();
00032   }
00033   EXPECT_EQ("camera1", g_image.header.frame_id);
00034   EXPECT_EQ(480, g_image.height);
00035   EXPECT_EQ(640, g_image.width);
00036   EXPECT_EQ("bgr8", g_image.encoding);
00037 }
00038 
00039 TEST(CvCameraNode, getCameraInfo)
00040 {
00041   ros::NodeHandle node;
00042   ros::Subscriber sub = node.subscribe("/cv_camera_node/camera_info",
00043                                        1,
00044                                        &InfoCallback);
00045   ros::Rate r(10.0);
00046   while (sub.getNumPublishers() == 0) {
00047     r.sleep();
00048   }
00049   while (g_camera_info.header.frame_id == "") {
00050     ros::spinOnce();
00051     r.sleep();
00052   }
00053   EXPECT_EQ("camera1", g_camera_info.header.frame_id);
00054   // K
00055   EXPECT_EQ(9, g_camera_info.K.size());
00056   EXPECT_NEAR(4827.94, g_camera_info.K.at(0), 0.001);
00057   EXPECT_NEAR(0.0, g_camera_info.K.at(1), 0.001);
00058   EXPECT_NEAR(1223.5, g_camera_info.K.at(2), 0.001);
00059   // D
00060   EXPECT_EQ(5, g_camera_info.D.size());
00061   EXPECT_NEAR(-0.41527, g_camera_info.D.at(0), 0.001);
00062   EXPECT_NEAR(0.31874, g_camera_info.D.at(1), 0.001);
00063   EXPECT_NEAR(-0.00197, g_camera_info.D.at(2), 0.001);
00064   EXPECT_NEAR(0.00071, g_camera_info.D.at(3), 0.001);
00065   EXPECT_NEAR(0.0, g_camera_info.D.at(4), 0.001);
00066 
00067   EXPECT_EQ("plumb_bob", g_camera_info.distortion_model);
00068 
00069   // width
00070   EXPECT_EQ(2448, g_camera_info.width);
00071   EXPECT_EQ(2050, g_camera_info.height);
00072 }
00073 
00074 int main(int argc, char **argv){
00075   ros::init(argc, argv, "test_cv_camera");
00076   testing::InitGoogleTest(&argc, argv);
00077   return RUN_ALL_TESTS();
00078 }


cv_camera
Author(s): Takashi Ogura
autogenerated on Wed Aug 26 2015 11:13:42