Sunday, 28 May 2017

Installing OpenCV3 for Python 3 on Windows

I need to use python for face recognition as part of the server for a charity app I'm working on. The app is supposed to show charity logos, but in the case of smaller charities, sometimes the google custom search I use to search for the logos returns instead a picture with a person in it. I need to identify cases where this happens and use a placeholder image instead.

My first attempt to install opencv was through pip from anaconda:

pip install opencv-python

However this gave me the following error when I tried to import cv2:

ImportError: DLL load failed: The specified module could not be found.

I uninstalled the anaconda version and found a 64 bit wheel of opencv for python 3.6 at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. Downloading this and installing it with pip worked perfectly. I don't know why the original error occured, but it looks like python 3 support might not be great with opencv at the moment.

Thursday, 18 May 2017

Using Python 3 to extract files from an encrypted archive with a password

Recently I needed to use python to extract the contents of a password-protected zip archive and I came across a few issues I thought would be good to document.

Python has a build in zipfile library that is really good at handling zip files, but unfortunately has a few limitations when it comes to encrypted zip files. This is how Python3 can be used to extract a file from an encrypted zip archive:


The first issue that I came across was some unclear documentation for the "open" method of zipfile in Python 3. The open method uses the "pwd" argument to pass the password for the file, but in Python 3 you need to convert this to bytes before calling open. Unfortunately, the library only seems to support CRC-32 based encryption  - meaning that the default linux zip encryption will work, but AES will not. I was also unable to get this to work with 7zip and WinZip.

HTML form won't submit (Angular)

 It turns out if you mix normal HTML forms with Angular ones (i.e. using FormsModule) Angular will disable the default behaviour of forms on...