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

'str' object has no attribute 'shape' #52

Closed
ghost opened this issue Oct 31, 2022 · 13 comments
Closed

'str' object has no attribute 'shape' #52

ghost opened this issue Oct 31, 2022 · 13 comments

Comments

@ghost
Copy link

ghost commented Oct 31, 2022

When I try to use a function, do i get the error:

Traceback (most recent call last):
File "E:/python/test-object-detectie1.py", line 4, in
bbox, label, conf = cv.detect_common_objects('object_detection_input.jpg')
File "C:\Users\MyUserName\AppData\Local\Programs\Python\Python310\lib\site-packages\cvlib\object_detection.py", line 77, in detect_common_objects
Height, Width = image.shape[:2]
AttributeError: 'str' object has no attribute 'shape'

Can someone help me?

@arunponnusamy
Copy link
Owner

You need to read the image before passing it to detect_common_objects function.

# read input image
image = cv2.imread('object_detection_input.jpg')

# apply object detection
bbox, label, conf = cv.detect_common_objects(image)

Checkout this complete example.

@ghost
Copy link
Author

ghost commented Nov 11, 2022

As i try that, i get the second error:Traceback (most recent call last): File "G:\SR4E1\test-object-detectie1.py", line 12, in <module> bbox, label, conf = cv.detect_common_objects(image) File "C:\Users\philippechristl\AppData\Local\Programs\Python\Python310\lib\site-packages\cvlib\object_detection.py", line 77, in detect_common_objects Height, Width = image.shape[:2] AttributeError: 'NoneType' object has no attribute 'shape'

@arunponnusamy
Copy link
Owner

Make sure that you are giving the correct path to the input image while reading using cv2.imread. Try giving the complete path to the image. For example, if the image is in SR4E1 folder, try using the path as below.

image = cv2.imread('G:\SR4E1\object_detection_input.jpg')

Checkout this Colab notebook to learn more.

@ghost
Copy link
Author

ghost commented Nov 21, 2022

Still the same error ...

@arunponnusamy
Copy link
Owner

Can you share the complete code and input image you are using ? Let me try to reproduce this error on my end for debugging. Please share the version of OpenCV, cvlib and Python as well.

@ghost
Copy link
Author

ghost commented Nov 25, 2022

python version = 3.10.8
cvlib version = 0.2.7
OpenCV version = 1.0.0
image = https://github.com/arunponnusamy/cvlib/blob/master/examples/images/object_detection_input.jpg

`import cvlib as cv
from cvlib.object_detection import draw_bbox
import sys
import cv2

image = cv2.imread(sys.argv[1])

bbox, label, conf = cv.detect_common_objects(image)
print(bbox, label, conf)

out = draw_bbox(image, bbox, label, conf)

cv2.imshow("object_detection", out)
cv2.waitKey()

cv2.imwrite("object_detection.jpg", out)

cv2.destroyAllWindows()`

@arunponnusamy
Copy link
Owner

What command are you using to run the code ?

@ghost
Copy link
Author

ghost commented Dec 3, 2022

python E:\SR4E1\test-object-detectie1.py E:\SR4E1\imeges\object_detection_input.jpg (on Windows 10)

@arunponnusamy
Copy link
Owner

It seems that there is issue in reading the image. Are you sure the path to the input image is correct ?
The folder name is images or imeges ? Is that a typo ?

@ghost
Copy link
Author

ghost commented Dec 5, 2022

That is a typo. The folder name is images

@arunponnusamy
Copy link
Owner

Can you try running the command from the SR4E1 folder ?

cd E:\SR4E1\
python test-object-detectie1.py E:\SR4E1\images\object_detection_input.jpg

@ghost
Copy link
Author

ghost commented Dec 7, 2022

Still the same error ...

@ghost
Copy link
Author

ghost commented Dec 20, 2022

As i convert the images to PNG it's work! Thank you for helping me. (and for the easy to use libarty)

@ghost ghost closed this as completed Dec 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant