Quellcode durchsuchen

change rostopilot and pilottoros, add image support.

yuchuli vor 3 Jahren
Ursprung
Commit
23e6ee8ec3

+ 11 - 7
src/ros/catkin/src/pilottoros/CMakeLists.txt

@@ -6,16 +6,14 @@ message(STATUS  "Enter pilottoros")
 
 
 SET(QT_PATH  /opt/qt/5.13.2/gcc_64)
-SET(AGX_QT_PATH  /usr/include/aarch64-linux-gnu/qt5)
 
-find_path(QT_EXIST   QtCore   ${QT_PATH}/include/QtCore  ${AGX_QT_PATH}/QtCore)
+
+find_path(QT_EXIST   QtCore   ${QT_PATH}/include/QtCore)
 
 if(QT_EXIST)
 include_directories(
   ${QT_PATH}/include
   ${QT_PATH}/include/QtCore
-  ${AGX_QT_PATH}
-  ${AGX_QT_PATH}/QtCore
 )
 link_directories(
   ${QT_PATH}/lib
@@ -32,6 +30,7 @@ if (MODULECOMM_INCLUDE_DIR  AND  MODULECOMM_LIBRARAY_DIR )
   message(STATUS  "FIND  modulecomm")
   include_directories(
     ${CMAKE_SOURCE_DIR}/../../../../include
+    ${CMAKE_SOURCE_DIR}/../../../../src/include/msgtype
   )
   link_directories(
     ${CMAKE_SOURCE_DIR}/../../../../bin
@@ -45,6 +44,8 @@ endif ()
 ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
 ## is used, also find other catkin packages
 find_package(catkin REQUIRED COMPONENTS
+  cv_bridge
+  image_transport
   roscpp
   pluginlib
   sensor_msgs
@@ -52,6 +53,8 @@ find_package(catkin REQUIRED COMPONENTS
   pcl_conversions
 )
 find_package(Boost REQUIRED)
+find_package(OpenCV REQUIRED)
+find_package(Protobuf REQUIRED)
 
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_AUTOMOC ON)
@@ -95,6 +98,8 @@ catkin_package(
     pcl_ros pcl_conversions
   DEPENDS
     Boost
+    OpenCV
+    Protobuf
 #  DEPENDS system_lib
 )
 
@@ -113,8 +118,7 @@ include_directories(
   ${Boost_INCLUDE_DIR}
 )
 
-
 ## Declare a C++ executable
-add_executable(${PROJECT_NAME}_node src/main.cpp )
-target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} Qt5Core Qt5Xml modulecomm)
+add_executable(${PROJECT_NAME}_node src/main.cpp src  ./../../../../include/msgtype/rawpic.pb.cc )
+target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES}  ${OpenCV_LIBRARIES}    ${Protobuf_LIBRARIES}   Qt5Core Qt5Xml modulecomm)
 

+ 58 - 3
src/ros/catkin/src/pilottoros/src/main.cpp

@@ -6,14 +6,28 @@
 #include <pcl_ros/point_cloud.h>
 #include <pcl/point_types.h>
 
+#include <opencv2/opencv.hpp>
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc.hpp>
+#include<cv_bridge/cv_bridge.h>
+#include<sensor_msgs/image_encodings.h>
+#include<image_transport/image_transport.h>
+
+#include "rawpic.pb.h"
+
+
 static std::string _point_topic = "/points_raw";
 static std::string _point_msgname = "lidar_pc";
 
+static std::string _image_topic = "/image_raw";
+static std::string _image_msgname = "picfront";
+
 ros::Publisher  point_cloud_pub;
+image_transport::Publisher  image_pub;
 
 void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
 {
-	std::cout<<" get msg."<<std::endl;
+//	std::cout<<" get msg."<<std::endl;
     if(nSize <=16)return;
     unsigned int * pHeadSize = (unsigned int *)strdata;
     if(*pHeadSize > nSize)
@@ -59,6 +73,33 @@ void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsign
     point_cloud_pub.publish(point_cloud);
 }
 
