This commit is contained in:
Anna Sudnitsina 2018-09-10 23:09:39 +03:00
parent 837aa83471
commit dcbc32d6dd
9 changed files with 40241 additions and 0 deletions

70
capture.py Normal file
View File

@ -0,0 +1,70 @@
import cv2
import time
import pandas
from datetime import datetime
prev_frame = None
times = []
# df = pandas.DataFrame(columns=["start", "end"])
video = cv2.VideoCapture(0)
status_new = 0
counter = 0
low_red = (176, 132, 97)
high_red = (209, 151, 114)
face_cascade = cv2.CascadeClassifier("smile.xml")
while True:
status_new, status_old = 0, status_new
check, frame = video.read()
only_cat = cv2.inRange(frame, low_red, high_red)
# cat_hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
if prev_frame is None:
prev_frame = gray
# continue
delta_frame = cv2.absdiff(prev_frame, gray)
prev_frame = gray
thresh_delta = cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
thresh_frame = cv2.dilate(thresh_delta, None, iterations=2)
(_,cnts,_) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
print(len(cnts))
for contour in cnts:
if cv2.contourArea(contour) < 1000:
continue
status_new, status_old = 1, status_new
(x, y, w, h) = cv2.boundingRect(contour)
# cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 3)
# status_list.append(status)
if status_new != status_old:
times.append(datetime.now())
cv2.imwrite('media/capture{}.png'.format(counter), frame)
counter += 1
# cv2.imshow("capt", gray)
# cv2.imshow("delta", delta_frame)
# cv2.imshow("threshold", thresh_frame)
faces = face_cascade.detectMultiScale(gray,
scaleFactor=1.1,
minNeighbors=10)
# for x, y, w, h in faces:
# img = cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 3)
# print(type(faces))
# cv2.imshow("face_detector", img)
cv2.imshow('cat', only_cat)
cv2.imshow("rectangle", frame)
key = cv2.waitKey(1)
if key==ord('q'):
break
# print(times)
#
# for t in range(0, len(times), 2):
# df = df.append({"start": times[t], "end": times[t+1]}, ignore_index=True)
#
# df.to_csv("times.csv")
video.release()
cv2.destroyAllWindows

17
face_detector.py Normal file
View File

@ -0,0 +1,17 @@
import cv2
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
img = cv2.imread("Screenshot from 2018-07-20 14-00-25.png")
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray_img,
scaleFactor=1.05,
minNeighbors=5)
for x, y, w, h in faces:
img = cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 3)
# print(type(faces))
cv2.imshow("face_detector", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

File diff suppressed because it is too large Load Diff

10
make_gif.py Normal file
View File

@ -0,0 +1,10 @@
import os
import imageio
path = "media/остап_спальня"
file_names = os.listdir(path)
file_names.sort()
images = [imageio.imread(path+"/"+fn) for fn in file_names]
imageio.mimsave('movie.gif', images, duration=0.2)

17
requirements.txt Normal file
View File

@ -0,0 +1,17 @@
bokeh==0.13.0
imageio==2.3.0
images2gif==1.0.1
Jinja2==2.10
MarkupSafe==1.0
numpy==1.14.5
opencv-python==3.4.1.15
packaging==17.1
pandas==0.23.3
Pillow==5.2.0
pkg-resources==0.0.0
pyparsing==2.2.0
python-dateutil==2.7.3
pytz==2018.5
PyYAML==3.13
six==1.11.0
tornado==5.1

20
script1.py Normal file
View File

@ -0,0 +1,20 @@
import cv2
import os
path = "media/Screenshot from 2018-07-18 11-41-15.png"
img = cv2.imread(path, 0)
print(type(img))
img_path = "/home/anya/Изображения/"
files = os.listdir(img_path)
for i in files:
img = cv2.imread(img_path + i, 0)
re = cv2.resize(img, (100, 100))
cv2.imshow("Hey", re)
cv2.waitKey(500)
cv2.destroyAllWindows()
cv2.imwrite("media/resized_" + i, re)
# print(list(files) )
# cv2.imshow("fractal", img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

48
setup.py Normal file
View File

@ -0,0 +1,48 @@
import cv2
import numpy as np
# import video
if __name__ == '__main__':
def nothing(*arg):
pass
cv2.namedWindow( "result" ) # создаем главное окно
cv2.namedWindow( "settings" ) # создаем окно настроек
cap = cv2.VideoCapture(0)
# создаем 6 бегунков для настройки начального и конечного цвета фильтра
cv2.createTrackbar('h1', 'settings', 0, 255, nothing)
cv2.createTrackbar('s1', 'settings', 0, 255, nothing)
cv2.createTrackbar('v1', 'settings', 0, 255, nothing)
cv2.createTrackbar('h2', 'settings', 255, 255, nothing)
cv2.createTrackbar('s2', 'settings', 255, 255, nothing)
cv2.createTrackbar('v2', 'settings', 255, 255, nothing)
crange = [0,0,0, 0,0,0]
while True:
flag, img = cap.read()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV )
# считываем значения бегунков
h1 = cv2.getTrackbarPos('h1', 'settings')
s1 = cv2.getTrackbarPos('s1', 'settings')
v1 = cv2.getTrackbarPos('v1', 'settings')
h2 = cv2.getTrackbarPos('h2', 'settings')
s2 = cv2.getTrackbarPos('s2', 'settings')
v2 = cv2.getTrackbarPos('v2', 'settings')
# формируем начальный и конечный цвет фильтра
h_min = np.array((h1, s1, v1), np.uint8)
h_max = np.array((h2, s2, v2), np.uint8)
# накладываем фильтр на кадр в модели HSV
thresh = cv2.inRange(hsv, h_min, h_max)
cv2.imshow('result', thresh)
ch = cv2.waitKey(5)
if ch == 27:
break
cap.release()
cv2.destroyAllWindows

