簡體   English   中英

合並LBP和HOG功能描述符

[英]Merge LBP and HOG feature descriptors

我正在研究年齡,性別評估項目。 到目前為止,我已經嘗試使用LBP(局部二進制模式)+ SVM(支持向量機)來訓練它的性別分類,但是在使用LBP + SVM時會得到太多的誤報,所以我嘗試使用HOG(梯度直方圖) )+ SVM,令人驚訝的是,准確性提高了90%,因此,盡管我合並了描述符的功能並使用它來訓練SVM。 的代碼如下:

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    fd = hog(gray, orientations, pixels_per_cell, cells_per_block, visualize, normalize) #HOG descriptor here.

    hist = desc.describe(gray) #get the LBP histogram here.

    # extract the label from the image path, then update the
    # label and data lists
    labels.append(imagePath.split("/")[-2])
    data.append(fd + hist) # tried concatinate both featurs, but gives error on this line.

# train a Linear SVM on the data
model = LinearSVC(C=100.0, random_state=42)
model.fit(data, labels)

但是當嘗試這一行時: data.append(fd + hist)只是試圖同時連接兩個特征描述符,並引發以下錯誤:

追溯(最近一次通話最近):文件“ /home/swap/Ubuntu-Home/swap/openCV/gender_age_weight_recog/tarin.py”,

data.append(fd + hist)ValueError中的第41行:操作數不能與形狀(11340,)(26,)一起廣播

因此,有人可以指出我以便將兩個功能合並為一個功能,然后為此訓練SVM。

我想出了一個問題,一個人可以簡單地堆疊numpy數組,具有類似形狀的任何特征描述符,例如HOG和LBPH在灰度圖像上工作,因此在這種情況下,由LBP,HOG will always be one生成的特征的深度LBP,HOG will always be one ,因此我們可以使用numpy堆疊它們,

    desc_hist = desc.describe(gray_img)
    hog_hist = hog(gray_img, orientations, pixels_per_cell, cells_per_block, 'L1', visualize, normalize)      
    feat = np.hstack([desc_hist, hog_hist])

但假設有人想合並適用於3通道圖像(RGB)的hsv直方圖,則可以將其展平為一維數組,然后也可以堆疊為具有該特征的正則。

hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
hist = cv2.calcHist([hsv], [0, 1, 2], None, bins,
                    [0, 180, 0, 256, 0, 256])

hist = cv2.normalize(hist)

# return the flattened histogram as the feature vector
td_hist = hist.flatten()

現在,所有的東西都可以照常stacked

feat = np.hstack([desc_hist, hog_hist, td_hist])

問題是您試圖添加兩個大小不同的數組。 一個數組包含11340個元素,另一個數組包含26個元素。在存儲這些值並將其不加在一起時,應更改邏輯

暫無
暫無

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

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