opencv初探 行人檢測

2021-10-07 11:22:52 字數 1228 閱讀 6470

話不多說,直接上**,這裡採用opencv自帶的hogdescriptor()分裝好的類進行檢測,效果也還行。(這裡新增了tk檔案選擇,可以嘗試檢測自己蒐集的行人)

import cv2

import tkinter as tk

from tkinter import filedialog

defis_inside

(p,i)

: px,py,pw,ph = p

ix,iy,iw,ih = i

return px > ix and py > iy and px + pw < ix + iw and py + ph < iy +ih

defdraw_person

(image, person)

: x,y,w,h = person

cv2.rectangle(img,

(x,y)

,(x+w,y+h),(

0,255,

255,2)

)win = tk.tk(

)win.withdraw(

)filepath = filedialog.askdirectory(

)imagepath = filedialog.askopenfilename(

)img = cv2.imread(imagepath)

hog = cv2.hogdescriptor(

)#引數使用預設,獲取hog描述子

hog.setsvmdetector(cv2.hogdescriptor_getdefaultpeopledetector())

#構建分類器

found, w = hog.detectmultiscale(img)

#多尺度檢測

#定位found_filtered =

for ri, r in

enumerate

(found)

:for qi, q in

enumerate

(found)

:if ri != qi and is_inside(r,q)

:break

else

:for person in found_filtered:

draw_person(img,person)

#顯示效果

cv2.imshow(

"people detection"

,img)

OpenCV實踐之路 行人檢測

微博 行人檢測是視覺領域很熱也很有用的乙個主題,特別是在無人駕駛中,行人檢測的重要性不言而喻。在之前進行了人臉檢測之後,行人檢測就顯得簡單多了。過程大致與人臉檢測一樣,都是先載入分類器,然後進行多尺度檢測。就偷懶不再贅述。感興趣的可以看人臉檢測的這一篇文章 opencv實踐之路 人臉檢測 c pyt...

OpenCV 基於HOG特徵的行人檢測

opencv中提供了hog的行人檢測 pedestrain detection 類。cv hogdescriptor類的建構函式的各引數的定義 cpp view plain copy cv wrap hogdescriptor winsize 64,128 detect window blocksi...

c 結合opencv進行人臉檢測

include cv.h include highgui.h include include include include include 與一樣是定義邊界值的,定義的是浮點數的邊界值 include include include 在呼叫字元函式時,在原始檔中包含的標頭檔案 using name...