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

Fix the bug with rasterize landmarks with matplotlib backend. #703

Merged
merged 6 commits into from
Jun 1, 2016

Conversation

grigorisg9gr
Copy link
Member

@grigorisg9gr grigorisg9gr commented May 30, 2016

The matplotlib backend was causing errors in python 3.
The following code crashed with ValueError:

im = mio.import_builtin_asset.lenna_png()
im1 = rasterize_landmarks_2d(im, 'LJSON')

In my machine it works now (python 2.7 and 3.4).

@@ -80,7 +80,8 @@ def _rasterize_matplotlib(image, pclouds, render_lines=True, line_style='-',
# Get the pixels directly from the canvas buffer which is fast
c_buffer, shape = f.canvas.print_to_buffer()
# Turn buffer into numpy array and reshape to image
pixels_buffer = np.array(c_buffer).reshape(shape[::-1] + (-1,))
pixels_buffer = np.fromstring(c_buffer, dtype=np.int8).reshape(shape[::-1] + (-1,))
pixels_buffer = pixels_buffer.astype(np.uint8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast twice - can just do it once:

    # Turn buffer into numpy array and reshape to image
    pixels_buffer = np.fromstring(c_buffer,
                                  dtype=np.uint8).reshape(shape[::-1] + (-1,))

@patricksnape patricksnape merged commit 803c7d9 into menpo:master Jun 1, 2016
@grigorisg9gr grigorisg9gr deleted the bug_rasterize_matplotlib branch June 1, 2016 10:34
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

Successfully merging this pull request may close these issues.

None yet

3 participants