'module' object has no attribute 'DescriptorExtractor_create' - python

I'm trying to extract the descriptors using BRISK, as follows:
cv2.DescriptorExtractor_create('BRISK')
But, getting the following error:
AttributeError: 'module' object has no attribute 'DescriptorExtractor_create'
Why is that? How can I fix the issue?
Thanks.

Using the help command will clear the air on using the BRISK feature descriptor. To use it type the following in the terminal console:
help(cv2.BRISK)
In order to obtain the descriptors, there are certain pre-requisites:
Create the BRISK object, here f is the object of class BRISK:
f = cv2.BRISK_create()
Find the keypoints for a given image img using detect() method:
keypoints = f.detect(img)
Now using the image and the keypoints you can obtain the descriptors:
descriptors = f.compute(img, keypoints)

Related

DaskLGBMClassifier.fit() error: 'Future' object has no attribute 'get_params'

I'm trying LGBM's Dask API and when I fit DaskLGBMClassifier I get the following error:
'Future' object has no attribute 'get_params'
I tried to deug it working on the original code. The variable model that you can see in the error reference that Colab should be an instance of the class LGBMModel, which seems to have the method get_params().
Why does it say that get_params is an attribute? What is a 'Future' object?
this is the image of the error image of error , this the model=_train, this the _train function, this the LGBMModel adn finally the get param function.

Loading a Mesh in OpenCV Python with viz module

I am creating an AR-app, where you can virtually try on shoes. For now I have the location of the foot calculated using SolvePnp. Now I want to render the 3D object (.obj) file on top of the image, using the OpenCv Viz module. (Manually compiling worked)
I want to load the object as an cv::viz::Mesh object using the cv::viz::Mesh::load function, but I don't find the corresponding Python function call.
I tried
mesh = cv2.viz_Mesh()
mesh.load('shoe.obj', cv2.viz_Mesh_LOAD_OBJ)
and also
mesh = cv2.viz_Mesh_load('shoe.obj', cv2.viz_Mesh_LOAD_OBJ)
I always get the error:
AttributeError: 'cv2.viz_Mesh' object has no attribute 'load'
Using the dir() function from python I found all other methods except the load method, which is a static method (that's probably why it isn't here).
>>> dir(cv2) #contains the Viz Classes
['', ... , 'viz',... ,'viz_Mesh]
>>> dir(cv2.viz) #Stuff like Enums , Colors etc
['',...'Color_amethyst', ..., 'MOUSE_EVENT_MOUSE_DBL_CLICK'...]
>>> dir(cv2.viz_Mesh) #pyhton functions and other non static methods
['__class__', ... , 'colors','polygons']
Does someone know what the correct python call is?
Appendix: the cv2.viz_Mesh_LOAD_OBJ and cv2.viz_MESH_LOAD_OBJ represent only integers 2 ( = enums), thus
>>>print(cv2.viz_MESH_LOAD_OBJ)
>>>print(cv2.viz_Mesh_LOAD_OBJ)
2
2
I found the solution. I overlooked some methods in the dir(cv2.viz).
The correct python call would be
mesh = cv2.viz.readMesh('./shoe.ply')
It only accepts the path to .ply file, but not to .obj files (Version 4.5.5). Maybe other formats will be added in newer versions

AttributeError: 'PhotoImage' object has no attribute 'shape'

I am currently trying to display an image in tkinter and identify its body using mediapipe. I use Opencv, mediapipe and tkinter for this. I have also implemented something for this, but unfortunately I am not getting anywhere.
The type of the first argument of mpDraw.draw_landmarks should be NumPy array, but you are passing and object of type PhotoImage.
You may replace landmarks(photo, results) with:
landmarks(image, results)
The following code:
photo = ImageTk.PhotoImage(image=Image.fromarray(image))
landmarks(photo, results)
Converts image from NumPy array to PhotoImage object, and passes the object as argument to landmarks method (that passes it to mpDraw.draw_landmarks).
Take a look at the error message:
if image.shape[2] != RGB_CHANNELS:
AttributeError: 'PhotoImage' object has no attribute 'shape'
That means the image type is 'PhotoImage'.
That also implies that image must have a 'shape' attribute, and we some experience we know that NumPy arrays have a 'shape' attribute.
You may also look at drawing_utils.py.
Args:
image: A three channel RGB image represented as numpy ndarray.
Note:
It's hard to tell if there are other errors (it's hard to follow the code).
My answer address only the posted error messgae.

obj file loaded as Scene object instead of Trimesh object

I'm trying to load a mesh from an .obj file (from ShapeNet dataset) using Trimesh, and then use the repair.fix_winding(mesh) function.
But when I load the mesh, via
trimesh.load('/path/to/file.obj') or trimesh.load_mesh('/path/to/file.obj'),
the object class returned is Scene, which is incompatible with repair.fix_winding(mesh), only Trimesh object are accepted.
How can I force it to load and return a Trimesh object or parse the Scene object to Trimesh object? Or any other way to fix winding of the triangles?
Using:
Python 3.6.5
Trimesh 3.0.14
MacOS 10.14.5
With the current trimesh version (3.9.42), you need to use trimesh.load with force='mesh':
trimesh.load('/path/to/file.obj', force='mesh')
https://trimsh.org/trimesh.html?highlight=load#trimesh.load
I have the same problem. You can access the "geometry" member of the scene, but I have no idea how the original mesh is split into multiple ones. Following.
The load_mesh has an option to be passed as aa Trimesh constructor
as explained in the documentation.
https://trimsh.org/trimesh.html?highlight=load_mesh#trimesh.load_mesh
here is an example code
mesh= t.load_mesh('./test.stl',process=False)
mesh.is_watertight
the second line ".is_watertight" is an attribute of Trimesh so you will get True if it is successfully imported as Trimesh.

Get a centroid in QGIS via python

I am trying to get a centroid of a polygon in QGIS using python. Here is my code
layerPluto = iface.addVectorLayer("/path/to/mn_mappluto_16v1/MNMapPLUTO.shp", "PLUTO", "ogr")
features = layerPluto.getFeatures()
counter = 0
for feature in features:
# Get the first feature from the layer
if counter < 3:
print feature['Address']
print getCentroid(feature)
counter += 1
... which gives me a "name 'getCentroid' is not defined" error.
I find this surprising, since the QGIS python editor has getCentroid as a dropdown syntax-completion option.
I also tried using this function as a method of the feature object via feature.getCentroid() and received a similar error ("'QgsFeature' object has no attribute 'getCentroid'").
Similarly, trying centroid(feature) gives me the error "NameError: name 'centroid' is not defined," while feature.centroid() gives me "'QgsFeature' object has no attribute 'centroid'".
Is there another method I should be using for this operation?
centroid() is a method of QgsGeometry class.
You can retrieve the geometry section of a QgsFeature with geometry() method
and so you can obtain centroid geometry siply chaining the two methods:
feature.geometry().centroid()

Categories