arunponnusamy / cvlib

A simple, high level, easy to use, open source Computer Vision library for Python.
http://arunponnusamy.com/cvlib/
MIT License
647 stars 127 forks source link

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

Closed ghost closed 1 year ago

ghost commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Still the same error ...

arunponnusamy commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

What command are you using to run the code ?

ghost commented 1 year ago

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

arunponnusamy commented 1 year ago

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 commented 1 year ago

That is a typo. The folder name is images

arunponnusamy commented 1 year ago

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 commented 1 year ago

Still the same error ...

ghost commented 1 year ago

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