python-pcl Segmentation_PointXYZI' object has no attribute 'set_MaxIterations' - python

I'm new in C++. So, I'm trying to use python-pcl, but I got an error:
AttributeError: 'pcl._pcl.Segmentation_PointXYZI' object has no attribute 'set_MaxIterations'
I'm trying to create the segmentation object for the planar model and set the parameters with the PointXYZI type. I have to use PointXYZI. How can I solve this problem?
My code:
def cluster_extraction(self,data):
print("Type1: ", type(data))
cloud_filtered = self.downsampling(data,0.3)
print("Type2: ", type(cloud_filtered))
seg = cloud_filtered.make_segmenter()
seg.set_optimize_coefficients (True)
seg.set_model_type (pcl.SACMODEL_PLANE)
seg.set_method_type (pcl.SAC_RANSAC)
seg.set_MaxIterations (100)
seg.set_distance_threshold (0.02)
Output:
('Type1: ', <type 'pcl._pcl.PointCloud_PointXYZI'>)
('Type2: ', <type 'pcl._pcl.PointCloud_PointXYZI'>)
[ERROR] [1596926303.890116]: bad callback: <bound method sub_pub_node.callback of <__main__.sub_pub_node object at 0x7f154be44ad0>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "node.py", line 154, in callback
downsampled_data = self.processing(pcl2_data)
File "node.py", line 103, in processing
processing.cluster_extraction(pcl2_data)
File "node.py", line 43, in cluster_extraction
seg.set_MaxIterations (100)
AttributeError: 'pcl._pcl.Segmentation_PointXYZI' object has no attribute 'set_MaxIterations'

I am not sure from where you got your python-pcl package, but I will assume that you used this one, therefore, and because there is no method called set_MaxIterations(int ) in the Segmentation_PointXYZI class (Sample Consensus), you can try to replace it with setMaxIterations(int ).
Inside the definition of the PointCloud_PointXYZI class, you can find that the Segmentation method used for this type of point clouds is an instance from pcl_seg.SACSegmentation_PointXYZI_t which defines the method for setting the max number of iterations as setMaxIterations(int ).
Please check the documentation provided here and check the functions that you are using and how are they defined. (I know that can be tedious but it is necessary).
I hope this helped in solving the issue.

According to strawlab's official example the correct call is:
seg.set_max_iterations(100)

Related

Python jsonpickle error: 'OrderedDict' object has no attribute '_OrderedDict__root'

