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)      

creating a real time color detector

#Color Detection

import numpy as np

import cv2

# Capturing video through webcam

webcam = cv2.VideoCapture(0)

while(1):

_, imageFrame = webcam.read()

# Convert the imageFrame in

# BGR(RGB color space) to

# HSV(hue-saturation-value)

# color space

hsvFrame = cv2.cvtColor(imageFrame, cv2.COLOR_BGR2HSV)

red_lower = np.array([136, 87, 111], np.uint8)

red_upper = np.array([180, 255, 255], np.uint8)

red_mask = cv2.inRange(hsvFrame, red_lower, red_upper)

green_lower = np.array([25, 52, 72], np.uint8)

green_upper = np.array([102, 255, 255], np.uint8)

green_mask = cv2.inRange(hsvFrame, green_lower, green_upper)

blue_lower = np.array([94, 80, 2], np.uint8)

blue_upper = np.array([120, 255, 255], np.uint8)

blue_mask = cv2.inRange(hsvFrame, blue_lower, blue_upper)

kernal = np.ones((5, 5), "uint8")

red_mask = cv2.dilate(red_mask, kernal)

res_red = cv2.bitwise_and(imageFrame, imageFrame,

mask = red_mask)

green_mask = cv2.dilate(green_mask, kernal)

res_green = cv2.bitwise_and(imageFrame, imageFrame,

mask = green_mask)

blue_mask = cv2.dilate(blue_mask, kernal)

res_blue = cv2.bitwise_and(imageFrame, imageFrame,

mask = blue_mask)

contours, hierarchy = cv2.findContours(red_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(0, 0, 255), 2)

cv2.putText(imageFrame, "Red Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX, 1.0,

(0, 0, 255))

contours, hierarchy = cv2.findContours(green_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(0, 255, 0), 2)

cv2.putText(imageFrame, "Green Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX,

1.0, (0, 255, 0))

contours, hierarchy = cv2.findContours(blue_mask,

cv2.RETR_TREE,

cv2.CHAIN_APPROX_SIMPLE)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if(area > 300):

x, y, w, h = cv2.boundingRect(contour)

imageFrame = cv2.rectangle(imageFrame, (x, y),

(x + w, y + h),

(255, 0, 0), 2)

cv2.putText(imageFrame, "Blue Colour", (x, y),

cv2.FONT_HERSHEY_SIMPLEX,

1.0, (255, 0, 0))

# Program Termination

cv2.imshow("Multiple Color Detection in Real-TIme", imageFrame)

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

cap.release()

cv2.destroyAllWindows()

break


Screen recorder

# importing packages

import pyautogui

import cv2

import numpy as np

#resolution

resolution = (1920, 1080)

codec = cv2.VideoWriter_fourcc(*"XVID")

#Output file

filename = "Recordings.avi"

#frames rate

fps = 60.0

# Create a VideoWriter object

out = cv2.VideoWriter(filename, codec, fps, resolution)

# Creating an Empty window

cv2.namedWindow("Live", cv2.WINDOW_NORMAL)

# Resize this window

cv2.resizeWindow("Live", 480, 270)

while True:

# Take screenshot using PyAutoGUI

img = pyautogui.screenshot()

# Convert the screenshot to a numpy array

frame = np.array(img)

# Convert it from BGR(Blue, Green, Red) to

# RGB(Red, Green, Blue)

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

# Write output file

out.write(frame)

#Display the recording screen

cv2.imshow('Live', frame)

# Stop recording when we press 'q'

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

break

# Release the Video writer

out.release()

# Destroy windows

cv2.destroyAllWindows()