'str' object has no attribute 'shape'
opened this issue · comments
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?
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.
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'
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.
Still the same error ...
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.
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()`
What command are you using to run the code ?
python E:\SR4E1\test-object-detectie1.py E:\SR4E1\imeges\object_detection_input.jpg (on Windows 10)
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 ?
That is a typo. The folder name is images
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
Still the same error ...
As i convert the images to PNG it's work! Thank you for helping me. (and for the easy to use libarty)