1

I am trying to use SIFT from OpenCV in a Google Cloud Function. I am encountering an issue due to the fact that SIFT is actually only in opencv-contrib-python for Python 3.

Firebase Logs

  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 346, in run_http_function
    result = _function_handler.invoke_user_function(flask.request)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 210, in call_user_function
    return self._user_function(request_or_event)
  File "/user_code/main.py", line 149, in findMatches
    maxMatches = siftMatcher(logoToSearch,cv_imgs[i])
  File "/user_code/main.py", line 80, in siftMatcher
    sift = cv2.xfeatures2d.SIFT_create()
AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'

requirements.txt

# File: requirements.txt
opencv-python
opencv-contrib-python
...

main.py

# File: main.py
import cv2
...
sift = cv2.xfeatures2d.SIFT_create()
Nicholas
  • 501
  • 2
  • 14
Anters Bear
  • 1,816
  • 1
  • 15
  • 41
  • FWIW, The Cloud Functions *are* running on Python 3 (3.7.1 to be precise), see [The Python Runtime](https://cloud.google.com/functions/docs/concepts/python-runtime) – Dan Cornilescu Apr 20 '19 at 15:03
  • Possible duplicate of [AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' \[Opencv 3.4.3\]](https://stackoverflow.com/questions/52669705/attributeerror-module-cv2-cv2-has-no-attribute-xfeatures2d-opencv-3-4-3) – Dustin Ingram Apr 22 '19 at 18:14

0 Answers0