簡體   English   中英

dlib 人臉檢測錯誤:不支持的圖像類型,必須是 8bit 灰度或 RGB 圖像

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

我正在嘗試通過首先檢測面部然后調整圖像大小來從 instagram 頭像中裁剪出面部。 我正在讀取存儲在 dataframe 中的所有圖像,然后創建一個 numpy 數組。 然后我正在運行一個正面檢測器,它返回給我一個 object 但是當我調用 object 時它返回給我說明的錯誤。 我嘗試只提供彩色圖像作為輸入,但這沒有用,也沒有嘗試和除外。 這是代碼:

 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將圖像讀取為BGR。

您可以使用cv2閱讀圖像:

import cv2
cv2.imread(image_filepath)

這對我有用:

image.astype('uint8')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM