Skip to content

Commit 523859e

Browse files
committed
commit
1 parent b9a10d6 commit 523859e

7 files changed

+140
-0
lines changed

Readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* template_matching_opencv.py
3131
* hough_line_transform_opencv.py
3232
* probabilistic_hough_line_transform.py
33+
* lande_detection_opencv.py
34+
* circle_detection_using_hough_transform.py
35+
* face_detection_opencv.py
36+
3337

3438
## Helpful Documentations⭐:
3539
* OpenCV : https://docs.opencv.org/master/
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
import cv2 as cv
3+
4+
# img = cv.imread('test_images/shapes.jpg')
5+
img = cv.imread('test_images/smarites.jpg')
6+
output = img.copy()
7+
8+
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
9+
gray = cv.medianBlur(gray, 5)
10+
# circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
11+
circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, 60, param1=50, param2=30, minRadius=0, maxRadius=70)
12+
13+
detected_circles = np.uint16(np.around(circles))
14+
for (x, y, r) in detected_circles[0, :]:
15+
cv.circle(output, (x, y), r, (0,255,0), 3)
16+
cv.circle(output, (x, y), 2, (0, 255, 255), 3)
17+
18+
cv.imshow('output', output)
19+
cv.waitKey(0)
20+
cv.destroyAllWindows()

face_detection_opencv.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import cv2
2+
# object detection based on Haar cascade classifier
3+
4+
#image face detection
5+
# face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
6+
# img = cv2.imread('test_images/test.jpg')
7+
#
8+
#
9+
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
10+
# faces = face_cascade.detectMultiScale(gray, 1.1, 4)
11+
#
12+
# for (x, y, w, h) in faces:
13+
# cv2.rectangle(img, (x, y), (x+w, y+h), (255,0,0),3)
14+
#
15+
#
16+
# cv2.imshow('img', img)
17+
# cv2.waitKey(0)
18+
#
19+
# cv2.destroyAllWindows()
20+
21+
22+
23+
# video face detection
24+
25+
## You have to download haarcascade_frontalface_default from internet
26+
27+
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
28+
# img = cv2.imread('test_images/test.jpg')
29+
cap = cv2.VideoCapture(0)
30+
31+
while cap.isOpened():
32+
_, img = cap.read()
33+
34+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
35+
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
36+
37+
for (x, y, w, h) in faces:
38+
cv2.rectangle(img, (x, y), (x+w, y+h), (255,0,0),3)
39+
40+
41+
cv2.imshow('img', img)
42+
if cv2.waitKey(1) & 0xff == ord('q'):
43+
break
44+
45+
cv2.destroyAllWindows()
46+
47+
cap.release()

lane_detection_opencv.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import matplotlib.pyplot as plt
2+
import cv2
3+
import numpy as np
4+
5+
def region_of_interest(img, vertices):
6+
mask = np.zeros_like(img)
7+
# channel_count = img.shape[2]
8+
match_mask_color = 255 #, ) * channel_count
9+
cv2.fillPoly(mask, vertices, match_mask_color)
10+
masked_image = cv2.bitwise_and(img, mask)
11+
return masked_image
12+
13+
def draw_the_lines(img, lines):
14+
img = np.copy(img)
15+
blank_image = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
16+
17+
for line in lines:
18+
for x1, y1, x2, y2 in line:
19+
cv2.line(blank_image, (x1, y1), (x2, y2), (0,255,0), thickness=3)
20+
21+
22+
img = cv2.addWeighted(img, 0.8, blank_image, 1, 0.0)
23+
return img
24+
25+
# image = cv2.imread('road.jpg')
26+
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
27+
28+
def process(image):
29+
30+
# print(image.shape)
31+
height = image.shape[0]
32+
width = image.shape[1]
33+
34+
region_of_interest_vertices = [
35+
36+
(0, height),
37+
(width/2, height/2),
38+
(width,height)
39+
40+
# (120, height),
41+
# (width / 2, height / 2),
42+
# (width, 180)
43+
]
44+
45+
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
46+
canny_image = cv2.Canny(gray_image, 100, 120)
47+
48+
cropped_image = region_of_interest(canny_image,
49+
np.array([region_of_interest_vertices], np.int32))
50+
lines = cv2.HoughLinesP(cropped_image, rho=2, theta=np.pi/60, threshold=50, lines=np.array([]), minLineLength=40, maxLineGap=100)
51+
52+
image_with_lines = draw_the_lines(image, lines)
53+
if lines is None:
54+
image_with_lines = image
55+
56+
return image_with_lines
57+
58+
59+
cap = cv2.VideoCapture('test_images/test_video.mp4')
60+
61+
while(cap.isOpened()):
62+
ret, frame = cap.read()
63+
frame = process(frame)
64+
cv2.imshow('frame',frame)
65+
if cv2.waitKeyEx(1) & 0xff == ord('q'):
66+
break
67+
68+
cap.release()
69+
cv2.destroyAllWindows()

test_images/road.jpg

891 KB
Loading

test_images/test.jpg

5.56 KB
Loading

test_images/test_video.mp4

31.9 MB
Binary file not shown.

0 commit comments

Comments
 (0)