Initial commit

This commit is contained in:
informatic 2015-02-21 18:32:43 +01:00
commit 7b895209e9
7 changed files with 78517 additions and 0 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

30
livepopeize.py Normal file
View file

@ -0,0 +1,30 @@
import cv2
import sys
from popeize import popeize
# Get user supplied values
try:
cascPath = sys.argv[1]
except IndexError:
cascPath = 'features/haarcascade_frontalface_default.xml'
video_capture = cv2.VideoCapture(0)
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
papaj = cv2.imread("zoltamorda.png", -1)
while True:
ret, image = video_capture.read()
popeize(faceCascade, image, papaj, 1.3)
cv2.imshow("Video", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()

61
popeize.py Normal file
View file

@ -0,0 +1,61 @@
import cv2
import sys
def blit(l_img, s_img, x_offset, y_offset):
for c in range(0, 3):
l_img[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1], c] = s_img[:,:,c] * (s_img[:,:,3]/255.0) + l_img[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1], c] * (1.0 - s_img[:,:,3]/255.0)
def downscale(img, width, height):
factor = min(1.0*height/img.shape[0], 1.0*width/img.shape[1])
return cv2.resize(img, None, None, factor, factor)
def popeize(faceCascade, image, papaj, faceScale=1.5):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(gray, faceScale, 5)
print "Found {0} faces!".format(len(faces))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
factor = min(1.0*h/papaj.shape[0], 1.0*w/papaj.shape[1]) * 1.3
scaledpapaj = cv2.resize(papaj, None, None, factor, factor)
dx = x + (w/2) - scaledpapaj.shape[1]/2
dy = y + (h/2) - scaledpapaj.shape[0]/2
print dx, dy, factor
try:
blit(image, scaledpapaj, dx, dy)
except Exception as e:
print e, dx, dy, factor
#cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
if __name__ == '__main__':
imagePath = sys.argv[1]
cascPath = sys.argv[2]
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
image = cv2.imread(imagePath)
papaj = cv2.imread("zoltamorda.png", -1)
cv2.namedWindow("image")
def trackbarChanged(value):
image = cv2.imread(imagePath)
popeize(faceCascade, image, papaj, 1.1 + value/100.0)
cv2.imshow("image", downscale(image, 1024, 768))
print 'showed'
cv2.createTrackbar("scale", "image", 0, 300, trackbarChanged)
popeize(faceCascade, image, papaj, 1.1)
cv2.imwrite("output.jpg", image)
cv2.imshow("image", downscale(image, 1024, 768))
while cv2.waitKey(0) & 0xff != ord('q'):
pass

43
popeproxy.py Normal file
View file

@ -0,0 +1,43 @@
"""
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

BIN
zoltamorda.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB