<jupyter_start><jupyter_text>Pedestrain Detection on Image<jupyter_code>import cv2
import sys
import numpy as np
# import libraries



#Loading the image to be tested
test_image = cv2.imread('dataset/pedestrain.jpg')

#Converting to grayscale
test_image_gray = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)

# Displaying the grayscale image
#cv2.imshow(test_image_gray, cmap='gray')
#Since we know that OpenCV loads an image in BGR format, so we need to convert it into RBG format to be able to display its true colors. Let us write a small function for that.

body_classifier=cv2.CascadeClassifier('dataset/haarcascade_fullbody.xml')
# importing the body classifier

body=body_classifier.detectMultiScale(test_image_gray,1.05, 4)
# extracting the x-coordinate, y-coordinate, width (w) and height(h) & gray scale image.

# Let us print the no. of faces found
# print('Pedestrain found: ', len(body))


for (x,y,w,h) in body:
     cv2.rectangle(test_image, (x, y), (x+w, y+h), (0, 255, 255), 4)
     # looping through the image and drawing frames around the image.
        


half = cv2.resize(test_image, (0,0),fx=0.4,fy=0.3,interpolation=cv2.INTER_CUBIC) 
# resizing the image


cv2.imshow("Pedestrains",half)

cv2.waitKey(0)
cv2.destroyAllWindows()<jupyter_output><empty_output><jupyter_text>Pedestrain Detection on Video<jupyter_code># Importing required libraries
import time
import numpy as np
import cv2


# importing the body classifier
body_classifier = cv2.CascadeClassifier('dataset/haarcascade_fullbody.xml')


# Initiate video capture for video file
cap = cv2.VideoCapture('dataset/ped_data_1.mp4')


# Loop once video is successfully loaded
while (cap.isOpened()):
    time.sleep(0.05)
    
    # Read the frame
    ret, frame = cap.read()
    
    # print(frame)
    if ret== False: # if frame doesn't exist i.e. ret = False 
        cap.release()
        cv2.destroyAllWindows()
        break
    else:
        
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        # converting the images to grayscale
        
        # Pass frame to our body classifier
        bodies = body_classifier.detectMultiScale(gray, 1.05, 4)
    
        # Extract bounding boxes for any bodies identified
        for (x,y,w,h) in bodies:
            cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 255), 2)
            cv2.imshow('Pedestrians', frame)
            cv2.waitKey(33)
            # 33 used because the loaded video framerate is 29.97fps. 1sec/29.97=0.0333=33msec.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10199203187250996, 'fraction_numerical': 0.03147410358565737, 'mean_word_length': 3.65, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '588131', 'license': 'MIT', 'n_tokens_mistral': 915, 'n_tokens_neox': 849, 'n_words': 239, 'path': 'PedestrainDetection-HaarCascades/Pedestrian Detection.ipynb', 'repo_name': 'noviicee/Image-Processing-OpenCV', 'size': '2510'}