Pedestrian Detector for images

import cv2

import imutils

# detector

hog = cv2.HOGDescriptor()

hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

# Reading the Image

image = cv2.imread('img_path')

# 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)

# Showing the output Image

cv2.imshow("Image", image)

cv2.waitKey(0)

cv2.destroyAllWindows()


Multiple color live camera

import cv2

import numpy as np

# capturing first camera 

cap = cv2.VideoCapture(0)

while True:

ret, frame = cap.read()

# Capturing grayscale

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

cv2.imshow('frame', frame)

cv2.imshow('gray', gray)

# Program will terminate when 'q' key is pressed

if cv2.waitKey(1) & 0xFF == ord('q'):

break

# Releasing resources

cap.release()

cv2.destroyAllWindows()


weight converter

from tkinter import *

window = Tk()

def from_kg():

gram = float(e2_value.get())*1000

pound = float(e2_value.get())*2.20462

ounce = float(e2_value.get())*35.274

t1.delete("1.0", END)

t1.insert(END,gram)

t2.delete("1.0", END)

t2.insert(END,pound)

t3.delete("1.0", END)

t3.insert(END,ounce)

e1 = Label(window, text = "Enter the weight in Kg")

e2_value = StringVar()

e2 = Entry(window, textvariable = e2_value)

e3 = Label(window, text = 'Gram')

e4 = Label(window, text = 'Pounds')

e5 = Label(window, text = 'Ounce')

t1 = Text(window, height = 1, width = 20)

t2 = Text(window, height = 1, width = 20)

t3 = Text(window, height = 1, width = 20)

b1 = Button(window, text = "Convert", command = from_kg)

e1.grid(row = 0, column = 0)

e2.grid(row = 0, column = 1)

e3.grid(row = 1, column = 0)

e4.grid(row = 1, column = 1)

e5.grid(row = 1, column = 2)

t1.grid(row = 2, column = 0)

t2.grid(row = 2, column = 1)

t3.grid(row = 2, column = 2)

b1.grid(row = 0, column = 2)

window.mainloop()


Counting Faces

import cv2

import numpy as np

import dlib

cap = cv2.VideoCapture(0)

# Detect the coordinates

detector = dlib.get_frontal_face_detector()

while True:

# Capture frame-by-frame

ret, frame = cap.read()

frame = cv2.flip(frame, 1)

# RGB to grayscale

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = detector(gray)

i = 0

for face in faces:

x, y = face.left(), face.top()

x1, y1 = face.right(), face.bottom()

cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)

i = i+1

cv2.putText(frame, 'face num'+str(i), (x-10, y-10),

cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

print(face, i)

cv2.imshow('frame', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

cap.release()

cv2.destroyAllWindows()


Turtle moving circle

import turtle

def moving_object(move):

    move.fillcolor('Purple') 

    move.begin_fill() 

    move.circle(10)  

    move.end_fill()             

if __name__ == "__main__" :

    screen = turtle.Screen() 

    screen.setup(600,600)    

    # screen background color

    screen.bgcolor('white')   

    screen.tracer(0)           

    move = turtle.Turtle() 

    move.color('Purple')

    move.speed(0) 

    move.width(2)     

    move.hideturtle()          

    move.penup()               

    move.goto(-250, 0) 

    move.pendown()             

    while True :

        move.clear()  

        moving_object(move)   

        screen.update()    

        move.forward(0.5)