Contribution 4: Porting to Python 3 and and other changes
After considering declining support for Python 2 programming language and added benefits from upgrades to Python 3, it is always advisable for a developer to select Python version 3. So, from the statement above, it is pretty much obvious that the first task assigned to me was porting the People Counter module from Python 2 to Python 3 which is done. Changes made are:
- Changed all print statements from
print " "
toprint()
. - Python3 uses the module
queue
and notQueue
. - In Python 3 there are two different types of strings:
- The bytes type:
This is just a sequence of bytes, Python doesn’t know anything about how to interpret this as characters. - The str type:
This is also a sequence of bytes, but Python knows how to interpret those bytes as characters. So, to conversion of an empty string into bytes, can be done with
msg = bytes('', encoding = 'utf-8')
- The bytes type:
In this process I learned that due to significant refactoring done in the latest version python openpifpaf library some functions also need to be changed accordingly in our component. So, I have made the component work with the openpifpaf library version = 0.10.1. The changes I needed to make were:
- I had to change the line:
processed_image_cpu = transforms.image_transform(image.copy())
in specificworker.py to:
processed_image_cpu, _, __ = transforms.EVAL_TRANSFORM(image_pil, [], None)
becauseimage_transform
is no longer inopenpifpaf.transforms.
because of the version update of OpenpifPaf Library. - I also had to convert the image to a PIL image before passing it through the function mentioned above from a CV2 image as the function only accepts PIL image with the following:
image_pil = PIL.Image.fromarray(image)
There were also a few very minor bugs which I fixed. So Now the component is up and running and I have made Pull-request for the same, do check it out!!!