当前位置:网站首页>QT ROS related operations (running Terminal instructions, publishing and subscribing to custom message topics or services, subscribing to images and displaying)
QT ROS related operations (running Terminal instructions, publishing and subscribing to custom message topics or services, subscribing to images and displaying)
2022-07-24 03:41:00 【Ice cream】
01 Run terminal instructions

Configure remote login
ssh-keygen -t rsa
# Then keep going back
ssh-copy-id [email protected] Address
# Then enter the password
ssh [email protected] Address
02 Publish and subscribe to custom message topics or services
2.1 Create nodes to subscribe to publish topics


- Be careful :
1、 Frequency is modifiedqnodeClassrunFunctionros::Rate loop_rate(10);, At first I deleted while What's inside , Later, I found that for subscribing to video topics , The rating needs to be revised a little larger .
2、 stayQNode::init()Declare the name of subscription and publishing topic , Then where do I need to , Where to use the topic handle publish Just fine .
2.2 Customize messages or services
For adding custom messages
CmakeList.txtpass the civil examinations 41 Line modification and addition.hfile ( So you can read h The file ), As shown below :file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/manipulator_app/*.hpp *.h)Then compile , In the workspace build Found the compiled
.hThe header file ( This ismsgorsrvAfter compiling )Put the compiled into
.hFiles inincludeAnd then in
qnode.hppReference header file in , It can be used normally#include "../myMsg/SyncSetPosition.h" #include "../mySrv/SyncGetPosition.h"
03 Subscribe to images and display
3.1 Overall process :


- The main problem here is that the subscribed image is converted to QImage Can be in Qt It shows that , To QImage The function of is as follows :
QImage QNode::Mat2QImage(cv::Mat const& src) { QImage dest(src.cols, src.rows, QImage::Format_ARGB32); const float scale = 255.0; if (src.depth() == CV_8U) { if (src.channels() == 1) { for (int i = 0; i < src.rows; ++i) { for (int j = 0; j < src.cols; ++j) { int level = src.at<quint8>(i, j); dest.setPixel(j, i, qRgb(level, level, level)); } } } else if (src.channels() == 3) { for (int i = 0; i < src.rows; ++i) { for (int j = 0; j < src.cols; ++j) { cv::Vec3b bgr = src.at<cv::Vec3b>(i, j); dest.setPixel(j, i, qRgb(bgr[2], bgr[1], bgr[0])); } } } } else if (src.depth() == CV_32F) { if (src.channels() == 1) { for (int i = 0; i < src.rows; ++i) { for (int j = 0; j < src.cols; ++j) { int level = scale * src.at<float>(i, j); dest.setPixel(j, i, qRgb(level, level, level)); } } } else if (src.channels() == 3) { for (int i = 0; i < src.rows; ++i) { for (int j = 0; j < src.cols; ++j) { cv::Vec3f bgr = scale * src.at<cv::Vec3f>(i, j); dest.setPixel(j, i, qRgb(bgr[2], bgr[1], bgr[0])); } } } } return dest; }
3.2 Problems encountered and solutions
- problem : The color displayed is very strange , Human skin is blue , Like Avatar
- solve : Yes to QImage There was a problem , swap R Channels and B Just the passage
边栏推荐
- C自定义类型详解
- Basic syntax of MySQL DDL and DML and DQL
- leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
- 数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表
- Jump statement in day011 loop structure
- Matlab Fractional Order PID control
- 2022 China software products national tour exhibition is about to set sail
- Lagrange polynomial
- Bet on the whole scene, what is the odds of glory?
- Internet of things installation and debugging personnel let "smart" life come early
猜你喜欢

What is IMU?

Data Lake: introduction to Apache Hudi

QT custom class uses custom parametric signals and slots
![Embedded system transplantation [5] - Cross compilation tool chain](/img/2a/eadaaafe794aa9b3106441fa50ffc7.png)
Embedded system transplantation [5] - Cross compilation tool chain

Lagrange polynomial

Talk about the application of FIFO

Summary of Zhang Yu's 30 lectures on Advanced Mathematics

Cannot resolve symbol 'override' of idea clone‘

Convert the pseudo array returned by childNodes into a true array

IO stream sorting
随机推荐
Matlab Fractional Order PID control
RTOS内功修炼记(十) | 深度解析RTOS内核上下文切换机制
idea写web项目时报错Failed to load resource: the server responded with a status of 404 (Not Found)
Express built-in Middleware
Correct usage of iota in golang
数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表
Bet on the whole scene, what is the odds of glory?
A series of problems of dp+ backtracking segmentation palindrome string
[wepy2.0] installation
Scenario and value of data desensitization [summary]
Write code, and multiple characters move from both ends to converge in the middle
Machine learning notes - image homography estimation based on deep learning (homographynet)
Redis transaction learning
Data Lake: introduction to Apache Hudi
Industrial controller, do you really know your five insurances and one fund?
You must know the ten vulnerabilities of invalid access control
Convert the pseudo array returned by childNodes into a true array
Worthington's test of hepatocyte separation system and related optimization schemes
Programmers may still be programmers, and coders may only be coders
uniapp H5打包后本地图片无法显示问题