+void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    if(nSize<1000)return;
+    iv::vision::rawpic pic;
+    if(false == pic.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"picview Listenpic fail."<<std::endl;
+        return;
+    }
+
+    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
+    
+    if(pic.type() == 1)
+        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
+    else
+    {
+        std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data()+pic.picdata().size());
+        mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
+    }
+
+    sensor_msgs::ImagePtr msg;
+    msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", mat).toImageMsg();
+
+  image_pub.publish(msg);
+
+}
+
 int main(int argc, char *argv[])
 {
 	ros::init(argc, argv, "pilottoros");
@@ -70,16 +111,30 @@ int main(int argc, char *argv[])
 	private_nh.getParam("points_msgname",_point_msgname);
     std::cout<<"_point_topic is "<<_point_topic<<std::endl;
 	std::cout<<"_point_msgname : "<<_point_msgname<<std::endl;
+
+    private_nh.getParam("image_node",_image_topic);
+	private_nh.getParam("image_msgname",_image_msgname);
+    std::cout<<"_image_topic is "<<_image_topic<<std::endl;
+	std::cout<<"_image_msgname : "<<_image_msgname<<std::endl;
+
     point_cloud_pub = n.advertise<sensor_msgs::PointCloud2>(
                 _point_topic, 10);
-
 	void * pliar = iv::modulecomm::RegisterRecv(_point_msgname.data(),ListenPointCloud);
 
 
+    // 定义节点句柄   
+    image_transport::ImageTransport it(n);
+    image_pub  = it.advertise("image_raw", 1);
+
+    void * pimage = iv::modulecomm::RegisterRecv(_image_msgname.data(),Listenpic);
+
+
+ros::spin();
+/*
 	while (ros::ok())
 	{
- //       ROS_INFO("hello");
         ros::spinOnce();
 	 	loop_rate.sleep();
 	}
+    */
 }

+ 9 - 2
src/ros/catkin/src/rostopilot/CMakeLists.txt

@@ -32,6 +32,7 @@ if (MODULECOMM_INCLUDE_DIR  AND  MODULECOMM_LIBRARAY_DIR )
   message(STATUS  "FIND  modulecomm")
   include_directories(
     ${CMAKE_SOURCE_DIR}/../../../../include
+    ${CMAKE_SOURCE_DIR}/../../../../src/include/msgtype
   )
   link_directories(
     ${CMAKE_SOURCE_DIR}/../../../../bin
@@ -45,6 +46,8 @@ endif ()
 ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
 ## is used, also find other catkin packages
 find_package(catkin REQUIRED COMPONENTS
+ cv_bridge
+ image_transport
   roscpp
   pluginlib
   sensor_msgs
@@ -52,6 +55,8 @@ find_package(catkin REQUIRED COMPONENTS
   pcl_conversions
 )
 find_package(Boost REQUIRED)
+find_package(OpenCV REQUIRED)
+find_package(Protobuf REQUIRED)
 
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 set(CMAKE_AUTOMOC ON)
@@ -95,6 +100,8 @@ catkin_package(
     pcl_ros pcl_conversions
   DEPENDS
     Boost
+    OpenCV
+    Protobuf
 #  DEPENDS system_lib
 )
 
@@ -115,6 +122,6 @@ include_directories(
 
 
 ## Declare a C++ executable
-add_executable(${PROJECT_NAME}_node src/main.cpp )
-target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} Qt5Core Qt5Xml modulecomm)
+add_executable(${PROJECT_NAME}_node src/main.cpp ./../../../../include/msgtype/rawpic.pb.cc )
+target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES}  ${OpenCV_LIBRARIES}    ${Protobuf_LIBRARIES}  Qt5Core Qt5Xml modulecomm)
 

+ 89 - 1
src/ros/catkin/src/rostopilot/src/main.cpp

@@ -1,16 +1,32 @@
 #include "ros/ros.h"
 
+#include <memory>
+
 #include "modulecomm.h"
 
 #include <pcl_conversions/pcl_conversions.h>
 #include <pcl_ros/point_cloud.h>
 #include <pcl/point_types.h>
 
