<commit_before>import praw
import urllib
import cv2, numpy as np
from PIL import Image

eyeData = "xml/eyes.xml"
glasses = cv2.imread('assets/glasses.png', cv2.IMREAD_UNCHANGED)
DOWNSCALE = 2
foundImage = False

r = praw.Reddit('/u/powderblock Glasses Bot')

for post in r.get_subreddit('all').get_new(limit=15):
        if "imgur.com" in post.url and (".jpg" in post.url or ".png" in post.url):
                        print str(post.url)
                        foundImage = True
                        break

if foundImage:
        response = urllib.urlopen(str(post.url))
        # load the image we want to detect features on
        # Convert rawImage to Mat
        filearray = np.asarray(bytearray(response.read()), dtype=np.uint8)
        frame = cv2.imdecode(filearray, cv2.CV_LOAD_IMAGE_UNCHANGED)
        minisize = (frame.shape[1]/DOWNSCALE,frame.shape[0]/DOWNSCALE)
        miniframe = cv2.resize(frame, minisize)
        cv2.imshow("Loading Image Buffer From a URL", miniframe)<commit_msg>Add glasses if eyes are found<commit_after>import praw
import urllib
import cv2, numpy as np
from PIL import Image

eyeData = "xml/eyes.xml"
eyeClass = cv2.CascadeClassifier(eyeData)
glasses = cv2.imread('assets/glasses.png', cv2.IMREAD_UNCHANGED)
ratio = glasses.shape[1] / glasses.shape[0]
DOWNSCALE = 4
foundImage = False

r = praw.Reddit('/u/powderblock Glasses Bot')

for post in r.get_subreddit('all').get_new(limit=30):
        if "imgur.com" in post.url and (".jpg" in post.url or ".png" in post.url):
                        response = urllib.urlopen(str(post.url))
                        # load the image we want to detect features on
                        # Convert rawImage to Mat
                        filearray = np.asarray(bytearray(response.read()), dtype=np.uint8)
                        frame = cv2.imdecode(filearray, cv2.CV_LOAD_IMAGE_UNCHANGED)
                        minisize = (frame.shape[1]/DOWNSCALE,frame.shape[0]/DOWNSCALE)
                        miniframe = cv2.resize(frame, minisize)
                        eyes = eyeClass.detectMultiScale(miniframe)
                        if len(eyes) > 0:
                                print str(post.url)
                                foundImage = True
                                break

# Only process if the image was found
if foundImage:
        for eye in eyes:
            x, y, w, h = [v * DOWNSCALE for v in eye]
            h = w / ratio
            y += h / 2
            # resize glasses to a new var called small glasses
            smallglasses = cv2.resize(glasses, (w, h))
            # the area you want to change
            bg = frame[y:y+h, x:x+w]
            bg *= np.atleast_3d(255 - smallglasses[:, :, 3])/255.0
            bg += smallglasses[:, :, 0:3] * np.atleast_3d(smallglasses[:, :, 3])
            # put the changed image back into the scene
            frame[y:y+h, x:x+w] = bg
        cv2.imwrite(str(post.url), frame)
{'fraction_non_alphanumeric': 0.10649880911874787, 'fraction_numerical': 0.015311330384484519, 'mean_word_length': 1.9726996966632964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1800502', 'n_tokens_mistral': 950, 'n_tokens_neox': 914, 'n_words': 242}