Home Ask Login Register

Developers Planet

Your answer is one click away!

user5538206 February 2016

how to show my image in array or matrix in python?

I have an array like:

{(0, 27): 0.0, (0, 20): 0.0, (0, 14): 0.0, (0, 7): 0.0, (0, 16): 0.0, (0, 10): 0.0, (0, 3): 0.0, (0, 28): 0.0, (0, 21): 0.0, (0, 15): 0.0, (0, 24): 0.0, (0, 17): 0.0, (0, 11): 0.0, (0, 4): 0.0, (0, 29): 0.0, (0, 22): 0.0, (0, 0): 0.0, (0, 25): 0.0, (0, 18): 0.0, (0, 12): 0.0, (0, 5): 0.0, (0, 30): 0.0, (0, 8): 0.0, (0, 23): 0.0, (0, 1): 0.0, (0, 26): 0.0, (0, 19): 0.0, (0, 13): 0.0, (0, 6): 0.0, (0, 31): 0.0, (0, 9): 0.0, (0, 2): 0.0}

and it is an image and I want to draw it. First how should I draw it in python opencv? I know I should use

cv2.imshow('M',M )
cv2.waitKey()

but the error is:

ypeError: mat is not a numpy array, neither a scalar

and when I change it into matrix by:

zas = np.asmatrix(M)


[[ {(0, 27): 0.0, (0, 20): 0.0, (0, 14): 0.0, (0, 7): 0.0, (0, 16): 0.0, (0, 10): 0.0, (0, 3): 0.0, (0, 28): 0.0, (0, 21): 0.0, (0, 15): 0.0, (0, 24): 0.0, (0, 17): 0.0, (0, 11): 0.0, (0, 4): 0.0, (0, 29): 0.0, (0, 22): 0.0, (0, 0): 0.0, (0, 25): 0.0, (0, 18): 0.0, (0, 12): 0.0, (0, 5): 0.0, (0, 30): 0.0, (0, 8): 0.0, (0, 23): 0.0, (0, 1): 0.0, (0, 26): 0.0, (0, 19): 0.0, (0, 13): 0.0, (0, 6): 0.0, (0, 31): 0.0, (0, 9): 0.0, (0, 2): 0.0}]]

the error is:

TypeError: mat data type = 17 is not supported

would you please tell me what mistake I am making?

Answers


Rahul K P February 2016

If you try to looking for values in that dictionary to draw as image. It's simple.It hold 32 values and i hope it's a size of image is 1 by 32. Then you can Plot like this. I considered a as your dictionary.

a = {(0, 27): 0.0, (0, 20): 0.0, (0, 14): 0.0, (0, 7): 0.0, (0, 16): 0.0, (0, 10): 0.0, (0, 3): 0.0, (0, 28): 0.0, (0, 21): 0.0, (0, 15): 0.0, (0, 24): 0.0, (0, 17): 0.0, (0, 11): 0.0, (0, 4): 0.0, (0, 29): 0.0, (0, 22): 0.0, (0, 0): 0.0, (0, 25): 0.0, (0, 18): 0.0, (0, 12): 0.0, (0, 5): 0.0, (0, 30): 0.0, (0, 8): 0.0, (0, 23): 0.0, (0, 1): 0.0, (0, 26): 0.0, (0, 19): 0.0, (0, 13): 0.0, (0, 6): 0.0, (0, 31): 0.0, (0, 9): 0.0, (0, 2): 0.0}
In [20]: zas = np.asmatrix(a.values())
In [24]: cv2.imshow('M',zas)
In [25]: cv2.waitKey()

But it's not a good method to store image as dictionary. Try to maintain as a numpy array.

Post Status

Asked in February 2016
Viewed 2,455 times
Voted 7
Answered 1 times

Search




Leave an answer


Quote of the day: live life