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

blend_non_transparent multiplication error #3

Open
rhthomas opened this issue Jun 4, 2019 · 1 comment
Open

blend_non_transparent multiplication error #3

rhthomas opened this issue Jun 4, 2019 · 1 comment

Comments

@rhthomas
Copy link

rhthomas commented Jun 4, 2019

The program runs until the webcam on my laptop is engaged, then it fails with the following error. Looks like a matrix size mismatch.

...
Neural Network loaded!
Traceback (most recent call last):
  File "camera.py", line 19, in <module>
    output = sudoku_master(img)
  File "songoku/image_parsing.py", line 40, in sudoku_master
    img_final = blend_non_transparent(img_original, img_sudoku_final)
  File "songoku/helpers.py", line 95, in blend_non_transparent
    face_part = (face_img * (1 / 255.0)) * (background_mask * (1 / 255.0))
ValueError: operands could not be broadcast together with shapes (720,1280,3) (480,640,3) 
@rhthomas rhthomas changed the title blend_non_transparrent multiplication error blend_non_transparent multiplication error Jun 4, 2019
@rhthomas
Copy link
Author

Ah so the webcam on-board my device is 1280x720, so one needs to modify the perspective_transform function:

def perspective_transform(img, transformation_matrix, original_shape=None):
    warped = img

    if original_shape is not None:
        if original_shape[0] > 0 and original_shape[1] > 0:
            warped = cv2.resize(
                warped,
                (original_shape[1], original_shape[0]),
                interpolation=cv2.INTER_CUBIC,
            )

    white_image = np.zeros((640, 480, 3), np.uint8)

    white_image[:, :, :] = 255

    # warped = cv2.warpPerspective(warped, transformation_matrix, (640, 480), borderMode=cv2.BORDER_TRANSPARENT)
    warped = cv2.warpPerspective(warped, transformation_matrix, (640, 480))

    return warped

Swapping 640 for 1280, and 480 for 720 in this function stops the program crashing. Could be worth adding functionality to detect the dimensions of the camera at start-up.

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