import numpy as np
from scipy import signal
from opencv import adaptors
class scipyFromOpenCV(object):
"""This decorator can be used to wrap a function that takes
and returns a numpy array into one that takes and retuns an
opencv CvMat.
"""
def __init__(self, f):
self.f = f
def __call__(self, image):
# Convert CvMat to ndarray
np_image = adaptors.Ipl2NumPy(image)
# Call the original function
np_image_filtered = self.f(np_image)
# Convert back to CvMat
return adaptors.NumPy2Ipl(np_image_filtered)
@scipyFromOpenCV
def slowGaussianBlur(matrix):
"""Manual gaussian blur - Very very very slow!"""
filterSize = 3
filt = gauss_kern(filterSize)
r = signal.convolve(matrix[:,:,0],filt,'same')
g = signal.convolve(matrix[:,:,1],filt,'same')
b = signal.convolve(matrix[:,:,2],filt,'same')
result = array([r,b,g]).astype(uint8).transpose((1,2,0))
return result
While at PyConAU 2016 I attended the Monday sprints and spent some time looking at a proposed feature I hoped would soon be part of cryptography . As most readers of this blog will know, cryptography is a very respected project within the Python ecosystem and it was an interesting experience to see how such a prominent open source project handles contributions and reviews. The feature in question is the Diffie-Hellman Key Exchange algorithm used in many cryptography applications. Diffie-Helman Key Exchange is a way of generating a shared secret between two parties where the secret can't be determined by an eavesdropper observing the communication. DHE is extremely common - it is one of the primary methods used to provide "perfect forward secrecy" every time you initiate a TLS connection to an HTTPS website. Mathematically it is extremely elegant and the inventors were the recipients of the 2015 Turing award . I wanted to write about this particular contribution becau...