Skip to content

Instantly share code, notes, and snippets.

View shoaibmehedi7's full-sized avatar
:octocat:
Working from home

MD Shoaib Mehedi shoaibmehedi7

:octocat:
Working from home
View GitHub Profile
#socialDistancing.py
import cv2
import datetime
import imutils
import numpy as np
from centroidtracker import CentroidTracker
from itertools import combinations
import math
def main():
cap = cv2.VideoCapture('/home/python/OpenCV/soacialDistanceDetect/video .mp4')
fps_start_time = datetime.datetime.now()
fps = 0
total_frames = 0
while True:
ret, frame = cap.read()
frame = imutils.resize(frame, width=600)
import cv2
import numpy as np
min_contour_width = 40
min_contour_height = 40
offset = 10
line_height = 550
matches = []
cars = 0
while ret:
d = cv2.absdiff(frame1, frame2)
grey = cv2.cvtColor(d, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(grey, (5, 5), 0)
ret, th = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
dilated = cv2.dilate(th, np.ones((3, 3)))
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))
import cv2
#img = cv2.imread('/home/pyarena/python/OpenCV/objectDetection/image1.jpg')
cap = cv2.VideoCapture(-1)
cap.set(3, 640)#
cap.set(4, 480)#
classNames = []
while True: #
success, img = cap.read() #
classIds, confs, bbox = net.detect(img, confThreshold=0.5)
print(classIds, bbox)
if len(classIds) != 0: #
for classId, confidence, box in zip(classIds.flatten(), confs.flatten(), bbox):
cv2.rectangle(img, box, color=(0, 255, 0), thickness=2)
cv2.putText(img, classNames[classId-1].upper(), (box[0]+10, box[1]+30), cv2.FONT_HERSHEY_COMPLEX, 1, (0,255,0), 2)
import cv2
import mediapipe as mp
import time
class FaceDetector():
def __init__(self, minDetectionCon=0.5):
import cv2
import mediapipe as mp
import time
cap = cv2.VideoCapture('/home/python/OpenCV/faceDetect/faceD1.mp4')
#cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
results = faceDetection.process(imgRGB)
if results.detections:
for id, detection in enumerate(results.detections):
mpDrawing.draw_detection(img, detection)
#print(id, detection)
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">