[Python] no alphabet output in real time sign language to speech conversion project

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo


    these are the model details

    Model: "sequential_1" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ │ dense_3 (Dense) │ (None, 128) │ 100,480 │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ batch_normalization │ (None, 128) │ 512 │ │ (BatchNormalization) │
    │ │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ dropout (Dropout) │ (None, 128) │ 0 │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ dense_4 (Dense) │ (None, 64) │ 8,256 │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ batch_normalization_1 │ (None, 64) │ 256 │ │ (BatchNormalization) │
    │ │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ dropout_1 (Dropout) │ (None, 64) │ 0 │ ├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤ │ dense_5 (Dense) │ (None, 10) │ 650 │ └──────────────────────────────────────┴─────────────────────────────┴─────────────────┘


    Total params: 110,154 (430.29 KB) Trainable params: 109,770 (428.79 KB) Non-trainable params: 384 (1.50 KB)

    inal training accuracy: 0.9999 Final validation accuracy: 1.0000
    ​

    79/79 ━━━━━━━━━━━━━━━━━━━━ 0s 1ms/step Confusion Matrix: |[[254 0
    0 0 0 0 0 0 0 0]| |[ 0 253 0 0 0 0 0 0 0 0]| |[ 0 0 252 0 0 0 0 0 0 0]| |[ 0 0 0 253 0 0 0 0 0 0]| |[ 0 0 0 0 253 0 0 0 0 0]| |[ 0 0 0 0 0 253 0 0 0 0]| |[ 0 0 0 0 0 0 0 253 0 0]| |[ 0 0 0 0 0 0 0 0 252 0]| |[ 0 0 0 0 0 0 0 0 0 253]]|

    Classification Report: precision recall f1-score support

    0 1.00 1.00 1.00 254
    1 1.00 1.00 1.00 253
    2 1.00 1.00 1.00 252
    3 1.00 1.00 1.00 253
    4 1.00 1.00 1.00 253
    5 1.00 1.00 1.00 253
    6 1.00 1.00 1.00 252
    7 1.00 1.00 1.00 253
    8 1.00 1.00 1.00 252
    9 1.00 1.00 1.00 253


    accuracy 1.00 2528 macro avg
    1.00 1.00 1.00 2528 weighted avg 1.00 1.00 1.00 2528
    ​

    ```

    # Convert the BGR image to RGB
    rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    # Process the image and find hands
    results = hands.process(rgb_img)

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Check if hand landmarks are detected
    if results.multi_hand_landmarks:
    for hand_landmarks in results.multi_hand_landmarks:
    # Draw hand landmarks
    mp_drawing.draw_landmarks(img, hand_landmarks, mp_hands.HAND_CONNECTIONS)

    # Calculate bounding box around the hand
    h, w, c = img.shape
    x_max = 0
    y_max = 0
    x_min = w
    y_min = h

    for lm in hand_landmarks.landmark:
    x, y = int(lm.x * w), int(lm.y * h)
    if x > x_max:
    x_max = x
    if x < x_min:
    x_min = x
    if y > y_max:
    y_max = y
    if y < y_min:
    y_min = y

    # Add padding to the bounding box
    padding = 20
    x_min = max(0, x_min - padding)
    y_min = max(0, y_min - padding)
    x_max = min(w, x_max + padding)
    y_max = min(h, y_max + padding)

    # Draw rectangle around hand
    cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color_dict, 2)

    # Crop the hand region
    if x_min < x_max and y_min < y_max: # Ensure valid crop region
    crop_img = gray[y_min:y_max, x_min:x_max]
    if crop_img.size != 0: # Check if crop is not empty
    count = count + 1
    if(count % 100 == 0):
    prev_val = count

    # Process the cropped hand image
    blur = cv2.GaussianBlur(crop_img, (5, 5), 2)
    th3 = cv2.adaptiveThreshold(blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
    ret, res = cv2.threshold(th3, minValue, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)

    # Resize to match model input size
    resized = cv2.resize(res, (img_size, img_size))
    normalized = resized/255.0
    reshaped = np.reshape(normalized, (1, img_size, img_size, 1))

    # Predict with model
    result = model.predict(reshaped)
    label = np.argmax(result, axis=1)[0]

    if(count == 300):
    count = 99
    prev = labels_dict[label]
    if(label == 0):
    string = string + " "
    else:
    string = string + prev

    # Show the processed hand image
    cv2.imshow("Hand", res)
    else:
    # If no hand is detected, reset counter
    count = 0

    cv2.putText(img, prev, (24, 14), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
    cv2.putText(img, string, (275, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (200, 200, 200), 2)
    #cv2.putText(img, str(prev_val//100), (300, 150), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255, 255, 255), 2)

    cv2.imshow('LIVE', img)
    key = cv2.waitKey(1)

    if(key == 27): # press Esc. to exit
    break


    ```


    `


    whenever the cell is run it accurately recognizes the hand and moves around with it but is does not convert the gestures to alphabets
    ​

    Continue reading...

Compartilhe esta Página