""" usage: mitmdump -T --anticache --host -s popeproxy.py """ from libmproxy.protocol.http import decoded import cv2 import sys import os import numpy as np sys.path.insert(0, os.getcwd()) import popeize papaj = cv2.imread("zoltamorda.png", -1) faceCascade = cv2.CascadeClassifier('features/haarcascade_frontalface_default.xml') types = { 'image/jpeg': '.jpg', 'image/png': '.png', } def response(context, flow): if 'content-type' not in flow.response.headers: return ctype = flow.response.headers['content-type'][0] if ctype not in types: return with decoded(flow.response): image = cv2.imdecode(np.fromstring(flow.response.content, dtype=np.uint8), -1) popeize.popeize(faceCascade, image, papaj, 1.1) success, encimg = cv2.imencode(types[ctype], image) if success: flow.response.content = encimg.tostring() print '*'*20, 'length', len(flow.reply.obj.response.content) print '*'*20, 'type', ctype