Robotics StackExchange | Archived questions

PointCloud2 read_points unpack_from problem

Hey, I'm working on a object recognition framework that uses deep learning methods. Given the locations of the objects in the image (bounding box), I use the PointCloud publised by a Kinect 2, to locate those.

Currently, I'm working with ROS Kinetic and I'm developing in python.

Sometimes, trying to obtain the xyz points of the bounding box, using the read_points method I receive the following error:

File "/home/some1/catkinws/src/semmapperisr/semmappermarkers/nodes/objectmapper.py", line 205, in getobject3Dpoints points = np.array(list(pc2.readpoints(self.currpc,fieldnames = ("x", "y", "z"), skipnans=True, uvs=bbpts))) File "/opt/ros/kinetic/lib/python2.7/dist-packages/sensormsgs/pointcloud2.py", line 83, in readpoints p = unpackfrom(data, (rowstep * v) + (pointstep * u)) error: unpack_from requires a buffer of at least 12 bytes

This error doesn't happen everytime I try to obtain the xyz points. Sometimes, there is no problem. The code is extensive, I will try to show their important parts for this case.

Imports:

import rospy
from sensormsgs.msg import PointCloud2, PointField
import sensormsgs.point_cloud2 as pc2

PointCloud Callback definition:

self.pcxyzsub = rospy.Subscriber(subpointcloudtopic, PointCloud2, self.pointcloudcallback, queuesize=2)

PointCloud Callback:

def pointcloudcallback(self, pointcloudmsg):
    self.pcmessagelocker.acquire()
    self.currpc = pointcloudmsg
    self.pcmessagelocker.release()

Where I try to obtain the xyz points:

def getobject3Dpoints(self,widthmin,widthmax,heightmin,heightmax,viewpath):
    bbpts=((i,j) for i in xrange(widthmin,widthmax+1) for j in xrange(heightmin, heightmax+1))#pixels of the image to verify in the pointcloud
    self.pcmessagelocker.acquire() #lock the pc message -> dont change/access current pc message at same time
    points = np.array(list(pc2.readpoints(self.currpc,fieldnames = ("x", "y", "z"), skipnans=True, uvs=bbpts)))
    self.pcmessagelocker.release()

I'm subscribing to the camera/depth_registered/points published by openni using Kinect.

I searched for that problem with the unpack and found nothing until now, do you have any idea what can be happening? Thanks for your patience, SancheZ

Asked by SancheZ on 2018-04-30 12:29:44 UTC

Comments

did u find a solution for this??

Asked by MohamedEhab on 2019-04-18 14:04:22 UTC

I have the same issue.

Asked by Redhwan on 2022-10-12 03:42:21 UTC

Answers