0

I am trying to run a live pedestrian tracking code with HOG and opencv on a raspicam. Whenever I run it, it takes about 20 seconds before the image frame appears and it only shows the first image it sees rather than live feed. Any help is great!!

import cv2 
import imutils 
import time
from picamera.array import PiRGBArray 
from picamera import PiCamera


###CAMERA SETUP##
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
raw_capture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)


# Initializing the HOG person 
# detector 

hog = cv2.HOGDescriptor() 
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) 


###VIDEO CAPTURE LOOP### 
for frame in camera.capture_continuous(raw_capture, format="bgr", use_video_port=True):

    #cv2 video init
    image = frame.array

    # Resizing the Image 
    image = imutils.resize(image, width=min(400, image.shape[1])) 

       
    # Detecting all the regions in the  
    # Image that has a pedestrians inside it 
    (regions, _) = hog.detectMultiScale(image,  
                                        winStride=(4, 4), 
                                        padding=(4, 4), 
                                        scale=1.05) 
   
    # Drawing the regions in the Image 
    for (x, y, w, h) in regions: 
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2) 


    #set line x/y var to center
    x_medium=320
    y_medium=240


    '''cv2.imshow('mask', red_mask)'''
    #show regular frame
    cv2.imshow("Frame", image)
    key = cv2.waitKey(1) & 0xFF
    raw_capture.truncate(0)

    #quit 
    if key == ord("q"):
        cv2.waitKey(1)
        px.stop()
        py.stop
        break
cv2.destroyAllWindows()
   
   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.