Skip to content

Instantly share code, notes, and snippets.

View karthick965938's full-sized avatar
🎯
Focusing

Karthick Nagarajan karthick965938

🎯
Focusing
View GitHub Profile
@karthick965938
karthick965938 / demo_live_face_detection.py
Created November 20, 2019 06:10
Open cv python face detection
import cv2
# Load the cascade
#https://github.com/karthick965938/Face-detection/blob/master/haarcascades/haarcascade_frontalface_default.xml
face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_default.xml')
# To capture video from webcam.
cap = cv2.VideoCapture(0)
# To use a video file as input
while True:
# Read the frame
_, img = cap.read()
@karthick965938
karthick965938 / file_rename.py
Last active May 9, 2020 13:10
python file name inside the folder
import os
os.getcwd()
collection = "images/cat"
for i, filename in enumerate(os.listdir(collection)):
print(filename)
os.rename(collection + "/" + filename, collection + "/cat" + str(i) + ".jpg")
@karthick965938
karthick965938 / video_to_image.py
Last active May 23, 2021 20:01
Create images into the video
from detecto.utils import split_video
#split_video('video file path', 'image save path', frame size)
split_video('images/cat.mp4', 'images/cat/', step_size=10)
@karthick965938
karthick965938 / remove_png_image.py
Last active September 12, 2021 16:23
Remove PNG images into the directory
import glob
import pathlib
for file in glob.glob('frames/*.png'):
path = pathlib.Path(file)
path.unlink()
@karthick965938
karthick965938 / convert_image_resolution.py
Last active May 9, 2020 13:08
Python script for convert image resolution
from PIL import Image
import os
import argparse
def rescale_images(directory, size):
for img in os.listdir(directory):
im = Image.open(directory+img)
im_resized = im.resize(size, Image.ANTIALIAS)
im_resized.save(directory+img)
@karthick965938
karthick965938 / image_process.py
Last active May 10, 2020 09:59
We can using 'Download All Images' chrome extentions to get images from the google. Here i have shared some images process code
#Get images from the google
#Remove PNG images
import glob
import pathlib
for file in glob.glob('frames/*.png'):
path = pathlib.Path(file)
path.unlink()
#Rename your images files form the image directory
import os
os.getcwd()
@karthick965938
karthick965938 / cloab.py
Created May 10, 2020 19:25
Install detecto on google cloab :)
import os
from google.colab import drive
drive.mount('/content/drive')
os.chdir('/content/drive/My Drive/object_detection')
!pip install detecto
@karthick965938
karthick965938 / prepare_model.py
Last active May 11, 2020 11:26
Python code for prepare object detection model
from detecto import core, utils, visualize
#mention you dataset path
dataset = core.Dataset('images/')
#mention you object label here
model = core.Model(['cat'])
model.fit(dataset)
@karthick965938
karthick965938 / test_model.py
Last active May 11, 2020 12:39
Test your model on google colab for detecto
# Specify the path to your image
from detecto import core, utils, visualize
image = utils.read_image('animals/cat48.jpg')
predictions = model.predict(image)
# predictions format: (labels, boxes, scores)
labels, boxes, scores = predictions
# ['alien', 'bat', 'bat']
print(labels)
print(boxes)
# tensor([0.9952, 0.9837, 0.5153])
@karthick965938
karthick965938 / save_model.py
Last active May 11, 2020 12:35
Save your model file on google colab
model.save('model_weights.pth')
#you can save your model using above file
model = core.Model.load('model_weights.pth', ['alien', 'bat', 'witch'])