6727
smile.xml Normal file

File diff suppressed because it is too large Load Diff

18
times.csv Normal file
View File

@ -0,0 +1,18 @@
,start,end
0,2018-07-20 16:25:51.415964,2018-07-20 16:25:51.449240
1,2018-07-20 16:25:51.487239,2018-07-20 16:25:51.517014
2,2018-07-20 16:25:52.719849,2018-07-20 16:25:52.748115
3,2018-07-20 16:25:52.784534,2018-07-20 16:25:52.818577
4,2018-07-20 16:25:52.850347,2018-07-20 16:25:53.650743
5,2018-07-20 16:25:53.682903,2018-07-20 16:25:53.713877
6,2018-07-20 16:25:53.752210,2018-07-20 16:25:54.980915
7,2018-07-20 16:25:55.015023,2018-07-20 16:25:55.054432
8,2018-07-20 16:25:55.083007,2018-07-20 16:25:55.114010
9,2018-07-20 16:25:55.151263,2018-07-20 16:25:55.681425
10,2018-07-20 16:25:55.713382,2018-07-20 16:25:55.745624
11,2018-07-20 16:25:55.782112,2018-07-20 16:25:56.982078
12,2018-07-20 16:25:57.016760,2018-07-20 16:25:57.047928
13,2018-07-20 16:25:57.078765,2018-07-20 16:25:57.113705
14,2018-07-20 16:25:57.946889,2018-07-20 16:25:57.980079
15,2018-07-20 16:25:58.017876,2018-07-20 16:25:58.048768
16,2018-07-20 16:25:58.079373,2018-07-20 16:25:58.115729
1 start end
2 0 2018-07-20 16:25:51.415964 2018-07-20 16:25:51.449240
3 1 2018-07-20 16:25:51.487239 2018-07-20 16:25:51.517014
4 2 2018-07-20 16:25:52.719849 2018-07-20 16:25:52.748115
5 3 2018-07-20 16:25:52.784534 2018-07-20 16:25:52.818577
6 4 2018-07-20 16:25:52.850347 2018-07-20 16:25:53.650743
7 5 2018-07-20 16:25:53.682903 2018-07-20 16:25:53.713877
8 6 2018-07-20 16:25:53.752210 2018-07-20 16:25:54.980915
9 7 2018-07-20 16:25:55.015023 2018-07-20 16:25:55.054432
10 8 2018-07-20 16:25:55.083007 2018-07-20 16:25:55.114010
11 9 2018-07-20 16:25:55.151263 2018-07-20 16:25:55.681425
12 10 2018-07-20 16:25:55.713382 2018-07-20 16:25:55.745624
13 11 2018-07-20 16:25:55.782112 2018-07-20 16:25:56.982078
14 12 2018-07-20 16:25:57.016760 2018-07-20 16:25:57.047928
15 13 2018-07-20 16:25:57.078765 2018-07-20 16:25:57.113705
16 14 2018-07-20 16:25:57.946889 2018-07-20 16:25:57.980079
17 15 2018-07-20 16:25:58.017876 2018-07-20 16:25:58.048768
18 16 2018-07-20 16:25:58.079373 2018-07-20 16:25:58.115729