PCL点云学习(二) 学习内容和报错总结

1.在投影点云时,遇到Failed to find match for field 'intensity'.

Failed to find match for field 'intensity'.
project picture is published

 因为原始点云数据中不包含强度信息,所以在选择点云数据类型时应选择XYZ,而不是XYZ

投影成功

 2.投影时,遇到[ WARN] [1725800949.458191688]: Messages of type 0 arrived out of order (will print only once),并且rviz接收不到投影后的图像,显示 no image

时间戳 stamp 秒级精度相同

频率都改成了 10 hz

同步策略选择为 ApproximateTime

MySyncPolicy(10)为同步器的缓存大小(即队列大小),缓存大小指定了同步器在处理消息时可以缓存的最大消息数量。

但还是显示no image

. **时间同步**

确保系统时间同步正常。如果计算机时间不一致,可能导致 ROS 消息时间戳不准确。你可以使用 NTP 来同步系统时间。

sudo apt-get install ntp
sudo service ntp restart

### 总结

- **确认话题名称和类型**:确保你订阅了正确的话题。
- **检查消息内容**:确保话题上有消息发布。
- **检查同步器配置**:确认同步器的配置是否正确。
- **调试和日志输出**:添加调试信息以确认回调函数是否被调用。
- **检查发布节点**:确认发布节点是否正常工作。
- **时间同步**:确保系统时间同步正常。
- **消息过滤和丢失**:检查网络和消息丢失问题。
- **图像转换问题**:确保图像格式转换正确。
- **ROS 参数**:检查参数配置。

在代码中加入调试打印info语句

发现可以进入回调函数,但

// 发布投影后的图像

ros::Time time = ros::Time::now();

cv_ptr->encoding = "bgr8";

cv_ptr->header.stamp = time;

cv_ptr->header.frame_id = "/camera_main";

cv_ptr->image = visImg;

image_publisher.publish(cv_ptr->toImageMsg()); // 发布处理后的图像

ROS_INFO("Project picture is published!"); // 打印发布成功消息

 "Project picture is published!" 不能够成功打印

增加了打印信息,第二天不知道为什么可以打印 “Project picture is published”了。相关信息如下:

[ INFO] [1725852277.208848737, 204.243000000]: Callback function is triggered!
[ INFO] [1725852277.209183209, 204.243000000]: Image successfully converted to OpenCV format.
[ INFO] [1725852277.209440157, 204.244000000]: ******Image dimensions: Width = 1280, Height = 720******
[ INFO] [1725852277.209461948, 204.244000000]: Processing bounding boxes...
[ INFO] [1725852277.209477802, 204.244000000]: Processing bounding box with position: (4.405076, 1.836818, -0.045130) and dimensions: (0.551710, 0.825150)
[ INFO] [1725852277.209506926, 204.244000000]: Projected 2D coordinates: (903.739245, 3509.959421)
[ INFO] [1725852277.209522431, 204.244000000]: Draw bounding box from (1543.739245, 3869.959421) to (1544.290955, 3870.784571)
[ INFO] [1725852277.209584171, 204.244000000]: Prepare to publish picture
[ INFO] [1725852277.210031507, 204.244000000]: Project picture is published!

发现 投影点 超出了 图像尺寸

bboxjsk_recognition_msgs::BoundingBox 类型的对象,jsk_recognition_msgs::BoundingBox 的主要字段和含义:

jsk_recognition_msgs::BoundingBox 的字段

  1. header:

    • std_msgs::Header 类型的消息头,包含时间戳和坐标系信息。
    • frame_id: 该边界框在的坐标系名称,例如 "camera_main""base_link"
  2. pose:

    • geometry_msgs::Pose 类型,表示边界框的姿态。
    • position:
      • geometry_msgs::Point 类型,包含边界框的中心位置。
      • x: 中心的 x 坐标。
      • y: 中心的 y 坐标。
      • z: 中心的 z 坐标。
    • orientation:
      • geometry_msgs::Quaternion 类型,表示边界框的方向。
      • x: 四元数的 x 分量。
      • y: 四元数的 y 分量。
      • z: 四元数的 z 分量。
      • w: 四元数的 w 分量。
  3. dimensions:

    • geometry_msgs::Vector3 类型,表示边界框的尺寸。
    • x: 边界框的宽度。
    • y: 边界框的高度。
    • z: 边界框的深度。
  4. color:

    • std_msgs::ColorRGBA 类型,用于表示边界框的颜色(如果有)。