+#include <opencv2/opencv.hpp>
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc.hpp>
+#include<cv_bridge/cv_bridge.h>
+#include<sensor_msgs/image_encodings.h>
+#include<image_transport/image_transport.h>
+
+#include "rawpic.pb.h"
+
 static std::string _point_topic = "/points_raw";
 static std::string _point_msgname = "lidarpc_ros";
 
+static std::string _image_topic = "/image_raw";
+static std::string _image_msgname = "pic_ros";
+
+
   ros::Subscriber points_sub;
   void * gpa_lidar;
+  void * gpa_image;
 
 static void points_callback(const sensor_msgs::PointCloud2::ConstPtr& input)
 {
@@ -40,6 +56,67 @@ static void points_callback(const sensor_msgs::PointCloud2::ConstPtr& input)
 }
 
 
+int gindex = 0;
+int gcompress = 1;
+void imageCalllback(const sensor_msgs::ImageConstPtr& msg)
+{
+//	ROS_INFO("Received \n");
+	try{
+
+        cv::Mat mat1 = cv_bridge::toCvShare(msg, "bgr8")->image ;
+        cv::imshow( "video", mat1 );
+        cv::waitKey(30);
+
+        
+                    iv::vision::rawpic pic;
+            
+            qint64 time = QDateTime::currentMSecsSinceEpoch();
+            QTime xg;
+            xg.start();
+            pic.set_time(time);
+            pic.set_index(gindex);gindex++;
+
+
+            pic.set_elemsize(mat1.elemSize());
+            pic.set_width(mat1.cols);
+            pic.set_height(mat1.rows);
+            pic.set_mattype(mat1.type());
+
+
+            std::vector<int> param = std::vector<int>(2);
+            param[0] = CV_IMWRITE_JPEG_QUALITY;
+            param[1] = 95; // default(95) 0-100
+            std::vector<unsigned char> buff;
+            if(gcompress == 1)
+            {
+                cv::imencode(".jpg", mat1, buff, param);
+                pic.set_picdata(buff.data(),buff.size());
+                buff.clear();
+                pic.set_type(2);
+            }
+            else
+            {
+                pic.set_picdata(mat1.data,mat1.rows*mat1.cols*mat1.elemSize());
+                pic.set_type(1);
+            }
+
+             int nSize = pic.ByteSize();
+             std::shared_ptr<char>  str_ptr = std::shared_ptr<char>(new char[nSize]);
+            bool bser = pic.SerializeToArray(str_ptr.get(),nSize);
+            if(bser)iv::modulecomm::ModuleSendMsg(gpa_image,str_ptr.get(),nSize);
+            else
+            {
+                std::cout<<"imageCalllback "<< "serialize error. "<<std::endl;
+            }
+    }
+    catch( cv_bridge::Exception& e )
+    {
+        ROS_ERROR( "Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str() );
+    }
+}
+
+
+
 int main(int argc, char *argv[])
 {
 	ros::init(argc, argv, "rostopilot");
@@ -52,15 +129,26 @@ int main(int argc, char *argv[])
     std::cout<<"_point_topic is "<<_point_topic<<std::endl;
 	std::cout<<"_point_msgname : "<<_point_msgname<<std::endl;
 
+    private_nh.getParam("image_node",_image_topic);
+	private_nh.getParam("image_msgname",_image_msgname);
+    std::cout<<"_image_topic is "<<_image_topic<<std::endl;
+	std::cout<<"_image_msgname : "<<_image_msgname<<std::endl;
+
 	gpa_lidar = iv::modulecomm::RegisterSend(_point_msgname.data(),20000000,1);
+    gpa_image = iv::modulecomm::RegisterSend(_image_msgname.data(),20000000,1);
 
    points_sub = private_nh.subscribe(_point_topic, 1, points_callback);
 
+      image_transport::ImageTransport it(private_nh);
+    image_transport::Subscriber sub = it.subscribe( _image_topic, 1, imageCalllback );
+
 
+   ros::spin();
+   /*
 	while (ros::ok())
 	{
- //       ROS_INFO("hello");
         ros::spinOnce();
 	 	loop_rate.sleep();
 	}
+    */
 }