import numpy as np
import urllib 
import matplotlib.pyplot as plt 
import cv2

#funcion to read image from url
def url2image(url):
    resp = urlopen(url) # download image from url
    image = np.asarray(bytearray(resp.read()),dtype ='uint8') #convert it to a Numpy array
    image = cv2.imdecode(image, cv2.IMREAD_COLOR) # read it into OpenCV format
    return image
import sys
if sys.version_info[0] == 3:
    from urllib.request import urlopen
else:
    from urllib import urlopen
import os.path

#Main
#load image from url
bgr_img = url2image('https://phunghuy.files.wordpress.com/2012/10/steve-jobs1.jpg?w=1140')
gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
face_classifier_xml = 'my_haarcascade_frontalface_default.xml'
ret = os.path.exists(face_classifier_xml)

if ret:
    print('the cascade classifier xml file already existed\n')
else:
    print('downloading the cascade classifier xml file from internet...\n')

face_classifier_url = 'https://raw.githubusercontent.com/shantnu/Webcam-Face-Detect/master/'+'haarcascade_frontalface_default.xml'

resp = urlopen(face_classifier_url)
data=resp.read()
fh = open(face_classifier_xml, 'wb')

fh.write(data)
fh.close()
resp.close()

face_cascade = cv2.CascadeClassifier(face_classifier_xml)
faces = face_cascade.detectMultiScale(gray_img, 1.25, 3)
for(x,y,w,h) in faces:
    cv2.rectangle(bgr_img,(x,y),(x+w,y+h),(255,0,0),2)
    
plt.axis('off')
plt.title('face detecion result')
plt.imshow(cv2.cvtColor(bgr_img,cv2.COLOR_BGR2RGB))
plt.show()

c611add9052935524ce33a73c71b2947214fb24e
<mask token>


def url2image(url):
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype='uint8')
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    return image


<mask token>

<mask token>


def url2image(url):
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype='uint8')
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    return image


<mask token>
if sys.version_info[0] == 3:
    from urllib.request import urlopen
else:
    from urllib import urlopen
<mask token>
if ret:
    print('the cascade classifier xml file already existed\n')
else:
    print('downloading the cascade classifier xml file from internet...\n')
<mask token>
fh.write(data)
fh.close()
resp.close()
<mask token>
for x, y, w, h in faces:
    cv2.rectangle(bgr_img, (x, y), (x + w, y + h), (255, 0, 0), 2)
plt.axis('off')
plt.title('face detecion result')
plt.imshow(cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB))
plt.show()

<mask token>


def url2image(url):
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype='uint8')
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    return image


<mask token>
if sys.version_info[0] == 3:
    from urllib.request import urlopen
else:
    from urllib import urlopen
<mask token>
bgr_img = url2image(
    'https://phunghuy.files.wordpress.com/2012/10/steve-jobs1.jpg?w=1140')
gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
face_classifier_xml = 'my_haarcascade_frontalface_default.xml'
ret = os.path.exists(face_classifier_xml)
if ret:
    print('the cascade classifier xml file already existed\n')
else:
    print('downloading the cascade classifier xml file from internet...\n')
face_classifier_url = (
    'https://raw.githubusercontent.com/shantnu/Webcam-Face-Detect/master/' +
    'haarcascade_frontalface_default.xml')
resp = urlopen(face_classifier_url)
data = resp.read()
fh = open(face_classifier_xml, 'wb')
fh.write(data)
fh.close()
resp.close()
face_cascade = cv2.CascadeClassifier(face_classifier_xml)
faces = face_cascade.detectMultiScale(gray_img, 1.25, 3)
for x, y, w, h in faces:
    cv2.rectangle(bgr_img, (x, y), (x + w, y + h), (255, 0, 0), 2)
plt.axis('off')
plt.title('face detecion result')
plt.imshow(cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB))
plt.show()

import numpy as np
import urllib
import matplotlib.pyplot as plt
import cv2


def url2image(url):
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype='uint8')
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)
    return image


import sys
if sys.version_info[0] == 3:
    from urllib.request import urlopen
else:
    from urllib import urlopen
import os.path
bgr_img = url2image(
    'https://phunghuy.files.wordpress.com/2012/10/steve-jobs1.jpg?w=1140')
gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
face_classifier_xml = 'my_haarcascade_frontalface_default.xml'
ret = os.path.exists(face_classifier_xml)
if ret:
    print('the cascade classifier xml file already existed\n')
else:
    print('downloading the cascade classifier xml file from internet...\n')
face_classifier_url = (
    'https://raw.githubusercontent.com/shantnu/Webcam-Face-Detect/master/' +
    'haarcascade_frontalface_default.xml')
resp = urlopen(face_classifier_url)
data = resp.read()
fh = open(face_classifier_xml, 'wb')
fh.write(data)
fh.close()
resp.close()
face_cascade = cv2.CascadeClassifier(face_classifier_xml)
faces = face_cascade.detectMultiScale(gray_img, 1.25, 3)
for x, y, w, h in faces:
    cv2.rectangle(bgr_img, (x, y), (x + w, y + h), (255, 0, 0), 2)
plt.axis('off')
plt.title('face detecion result')
plt.imshow(cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB))
plt.show()

import numpy as np
import urllib 
import matplotlib.pyplot as plt 
import cv2

#funcion to read image from url
def url2image(url):
    resp = urlopen(url) # download image from url
    image = np.asarray(bytearray(resp.read()),dtype ='uint8') #convert it to a Numpy array
    image = cv2.imdecode(image, cv2.IMREAD_COLOR) # read it into OpenCV format
    return image
import sys
if sys.version_info[0] == 3:
    from urllib.request import urlopen
else:
    from urllib import urlopen
import os.path

#Main
#load image from url
bgr_img = url2image('https://phunghuy.files.wordpress.com/2012/10/steve-jobs1.jpg?w=1140')
gray_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2GRAY)
face_classifier_xml = 'my_haarcascade_frontalface_default.xml'
ret = os.path.exists(face_classifier_xml)

if ret:
    print('the cascade classifier xml file already existed\n')
else:
    print('downloading the cascade classifier xml file from internet...\n')

face_classifier_url = 'https://raw.githubusercontent.com/shantnu/Webcam-Face-Detect/master/'+'haarcascade_frontalface_default.xml'

resp = urlopen(face_classifier_url)
data=resp.read()
fh = open(face_classifier_xml, 'wb')

fh.write(data)
fh.close()
resp.close()

face_cascade = cv2.CascadeClassifier(face_classifier_xml)
faces = face_cascade.detectMultiScale(gray_img, 1.25, 3)
for(x,y,w,h) in faces:
    cv2.rectangle(bgr_img,(x,y),(x+w,y+h),(255,0,0),2)
    
plt.axis('off')
plt.title('face detecion result')
plt.imshow(cv2.cvtColor(bgr_img,cv2.COLOR_BGR2RGB))
plt.show()
