How to optimize conversion from PyCBitmap to OpenCV image

旧巷老猫 提交于 2019-12-01 13:58:58

First time working with Python. I think I have a better understanding of now of the data structures. Here's the fix that drastically improves performance:

Change:

signedIntsArray = bmp.GetBitmapBits(False)
img = np.array(signedIntsArray).astype(dtype="uint8")

to:

signedIntsArray = bmp.GetBitmapBits(True)
img = np.fromstring(signedIntsArray, dtype='uint8')

and speed is greatly increased!

This is because it's a lot faster for the np library to create an array from a string than from a tuple.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!