Bulid-in Target Detector
Call the internal function for human detection, the actual effect is not good. Three-link migrant workers:
Hog = Cv2. Hogdescriptor () # Starts the detector object Hog.setsvmdetector (CV2. Hogdescriptor_getdefaultpeopledetector ()) # Specify detector type found, W = Hog.detectmultiscale (img) # load && monitor image
Complete program:
Import Cv2import NumPy as Npdef is_inside (O, i): Ox, Oy, ow, OH = O IX, iy, IW, ih = i return (Ox > IX) and (O Y > Iy) and ((Ox+ow) < (IX+IW)) and ((Oy+oh) < (IY+IH)) def draw_persion (image, person): X, Y, W, h = person Cv2.rectangle (Image, (x, y), (x + W, y + h), (0, 255, 255), 2) img = Cv2.imread ('./pycv-master/images/people.jpg ') Hog = CV 2.HOGDescriptor () # Start Detector Object Hog.setsvmdetector (CV2. Hogdescriptor_getdefaultpeopledetector ()) # Specify detector type found, W = Hog.detectmultiscale (img) # Load && monitor Image found_filtered = []for ri, R in enumerate (found): For QI, q in Enumerate (found): if ri! = Qi and Is_inside (R, Q): # If the outside of R does not exist box, record print (' R ', r) print (' Q ', q) Break else: # The else exception that's on the for outside (Found_filtered.append) Ah, yes. (r) for the person in FOUND_FILTERED:DR Aw_persion (IMG, person) cv2.imshow (' People delection ', IMG) Cv2.waitkey (0) cv2.destroyallwindows ()
Other places there is nothing to talk about, but there is a writing, it is too angry, fierce:
For RI, R in enumerate (found): for QI, q in Enumerate (found): if ri! = Qi and is_inside (R, Q): print (' R ', R)
print (' q ', q) break Else: found_filtered.append (R)
Using an else to take all of the IF in for, this is a novelty, with a break, the effect is that all if in for is false when the statement in the else is run.
Actual effect part (Super Rotten test result):
"Python" Computer vision _OPENCV3 Target detector (to be continued)