tramvm / recognize-license-plate

Recognize license plate with Python + OpenCV + ML(Google Vision)
Other
39 stars 21 forks source link

Attribute Error #1

Open Lokeswaran-J opened 5 years ago

Lokeswaran-J commented 5 years ago

AttributeError: 'NoneType' object has no attribute 'shape'

height, width = img.shape[:2]

tramvm commented 4 years ago

check your image source path bro.

ArjunSarihyan commented 4 years ago

i have a similar problem, my path is correct

tramvm commented 4 years ago

Please post your screenshot about your path folder and script config @ArjunSarihyan

ArjunSarihyan commented 4 years ago

def recognize_license_plate(img_path):

# Read image with opencv
img = cv2.imread(img_path)
print(img)

# Get image size
height, width = img.shape[:2]

# Scale image
img = cv2.resize(img, (800, int((height * 800) / width)))

# Show the origin image
cv2.imshow('Origin image', img)

# Save the image to temp file
cv2.imwrite(SOURCE_PATH + "output.jpg", img)

# Create new img path for google vision
img_path = SOURCE_PATH + "output.jpg"

# Create google vision client
client = vision.ImageAnnotatorClient()

# Read image file
with io.open(img_path, 'rb') as image_file:
    content = image_file.read()

image = vision.types.Image(content=content)

# Recognize text
response = client.text_detection(image=image)
texts = response.text_annotations

for text in texts:
    if len(text.description) == 10:
        license_plate = text.description
        print(license_plate)
        vertices = [(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices]

        # Put text license plate number to image
        cv2.putText(img, license_plate, (200, 200),

cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)

        print(vertices)
        # Draw rectangle around license plate
        cv2.rectangle(img, (vertices[0][0]-10, vertices[0][1]-10),

(vertices[2][0]+10, vertices[2][1]+10), (0, 255, 0), 3) print('Total time: {}'.format(datetime.now() - start_time)) cv2.imshow('Recognize & Draw', img) cv2.waitKey(0)

print('---------- Start recognize license palate --------') path = SOURCE_PATH + 'IMG_6041.jpg' recognize_license_plate(path) print('---------- End ----------')

Regards, Arjun Sarihyan

On Mon, Apr 6, 2020 at 11:51 AM tramvm notifications@github.com wrote:

Please post your screenshot about your path folder and script config @ArjunSarihyan https://github.com/ArjunSarihyan

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vmtram/recognize-license-plate/issues/1#issuecomment-609878201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJX5K5W3NF74JBHTHNJ4ZT3RLH3BXANCNFSM4INUDCJA .

tramvm commented 4 years ago

what is your SOURCE_PATH value @ArjunSarihyan . Please send me screenshot about folder content image also.

mohamedosa commented 4 years ago

i've the same problem