2
votes

After cloning the GitHub repo of OpenCV, I am trying to run grabcut.py but I am getting error : Traceback (most recent call last): File "grabcut.py", line 114, in img = cv.imread(cv.samples.findFile(filename)) AttributeError: module 'cv2.cv2' has no attribute 'samples'

Here is the link to the file: https://github.com/opencv/opencv/blob/master/samples/python/grabcut.py

2
cv2.samples.findFile is used to find filepath. At least in OpenCV 4.0.1 (python), there is no cv2.samples submodule. You can just write a findFile to generate absolute path, such as os.path.join("/ABSOLUTE_OPENCV/samples/data/", filename) . Notice, you can download samples/data from github/opencvKinght 金

2 Answers

1
votes

samples submodule is available in opencv-python version 4.0.0.21. Use pip install to install that specific version, or a later version that has this submodule.

pip install opencv-python==4.0.0.21
1
votes

Change

img = cv.imread(cv.samples.findFile(fileName))

To

img = cv.imread(fileName)

as there is no cv.samples module