I'm hitting this exception with jsonpickle, when trying to pickle a rather complex object that unfortunately I'm not sure how to describe here. I know that makes it tough to say much, but for what it's worth:
>>> frozen = jsonpickle.encode(my_complex_object_instance)
>>> thawed = jsonpickle.decode(frozen)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/jsonpickle/__init__.py",
line 152, in decode
return unpickler.decode(string, backend=backend, keys=keys)
:
:
File "/Library/Python/2.7/site-packages/jsonpickle/unpickler.py",
line 336, in _restore_from_dict
instance[k] = value
File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/packages/ordered_dict.py",
line 49, in __setitem__
root = self.__root
AttributeError: 'OrderedDict' object has no attribute '_OrderedDict__root'
I don't find much of assistance when googling the error. I do see what looks like the same issue was resolved at some time past for simpler objects:
https://github.com/jsonpickle/jsonpickle/issues/33
The cited example in that report works for me:
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict()))
OrderedDict()
>>> jsonpickle.decode(jsonpickle.encode(collections.OrderedDict(a=1)))
OrderedDict([(u'a', 1)])
Has anyone ever run into this themselves and found a solution? I ask with the understanding that my case may be "differently idiosynchratic" than another known example.
The requests module for me seems to be running into problems when I .decode(). After looking at the jsonpickle code a bit, I decided to fork it and change the following lines to see what was going on (and I ended up keeping a private copy of jsonpickle with the changes so I can move forward).
In jsonpickle/unpickler.py (in my version it's line 368), search for the if statement section in the method _restore_from_dict():
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
instance[k] = value
else:
setattr(instance, k, value)
and change it to this (it will logERROR the ones that are failing and then you can either keep the code in place or change your OrderedDict's version that have __root)
if (util.is_noncomplex(instance) or
util.is_dictionary_subclass(instance)):
# Currently requests.adapters.HTTPAdapter is using a non-standard
# version of OrderedDict which doesn't have a _OrderedDict__root
# attribute
try:
instance[k] = value
except AttributeError as e:
import logging
import pprint
warnmsg = 'Unable to unpickle {}[{}]={}'.format(pprint.pformat(instance), pprint.pformat(k), pprint.pformat(value))
logging.error(warnmsg)
else:
setattr(instance, k, value)

Error setting attribute of an sdl2 Entity

I am using the pysdl2 library. self.velocity will print, but self.forward_tick with throw a key error.
What is causing only part of the self attributes from being assigned. I am thinking it has something to do with the inheritance.
class Robot(sdl2.ext.Entity):
def __init__(self, world, sprite, posx=0, posy=0):
self.sprite = sprite
self.sprite.position = posx, posy
self.velocity = Velocity()
self.forward_tick = 0
self.go_forward = 0
self.unit_forward = (1,0)
print(self.velocity)
print(self.forward_tick)
Here is the output:
Collins-MacBook-Air:soccer_bots collinbell$ python test_simulation_world.py
<simulation_world.Velocity object at 0x108ecb5c0>
Traceback (most recent call last):
File "/Users/collinbell/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sdl2/ext/ebs.py", line 53, in __getattr__
ctype = self._world._componenttypes[name]
KeyError: 'forward_tick'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_simulation_world.py", line 3, in <module>
world = Simulation_World("Test Simulation", 1080, 720)
File "/Users/collinbell/Programs/soccer_bots/simulation_world.py", line 100, in __init__
self.player1 = Robot(self.world, sp_paddle1, 0, 250)
File "/Users/collinbell/Programs/soccer_bots/simulation_world.py", line 22, in __init__
print(self.forward_tick)
File "/Users/collinbell/.pyenv/versions/3.4.3/lib/python3.4/site-packages/sdl2/ext/ebs.py", line 56, in __getattr__
(self.__class__.__name__, name))
AttributeError: object ''Robot'' has no attribute ''forward_tick''
From the docs on component-based design with sdl2.ext, the Entity type is special, and doesn't follow normal Python idioms. In particular, you can't just create arbitrary attributes; you can only create attributes whose value is a component type, and whose name is a lowercased version of that type:
Entity objects define the in-application objects and only consist of component-based attributes.
…
The Entity also requries its attributes to be named exactly as their component class name, but in lowercase letters.
So, when you try to add an attribute named forward_tick, that causes Entity.__setattr__ to go looking for a class named Forward_Tick in the world's component types. Which it apparently does by looking up self._world._componentypes[name], which is the line that's actually raising the exception, as you can see in the tracebacks.
Without knowing anything more about your code and your design than the tiny fragment you showed us, I can't tell you how to fix this. But most likely, it's one of the following:
You actually wanted to create a Component, not an Entity,
You wanted to wrap up forward_tick in a Component type that this Entity can contain, or
You didn't want a Component-oriented design in the first place.
At any rate, as the docs say:
If you are just starting with such a [component-oriented] design, it is recommended to read through the The Pong Game tutorial.

Object Location Change on Blender Python

I was following an animation example with Python in Blender 2.69, by typing a line by line.
obj = bpy.context.object
obj.location[2] = 0.0
obj.keyframe_insert(data_path="location", frame=10.0, index=2)
obj.location[2] = 1.0
obj.keyframe_insert(data_path="location", frame=20.0, index=2)
But I have encountered an error on the 3rd line, which is saying
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'location'
I am confused because I just followed a simple example.
Why is it saying the object has no attribute 'location'?
I'll be appreciated for your help, thanks.
You'll find that the error would be reported after the second line because the variable obj has not been set. Most likely this would be from a small typo.
You can verify this by looking at the type of the variable in the python console. When getting the error you will see -
>>> type(obj)
<class 'NoneType'>
While if it had been set correctly you will get -
>>> type(obj)
<class 'bpy_types.Object'>

how to use TTreeReader in PyROOT

I'm trying to get up and running using the TTreeReader approach to reading TTrees in PyROOT. As a guide, I am using the ROOT 6 Analysis Workshop (http://root.cern.ch/drupal/content/7-using-ttreereader) and its associated ROOT file (http://root.cern.ch/root/files/tutorials/mockupx.root).
from ROOT import *
fileName = "mockupx.root"
file = TFile(fileName)
tree = file.Get("MyTree")
treeReader = TTreeReader("MyTree", file)
After this, I am a bit lost. I attempt to access variable information using the TTreeReader object and it doesn't quite work:
>>> rvMissingET = TTreeReaderValue(treeReader, "missingET")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/ROOT/v6-03-01/root/lib/ROOT.py", line 198, in __call__
result = _root.MakeRootTemplateClass( *newargs )
SystemError: error return without exception set
Where am I going wrong here?
TTreeReaderValue is a templated class, as shown in the example on the TTreeReader documentation, so you need to specify the template type.
You can do this with
rvMissingET = ROOT.TTreeReaderValue(ROOT.Double)(treeReader, "missingET")
The Python built-ins can be used for int and float types, e.g.
rvInt = ROOT.TTreeReaderValue(int)(treeReader, "intBranch")
rvFloat = ROOT.TTreeReaderValue(float)(treeReader, "floatBranch")
Also note that using TTreeReader in PyROOT is not recommended. (If you're looking for faster ntuple branch access in Python, you might look in to the Ntuple class I wrote.)

Python: TypeError: 'float' object is not callable

I am trying to join 2 strings using this code:
def __get_temp(self):
return float(self.ask('RS'))
def __set_temp(self, temp):
set = ('SS' + repr(temp))
stat = self.ask(set)
return self.check(stat)
temp = property(__get_temp, __set_temp)
Once together, I then send a signal over a serial bus using PyVisa. However, when I try to call the function, I get
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
chil.temp(13)
TypeError: 'float' object is not callable
I've tried looking around for explanation of this error, but none of them make any sense. Anyone know what is going on?
It looks like you are trying to set the property temp, but what you're actually doing is getting the property and then trying to call it as function with the parameter 13. The syntax for setting is:
chil.temp = 13

Categories