Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am unable to run the command detail_ImageFeatures().descriptors in Python #16401

Open
VisheshKhosla opened this issue Jan 21, 2020 · 9 comments

Comments

@VisheshKhosla
Copy link

VisheshKhosla commented Jan 21, 2020

System Version(Information)

  • OpenCV =>4.1.2 (Python 3.7.3)
  • Operating System / Platform => Windows 10 64 Bit
  • Hardware => Dell Inspiron 7460
  • Compiler/Interpreter => Jupyter Notebooks
  • GPU =>NVIDIA 940MX

Detailed Description

I am unable to access a public data member of cv::detail::ImageFeatures::descriptors. When i run this command:
import cv2 obj_Umat=cv2.detail_ImageFeatures().descriptors

The command cv2.detail_ImageFeatures().descriptors returns a UMat object.
My interpreter then gives me a response that :

The kernel appears to have died

@alalek
Copy link
Member

alalek commented Jan 21, 2020

Please clarify what are you trying to do? What is expected result?

@VisheshKhosla
Copy link
Author

I am not aiming to do something,but why is my code not working? I was just trying out these data members present in this documentation: https://docs.opencv.org/3.4/d4/db5/structcv_1_1detail_1_1ImageFeatures.html#details
All are working fine except descriptors and keypoints.

@czgdp1807
Copy link
Contributor

Hi,
I tried the code above. It looks like for me, bindings for cv::detail::ImageFeatures. I checked build-opencv/modules/python_bindings_generator/pyopencv_signatures.json and observed that there is not key for cv::detail::ImageFeatures. Is that the underlying issue? What was the error when you tried to execute the above line. Thanks.

@alalek
Copy link
Member

alalek commented Jan 22, 2020

  • dir(image_features_object) ?
  • image_features_object.getKeypoints() ?

@saskatchewancatch
Copy link
Contributor

saskatchewancatch commented Feb 10, 2020

@czgdp1807 Not in the Python2 lib. In Python3, yes. You will see the key when you import cv2 in Python3 interpreter. For OP, it seems the underlying issue is that accessing the descriptors attribute of the struct results in a seg fault.

@alalek

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> f = cv2.detail_ImageFeatures()
>>> dir(f)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'descriptors', 'getKeypoints', 'img_idx', 'img_size']
>>> f.getKeypoints
<built-in method getKeypoints of cv2.detail_ImageFeatures object at 0x7fce3dc3fbe0>
>>> f.getKeypoints()
[]
>>> f.descriptors()
Segmentation fault (core dumped)

I don't use Stitching module, and I don't use the Python API, but it seems to me I should get an empty numpy array or None type instead of segfault.

I'm running a Ubuntu 18.04 on a VM with no GPU. Still, an unset UMat attribute should return None even if no reliance on OpenCL. I wonder if all UMat's members in structs accessed through Python3 api cause such segfaults.

@rllyryan
Copy link

Any leads on this? I am trying to transfer information from features detected by SIFT into a detail_ImageFeatures object.

@Sanyam-Mehta
Copy link

@czgdp1807 Not in the Python2 lib. In Python3, yes. You will see the key when you import cv2 in Python3 interpreter. For OP, it seems the underlying issue is that accessing the descriptors attribute of the struct results in a seg fault.

@alalek

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> f = cv2.detail_ImageFeatures()
>>> dir(f)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'descriptors', 'getKeypoints', 'img_idx', 'img_size']
>>> f.getKeypoints
<built-in method getKeypoints of cv2.detail_ImageFeatures object at 0x7fce3dc3fbe0>
>>> f.getKeypoints()
[]
>>> f.descriptors()
Segmentation fault (core dumped)

I don't use Stitching module, and I don't use the Python API, but it seems to me I should get an empty numpy array or None type instead of segfault.

I'm running a Ubuntu 18.04 on a VM with no GPU. Still, an unset UMat attribute should return None even if no reliance on OpenCL. I wonder if all UMat's members in structs accessed through Python3 api cause such segfaults.

I am also seeing a segfault when I try to access the descriptors. Are there any updates on this?

@berak
Copy link
Contributor

berak commented Sep 27, 2022

related: #20979

hmm it generates code like this:

static PyObject* pyopencv_detail_ImageFeatures_get_descriptors(pyopencv_detail_ImageFeatures_t* p, void *closure)
{
    return pyopencv_from(p->v.descriptors);
}

but i cant find pyopencv_from(const UMat &m) anywhere.

@xmba15
Copy link

xmba15 commented Jun 28, 2023

This is a little hack to create an empty cv2.detail_ImageFeatures and access its descriptors

image_features = cv2.detail.computeImageFeatures2(
      cv2.SIFT_create(),
      np.zeros_like((0, 0), dtype=np.uint8),
      np.zeros_like((0, 0), dtype=np.uint8),
)
image_features.descriptors # of type cv2.UMat

# update descriptors:
# image_features.descriptors = cv2.UMat(some numpy array)

After that, you can also update image_features ' keypoints, img_size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants