開發(fā)網(wǎng)站需要注意網(wǎng)站開發(fā)和安卓開發(fā)
鶴壁市浩天電氣有限公司
2026/01/24 12:25:54
開發(fā)網(wǎng)站需要注意,網(wǎng)站開發(fā)和安卓開發(fā),有沒有專做游戲腳本的網(wǎng)站,寧寧網(wǎng)seo一、HOG特征提取實現(xiàn)
1. 核心算法流程
function hog_feat compute_hog(img)% 輸入#xff1a;灰度圖像#xff08;單通道#xff09;% 輸出#xff1a;歸一化后的HOG特征向量% 參數(shù)設(shè)置cell_size 8; % cell尺寸#xff08;像素#xff09;block_size 2; % bloc…一、HOG特征提取實現(xiàn)1. 核心算法流程functionhog_featcompute_hog(img)% 輸入灰度圖像單通道% 輸出歸一化后的HOG特征向量% 參數(shù)設(shè)置cell_size8;% cell尺寸像素block_size2;% block包含的cell數(shù)num_bins9;% 方向直方圖分箱數(shù)[rows,cols]size(img);% 1. 計算梯度[Gx,Gy]imgradientxy(img,sobel);grad_magsqrt(Gx.^2Gy.^2);grad_diratan2(Gy,Gx)*180/pi;% 轉(zhuǎn)換為角度% 2. 構(gòu)建梯度直方圖num_cells_xfloor(cols/cell_size);num_cells_yfloor(rows/cell_size);hog_cellzeros(num_cells_y,num_cells_x,num_bins);fori1:num_cells_yforj1:num_cells_x% 提取當前cell區(qū)域cell_imggrad_mag((i-1)*cell_size1:i*cell_size,...(j-1)*cell_size1:j*cell_size);cell_dirgrad_dir((i-1)*cell_size1:i*cell_size,...(j-1)*cell_size1:j*cell_size);% 計算方向直方圖histzeros(1,num_bins);fork1:numel(cell_dir)anglecell_dir(k);ifangle0,angleangle180;endbinround(angle/(180/num_bins))1;hist(bin)hist(bin)cell_mag(k);endhog_cell(i,j,:)hist/sum(hist);% 歸一化endend% 3. Block歸一化hog_feat[];fori1:block_size:num_cells_y-block_size1forj1:block_size:num_cells_x-block_size1blockhog_cell(i:iblock_size-1,j:jblock_size-1,:);blockblock(:);% 展平blockblock/norm(blockeps);% L2歸一化hog_feat[hog_feat;block];endendend2. 關(guān)鍵優(yōu)化點Gamma校正預(yù)處理階段進行對比度歸一化imgsqrt(img);% Gamma0.5的近似實現(xiàn)方向插值采用雙線性插值提升方向估計精度重疊Block設(shè)置50%重疊區(qū)域提升特征連續(xù)性二、SVM分類器訓練1. 數(shù)據(jù)準備% 加載INRIA數(shù)據(jù)集pos_dirINRIAPerson/pos/;neg_dirINRIAPerson/neg/;% 提取正樣本特征pos_feat[];fori1:numel(dir(pos_dir))imgimread(fullfile(pos_dir,dir(pos_dir){i}));imgimresize(img,[64,128]);pos_feat[pos_feat;compute_hog(img)];endlabels_posones(size(pos_feat,1),1);% 提取負樣本特征neg_feat[];fori1:numel(dir(neg_dir))imgimread(fullfile(neg_dir,dir(neg_dir){i}));imgimresize(img,[64,128]);neg_feat[neg_feat;compute_hog(img)];endlabels_neg-ones(size(neg_feat,1),1);% 合并數(shù)據(jù)集features[pos_feat;neg_feat];labels[labels_pos;labels_neg];2. 訓練流程% 劃分訓練集和測試集cvcvpartition(size(features,1),HoldOut,0.3);train_featfeatures(cv.training,:);train_labelslabels(cv.training,:);test_featfeatures(cv.test,:);test_labelslabels(cv.test,:);% 訓練SVM模型modelfitcsvm(train_feat,train_labels,...KernelFunction,linear,...BoxConstraint,1,...Standardize,true);% 性能評估predictedpredict(model,test_feat);accuracysum(predictedtest_labels)/numel(test_labels);disp([測試集準確率: ,num2str(accuracy*100,%.2f),%]);三、行人檢測實現(xiàn)1. 滑動窗口檢測functiondetectionssliding_window_detection(img,model,step8)[rows,cols]size(img);detections[];fory1:step:rows-64forx1:step:cols-128windowimcrop(img,[x,y,128,64]);hog_featcompute_hog(window);ifpredict(model,hog_feat)1detections[detections;x,y,128,64];endendendend2. 非極大值抑制NMSfunctionkeepnms(boxes,overlap)ifisempty(boxes),return;end% 轉(zhuǎn)換為x1,y1,x2,y2格式x1boxes(:,1);y1boxes(:,2);x2x1boxes(:,3)-1;y2y1boxes(:,4)-1;% 計算面積area(x2-x11).*(y2-y11);% 按置信度排序[~,idx]sort(predictions,descend);x1x1(idx);y1y1(idx);x2x2(idx);y2y2(idx);areaarea(idx);pick[];while~isempty(idx)lastlength(idx);iidx(last);pick[pick;i];% 計算重疊區(qū)域xx1max(x1(i),x1(idx(1:last-1)));yy1max(y1(i),y1(idx(1:last-1)));xx2min(x2(i),x2(idx(1:last-1)));yy2min(y2(i),y2(idx(1:last-1)));wmax(0,xx2-xx11);hmax(0,yy2-yy11);overlap_ratio(w.*h)./(area(idx(1:last-1))area(i)-w.*h);% 刪除重疊過高的框idx(idx(1:last-1)overlap_ratiooverlap)[];endend四、完整檢測流程% 加載測試圖像imgimread(test.jpg);img_grayrgb2gray(img);% 檢測detectionssliding_window_detection(img_gray);% 非極大值抑制keepnms(detections,0.3);final_detectionsdetections(keep,:);% 可視化結(jié)果figure;imshow(img);hold on;fori1:size(final_detections,1)rectangle(Position,final_detections(i,:),...EdgeColor,r,LineWidth,2);endhold off;參考代碼 HOG特征提取在進行SVM行人檢測www.youwenfan.com/contentcsn/81104.html五、擴展應(yīng)用實時檢測結(jié)合YOLOv3實現(xiàn)混合檢測框架多目標跟蹤集成卡爾曼濾波器進行軌跡預(yù)測異常檢測分析時序行人行為特征