I'm trying to locate the facial land marks of an image using openCV by getting the image using a URL, The code bellow gets the image using the url and converts it from a image to a list and then from a list to a string as before did this I got the error 'TypeError: expected string or Unicode object, list found',
I am currently getting:
Blockquote : Traceback (most recent call last): File "C:\Users\matth\Desktop\testmctest.py", line 52, in cv2.imshow('Result',annotate_landmarks(im,get_landmarks(im))) File "C:\Users\matth\Desktop\testmctest.py", line 31, in get_landmarks x,y,w,h =rects[0] IndexError: tuple index out of range
def get_landmarks(im):
rects = cascade.detectMultiScale(im, 1.3,5)
x,y,w,h =rects[0]
rect=dlib.rectangle(x,y,x+w,y+h)
return numpy.matrix([[p.x, p.y] for p in predictor(im, rect).parts()])
def annotate_landmarks(im, landmarks):
im = im.copy()
for idx, point in enumerate(landmarks):
pos = (point[0, 0], point[0, 1])
cv2.putText(im, str(idx), pos,
fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
fontScale=0.4,
color=(0, 0, 255))
cv2.circle(im, pos, 3, color=(0, 255, 255))
return im
URL = "http://static-23.sinclairstoryline.com/resources/media/d368a1cb-f6af-4a04-83d0-ebc66e984ab2-large16x9_BIOPIC.jpg?1456517822862"
from PIL import Image
import urllib2
im = Image.open(urllib2.urlopen(URL))
o = str(im)
img =[unicode(o, encoding="UTF-8")]
string = ''.join(map(str, img))
im=cv2.imread(string)
cv2.imshow('Result',annotate_landmarks(im,get_landmarks(im)))