vishnu deepak

vishnu deepak

  • NA
  • 2
  • 1.8k

opencv python code

Jun 14 2017 6:35 AM
plz do help me to track the person which do not reduces the movement of frames
 
from imutils.video import FileVideoStream
from imutils.video import FPS
import numpy as np
import argparse
import imutils
import time
import cv2

def inside(r, q):
rx, ry, rw, rh = r
qx, qy, qw, qh = q
return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

def draw_detections(img, rects, thickness = 1):
for x, y, w, h in rects:
# the HOG detector returns slightly larger rectangles than the real objects.
# so we slightly shrink the rectangles to get a nicer output.
pad_w, pad_h = int(0.15*w), int(0.05*h)
print pad_w
print pad_h
if(pad_w>=9 and pad_h>=9 and pad_w<=18 and pad_h<=15):
cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (255, 0, 0), thickness)
ap = argparse.ArgumentParser()

args = vars(ap.parse_args())
print("[INFO] starting video file thread...")
fvs = FileVideoStream("D:/Videos/Chepauk Match Day/MVI_9642.MOV").start()
time.sleep(1.0)

fps = FPS().start()
hog = cv2.HOGDescriptor()
hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
while fvs.more():
frame = fvs.read()
found,w=hog.detectMultiScale(frame, winStride=(10,10), padding=(40,40), scale=1.05)
draw_detections(frame,found)
#frame = imutils.resize(frame, width=450)
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = np.dstack([frame, frame, frame])

cv2.putText(frame, "Queue Size: {}".format(fvs.Q.qsize()),
(10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)

cv2.imshow("Frame", frame)
cv2.waitKey(1)
fps.update()

fps.stop()
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))

cv2.destroyAllWindows()
fvs.stop()


 

Answers (1)