更改了3d box-> 2d box 的投影逻辑,计算所有点的凸包来找到最外面的四个角点

遇到报错:

[ INFO] [1725868608.007150873, 209.904000000]: Callback function triggered.
[ INFO] [1725868608.014174972, 209.911000000]: Image dimensions: Width = 1280, Height = 720
[ INFO] [1725868608.014202140, 209.911000000]: Processing bounding boxes...
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.2.0) ../modules/imgproc/src/convhull.cpp:137: error: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'convexHull'

已放弃 (核心已转储)

cv::convexHull 函数要求输入点的 cv::Mat 类型为 CV_32FCV_32S,但是当前传递的是 cv::Point2d 类型的 std::vector。这个数据类型不符合要求。


报错:

[ INFO] [1725870493.252210459, 214.298000000]: Callback function triggered.
[ INFO] [1725870493.253596662, 214.300000000]: Image dimensions: Width = 1280, Height = 720
[ INFO] [1725870493.253621386, 214.300000000]: Processing bounding boxes...
[ INFO] [1725870493.253636611, 214.300000000]: Processing bounding box with position: (4.405076, 1.836818, -0.045130) and dimensions: (0.551710, 0.825150, 0.489468)
[ INFO] [1725870493.253665176, 214.300000000]: Projected corner 0: (-nan, inf)
[ INFO] [1725870493.253682218, 214.300000000]: Projected corner 1: (-nan, inf)
[ INFO] [1725870493.253698071, 214.300000000]: Projected corner 2: (-nan, inf)
[ INFO] [1725870493.253716579, 214.300000000]: Projected corner 3: (-nan, inf)
[ INFO] [1725870493.253728592, 214.300000000]: Projected corner 4: (-nan, inf)
[ INFO] [1725870493.253741373, 214.300000000]: Projected corner 5: (-nan, inf)
[ INFO] [1725870493.253751919, 214.300000000]: Projected corner 6: (-nan, inf)
[ INFO] [1725870493.253762884, 214.300000000]: Projected corner 7: (-nan, inf)
[ INFO] [1725870493.253771893, 214.300000000]: Calculating convex hull for 8 projected points.
[ INFO] [1725870493.253787747, 214.300000000]: Drawing bounding box with 1 points on image.
[ INFO] [1725870493.253799550, 214.300000000]: Drawing line from (-nan, inf) to (-nan, inf)
[ INFO] [1725870493.253840547, 214.300000000]: Publishing projected image.
[ INFO] [1725870493.254767755, 214.301000000]: Projected image published.

打印出的内参和外参有问题

 打印出来的内外参矩阵和真值矩阵不一致。这通常是因为 cv::Mat 对象的内存布局或数据存储方式导致的。

原代码:

        double camToCam[12], cameraIn[16], RT[16];
        for (int i = 0; i < 12; ++i) infile >> camToCam[i];
        params.camToCamMat = cv::Mat(4, 4, CV_64F, camToCam);

        for (int i = 0; i < 12; ++i) infile >> cameraIn[i];
        params.cameraIntrinsics = cv::Mat(3, 4, CV_64F, cameraIn);

        for (int i = 0; i < 16; ++i) infile >> RT[i];
        params.RT = cv::Mat(4, 4, CV_64F, RT);

更改后:

        // 读取 camToCamMat
        double camToCam[16]; // 4x4 matrix
        for (int i = 0; i < 16; ++i) infile >> camToCam[i];
        params.camToCamMat = cv::Mat(4, 4, CV_64F, camToCam).clone(); // 使用 clone() 确保数据拷贝

        // 读取 cameraIntrinsics
        double cameraIn[12]; // 3x4 matrix
        for (int i = 0; i < 12; ++i) infile >> cameraIn[i];
        params.cameraIntrinsics = cv::Mat(3, 4, CV_64F, cameraIn).clone(); // 使用 clone() 确保数据拷贝

        // 读取 RT
        double RT[16]; // 4x4 matrix
        for (int i = 0; i < 16; ++i) infile >> RT[i];
        params.RT = cv::Mat(4, 4, CV_64F, RT).clone(); // 使用 clone() 确保数据拷贝

打印正确:

 

 

 发现两个问题:

        1.聚类算法

        2.凸包寻找错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值