简体   繁体   中英

dlib face detection error : Unsupported image type, must be 8bit gray or RGB image

i am trying to crop out the faces from instagram avatars by first detecting the faces and then resizing the image. i am reading all the images which have been stored in a dataframe and then creating a numpy array. Then i am running a frontal face detector which returns me an object but when i call the object it returns me the error stated. i tried giving only colored images as input but that did not work neither did try and except. Here is the code:

 df = pd.read_csv('/home/instaurls2.csv')
img_width, img_height = 139, 139
confidence = 0.8
#graph = K.get_session().graph
data1 = np.array([io.imread(row[1]) for row in df.itertuples()])
#print(data1)
detector = dlib.get_frontal_face_detector()
print (detector)
dets=detector(data1,1) # **error arrives here**
print (dets)
output=None
for i, d in enumerate(dets):
    data1 = data1[d.top():d.bottom(), d.left():d.right()]
    data1 = resize(data1, (img_width, img_height))
    output = np.expand_dims(data1, axis=0)
print (output)

Opencv reads image as BGR per default.

You can read images with cv2:

import cv2
cv2.imread(image_filepath)

This worked for me:

image.astype('uint8')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM