-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
amine789
authored
Jan 3, 2019
0 parents
commit e24ed5e
Showing
79 changed files
with
51,211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Dec 4 00:39:04 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
import cv2 | ||
import numpy as np | ||
|
||
img = cv2.imread("Sunflowers.jpg",0) | ||
params = cv2.SimpleBlobDetector_Params() | ||
params.filterByArea = True | ||
params.filterByCircularity = True | ||
params.minCircularity = 0.00001 | ||
params.minConvexity = 0.95 | ||
params.filterByConvexity = True | ||
detector = cv2.SimpleBlobDetector_create(params) | ||
|
||
keypoints = detector.detect(img) | ||
|
||
blank=np.zeros((1,1)) | ||
|
||
|
||
blob = cv2.drawKeypoints(img,keypoints,blank,(0,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT) | ||
|
||
|
||
cv2.imshow("blob", blob) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Dec 4 01:58:42 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
import cv2 | ||
import numpy as np | ||
|
||
image = cv2.imread("blobs.jpg") | ||
|
||
cv2.imshow(",",image) | ||
cv2.waitKey(0) | ||
|
||
params = cv2.SimpleBlobDetector_Params() | ||
#params.filterByArea = True | ||
#params.filterByCircularity = True | ||
#params.minCircularity = 0.00001 | ||
#params.minConvexity = 0.95 | ||
#params.filterByConvexity = True | ||
detector = cv2.SimpleBlobDetector_create(params) | ||
keypoints = detector.detect(image) | ||
|
||
blank=np.zeros((1,1)) | ||
blob = cv2.drawKeypoints(image,keypoints,blank,(0,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT) | ||
number_of_blobs = len(keypoints) | ||
text= "total number of blobs "+str(len(keypoints)) | ||
cv2.putText(blob,text,(20,550),cv2.FONT_HERSHEY_SIMPLEX,1,(100,0,255),2) | ||
|
||
cv2.imshow("blobs using default paramers",blob) | ||
cv2.waitKey(0) | ||
|
||
|
||
params = cv2.SimpleBlobDetector_Params() | ||
params.filterByArea = True | ||
params.filterByCircularity = True | ||
params.minCircularity = 0.9 | ||
|
||
params.filterByConvexity = True | ||
params.minConvexity = 0.2 | ||
params.filterByInertia=True | ||
params.minInertiaRatio=0.01 | ||
detector = cv2.SimpleBlobDetector_create(params) | ||
keypoints = detector.detect(image) | ||
|
||
blank=np.zeros((1,1)) | ||
blob = cv2.drawKeypoints(image,keypoints,blank,(0,255,255),cv2.DRAW_MATCHES_FLAGS_DEFAULT) | ||
number_of_blobs = len(keypoints) | ||
text= "total number of blobs "+str(len(keypoints)) | ||
cv2.putText(blob,text,(20,550),cv2.FONT_HERSHEY_SIMPLEX,1,(100,0,255),2) | ||
|
||
cv2.imshow("blobs using default paramers",blob) | ||
cv2.waitKey(0) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Fri Nov 30 03:25:48 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
import numpy as np | ||
import cv2 | ||
|
||
image = cv2.imread("hand.jpg") | ||
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) | ||
cv2.imshow("original image",image) | ||
cv2.waitKey(0) | ||
|
||
#threshhold image | ||
|
||
ret, thresh = cv2.threshold(gray,176,255,0) | ||
cv2.imshow("original image",thresh) | ||
cv2.waitKey(0) | ||
|
||
#find contours | ||
_,contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE) | ||
|
||
|
||
#sort contours by area and remove the largest frame contour | ||
n = len(contours)-1 | ||
|
||
contours = sorted(contours, key=cv2.contourArea, reverse=False)[:n] | ||
|
||
for c in contours: | ||
hull = cv2.convexHull(c) | ||
cv2.drawContours(image,[hull],0,(0,255,0),2) | ||
cv2.imshow("convex hull ", image) | ||
|
||
cv2.waitKey(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Nov 27 02:50:11 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
import cv2 | ||
import numpy as np | ||
|
||
def x_cord_contour(contours): | ||
# returns the x cordinate for the contour centroid | ||
if cv2.contourArea(contours)>10: | ||
M = cv2.moments(contours) | ||
return (int(M["m10"]/M["m00"])) | ||
|
||
def label_contour_center(image,c): | ||
# places a red circle on the centers of contours | ||
M = cv2.moments(c) | ||
cx = (int(M["m10"]/M["m00"])) | ||
cy = (int(M["m01"]/M["m00"])) | ||
|
||
# draw circles in | ||
cv2.circle(image,(cx,cy),10,(0,0,255),-1) | ||
return image | ||
|
||
image = cv2.imread("shapes.jpg") | ||
original_image = image.copy() | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
|
||
#canny edge | ||
edged = cv2.Canny(gray, 50,200) | ||
cv2.imshow("canny edge",edged) | ||
cv2.waitKey(0) | ||
_,contours, hierarchy = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) | ||
|
||
for (i,c) in enumerate(contours): | ||
orig = label_contour_center(image,c) | ||
|
||
cv2.imshow("4 contour = centers", image) | ||
cv2.waitKey(0) | ||
|
||
contours_left_to_right = sorted(contours, key=x_cord_contour,reverse=False) | ||
|
||
for (i,c) in enumerate(contours_left_to_right): | ||
cv2.drawContours(original_image,[c], -1,(0,0,255),-3) | ||
M = cv2.moments(c) | ||
cx = (int(M["m10"]/M["m00"])) | ||
cy = (int(M["m01"]/M["m00"])) | ||
cv2.putText(original_image,str(i+1),(cx,cy),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),2) | ||
cv2.imshow("left_to_rate", original_image) | ||
cv2.waitKey(0) | ||
|
||
(x,y,w,h) = cv2.boundingRect(c) | ||
|
||
cropped_countour = original_image[y:y+h, x:x+w] | ||
image_name = "output_number "+str(i+1)+".jpg" | ||
cv2.imwrite(image_name,cropped_countour) | ||
cv2.destroyAllWindows() | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Dec 13 00:23:24 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
#FACE DETECTION | ||
|
||
import numpy as np | ||
import cv2 | ||
|
||
face_classifier = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") | ||
|
||
image = cv2.imread("Trump.jpg") | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
|
||
faces = face_classifier.detectMultiScale(gray,1.3,5) | ||
|
||
if faces is (): | ||
print("no face found") | ||
|
||
for (x,y,w,h) in faces: | ||
cv2.rectangle(gray,(x,y),(x+w,y+h),(127,0,255),2) | ||
cv2.imshow(",", gray) | ||
cv2.waitKey(0) | ||
|
||
|
||
|
||
#FACE AND EYE DETECTION | ||
|
||
eye_classifier = cv2.CascadeClassifier("haarcascade_eye.xml") | ||
|
||
for (x,y,w,h) in faces: | ||
cv2.rectangle(image,(x,y),(x+w,y+h),(127,0,255),2) | ||
cv2.imshow(",", image) | ||
cv2.waitKey(0) | ||
roi_gray = gray[y:y+h, x:x+w] | ||
roi_color = image[y:y+h, x:x+w] | ||
eyes = eye_classifier.detectMultiScale(roi_gray) | ||
for (ex,ey,ew,eh) in eyes: | ||
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,255,0),2) | ||
cv2.imshow("img", image) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Dec 13 01:27:24 2018 | ||
@author: amine bahlouli | ||
""" | ||
import cv2 | ||
|
||
|
||
eye_classifier = cv2.CascadeClassifier("haarcascade_eye.xml") | ||
face_classifier = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") | ||
|
||
def face_detector(image, size=0.5): | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
faces = face_classifier.detectMultiScale(gray,1.3,5) | ||
if faces is (): | ||
return image | ||
for (x,y,w,h) in faces: | ||
x = x-50 | ||
w=w+50 | ||
y =y-50 | ||
h=h+50 | ||
cv2.rectangle(image,(x,y),(x+w,y+h),(127,0,255),2) | ||
roi_gray = gray[y:y+h, x:x+w] | ||
roi_color = image[y:y+h, x:x+w] | ||
eyes = eye_classifier.detectMultiScale(roi_gray) | ||
for (ex,ey,ew,eh) in eyes: | ||
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,255,0),2) | ||
roi_color = cv2.flip(roi_color,1) | ||
return roi_color | ||
|
||
cap = cv2.VideoCapture(0) | ||
|
||
while True: | ||
ret, frame= cap.read() | ||
cv2.imshow("our face extractor ", face_detector(frame)) | ||
if cv2.waitKey(1)==13: | ||
break | ||
|
||
cap.release() | ||
cv2.destroyAllWindows() | ||
|
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sat Dec 8 00:46:35 2018 | ||
@author: amine bahlouli | ||
""" | ||
|
||
import cv2 | ||
|
||
import numpy as np | ||
|
||
image = cv2.imread("WaldoBeach.jpg",0) | ||
cv2.imshow("where is waldo3",image) | ||
cv2.waitKey(0) | ||
|
||
|
||
|
||
template = cv2.imread("waldo.jpg",0) | ||
cv2.imshow(",",template) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
||
result = cv2.matchTemplate(image,template,cv2.TM_CCOEFF) | ||
min_val,max_val,min_loc,max_loc = cv2.minMaxLoc(result) | ||
|
||
#creating the box | ||
|
||
top_left = max_loc | ||
bottom_right = (top_left[0] + 50, top_left[1]+50) | ||
cv2.rectangle(image,top_left,bottom_right,(0,0,255),5) | ||
|
||
cv2.imshow("where is waldo", image) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() |
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.