Skip to content

Commit 5ecd267

Browse files
committed
Added graph plotting in Bokeh
1 parent 9a0fb04 commit 5ecd267

File tree

5 files changed

+121
-7
lines changed

5 files changed

+121
-7
lines changed

Project6-FaceDetection/Graph1.html

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
3+
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
8+
<head>
9+
10+
<meta charset="utf-8">
11+
<title>Bokeh Plot</title>
12+
13+
14+
15+
16+
<link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-0.13.0.min.css" type="text/css" />
17+
18+
19+
20+
<script type="text/javascript" src="https://cdn.pydata.org/bokeh/release/bokeh-0.13.0.min.js"></script>
21+
<script type="text/javascript">
22+
Bokeh.set_log_level("info");
23+
</script>
24+
25+
26+
27+
28+
</head>
29+
30+
31+
<body>
32+
33+
34+
35+
36+
37+
<div class="bk-root" id="ba0d7700-6f18-4609-86b8-ebe145999aa6"></div>
38+
39+
40+
41+
42+
<script type="application/json" id="e833eda6-990a-4f39-b512-58ddd675ce52">
43+
{"04a2799a-eece-4aa6-9993-0e71ed533ca5":{"roots":{"references":[{"attributes":{},"id":"4935fa83-ee99-45f7-a0c1-9a933f57a6a9","type":"DatetimeTickFormatter"},{"attributes":{},"id":"81d8cd61-bcba-4c6b-83fa-600eca5b97e6","type":"BasicTickFormatter"},{"attributes":{"mantissas":[1,2,5],"max_interval":500.0,"num_minor_ticks":0},"id":"4610b280-8e8f-4e6b-bc94-0afa6bc2dd0c","type":"AdaptiveTicker"},{"attributes":{"base":60,"mantissas":[1,2,5,10,15,20,30],"max_interval":1800000.0,"min_interval":1000.0,"num_minor_ticks":0},"id":"d05aefa2-165b-419d-be4e-0f3a7d3c2d70","type":"AdaptiveTicker"},{"attributes":{"active_drag":"auto","active_inspect":"auto","active_multi":null,"active_scroll":"auto","active_tap":"auto","tools":[{"id":"5b19ab41-9c8c-46f0-ade4-721acf9f7b19","type":"PanTool"},{"id":"f48cfe29-8283-4d23-935a-52eb1947b395","type":"WheelZoomTool"},{"id":"3047d68f-cc93-4f66-b358-2c270d95df8e","type":"BoxZoomTool"},{"id":"7e5b8219-ea8b-4dce-91a1-226f5930a907","type":"SaveTool"},{"id":"f162d65d-0c58-423e-83be-fbd9b6ce0c85","type":"ResetTool"},{"id":"99d3d3f8-30c0-4519-8074-c2054f295c74","type":"HelpTool"},{"id":"062e1a85-7e18-4095-960d-d86913fa8853","type":"HoverTool"}]},"id":"5f2b4243-d7af-4c4c-9c40-a2f87a64656e","type":"Toolbar"},{"attributes":{"callback":null,"renderers":"auto","tooltips":[["Start","@Start_string"],["End","@End_string"]]},"id":"062e1a85-7e18-4095-960d-d86913fa8853","type":"HoverTool"},{"attributes":{"base":24,"mantissas":[1,2,4,6,8,12],"max_interval":43200000.0,"min_interval":3600000.0,"num_minor_ticks":0},"id":"36be6b94-0fb2-497c-a4b5-4460882594f6","type":"AdaptiveTicker"},{"attributes":{"days":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]},"id":"799a7d6d-aaaa-4494-a548-4558d0e14895","type":"DaysTicker"},{"attributes":{"days":[1,4,7,10,13,16,19,22,25,28]},"id":"dd0abe0d-ae6b-41b4-a4db-f65ba7d83c33","type":"DaysTicker"},{"attributes":{"bottom":{"value":0},"fill_color":{"value":"green"},"left":{"field":"Start"},"line_color":{"value":"green"},"right":{"field":"End"},"top":{"value":1}},"id":"08491dde-fa80-4f64-99c5-1d975a1cb50d","type":"Quad"},{"attributes":{"days":[1,8,15,22]},"id":"c830e881-0971-4ce1-a73c-035085f85e90","type":"DaysTicker"},{"attributes":{"days":[1,15]},"id":"01363bee-a688-4996-a84a-7fa725526230","type":"DaysTicker"},{"attributes":{},"id":"3314b9a7-f7aa-4ffa-a15c-26027428b023","type":"LinearScale"},{"attributes":{"months":[0,1,2,3,4,5,6,7,8,9,10,11]},"id":"407bf632-e04d-4033-89c9-937487140483","type":"MonthsTicker"},{"attributes":{"callback":null},"id":"2d42547c-eb9e-4e15-8147-9c83be5a0479","type":"DataRange1d"},{"attributes":{"months":[0,2,4,6,8,10]},"id":"2958e2e1-581b-4c3e-a81e-43c4bf6a2ce6","type":"MonthsTicker"},{"attributes":{"months":[0,4,8]},"id":"1be76908-5ea2-498c-8ad2-bdb9217886ef","type":"MonthsTicker"},{"attributes":{"months":[0,6]},"id":"f342b5c4-e1b3-4d21-9c10-dcee1004d441","type":"MonthsTicker"},{"attributes":{"callback":null,"data":{"END":{"__ndarray__":"0drE94dJdkI=","dtype":"float64","shape":[1]},"End":{"__ndarray__":"/Knx0k1iQMM=","dtype":"float64","shape":[1]},"End_string":["NaT"],"Start":{"__ndarray__":"deES94dJdkI=","dtype":"float64","shape":[1]},"Start_string":["2018-07-14 11:14:06"],"index":[0]},"selected":{"id":"8e7aca40-a5b7-4fc6-ae47-318d7183d70b","type":"Selection"},"selection_policy":{"id":"a8fe59f8-7d30-46df-8218-db66bc9ecf90","type":"UnionRenderers"}},"id":"b4221854-71d6-4914-ae6a-bd3815ee5b1d","type":"ColumnDataSource"},{"attributes":{},"id":"f57d5ddb-8e6a-485b-a057-107a3a34f70f","type":"YearsTicker"},{"attributes":{"plot":{"id":"f2bb602b-ca57-42ab-9505-2e5b9a8b122b","subtype":"Figure","type":"Plot"},"ticker":{"id":"9accc99b-1ddf-42b2-bd68-f119b59f864a","type":"DatetimeTicker"}},"id":"fdb1c32c-78ae-4aba-ae41-8db08dc8b0cf","type":"Grid"},{"attributes":{},"id":"8e7aca40-a5b7-4fc6-ae47-318d7183d70b","type":"Selection"},{"attributes":{"num_minor_ticks":5,"tickers":[{"id":"4610b280-8e8f-4e6b-bc94-0afa6bc2dd0c","type":"AdaptiveTicker"},{"id":"d05aefa2-165b-419d-be4e-0f3a7d3c2d70","type":"AdaptiveTicker"},{"id":"36be6b94-0fb2-497c-a4b5-4460882594f6","type":"AdaptiveTicker"},{"id":"799a7d6d-aaaa-4494-a548-4558d0e14895","type":"DaysTicker"},{"id":"dd0abe0d-ae6b-41b4-a4db-f65ba7d83c33","type":"DaysTicker"},{"id":"c830e881-0971-4ce1-a73c-035085f85e90","type":"DaysTicker"},{"id":"01363bee-a688-4996-a84a-7fa725526230","type":"DaysTicker"},{"id":"407bf632-e04d-4033-89c9-937487140483","type":"MonthsTicker"},{"id":"2958e2e1-581b-4c3e-a81e-43c4bf6a2ce6","type":"MonthsTicker"},{"id":"1be76908-5ea2-498c-8ad2-bdb9217886ef","type":"MonthsTicker"},{"id":"f342b5c4-e1b3-4d21-9c10-dcee1004d441","type":"MonthsTicker"},{"id":"f57d5ddb-8e6a-485b-a057-107a3a34f70f","type":"YearsTicker"}]},"id":"9accc99b-1ddf-42b2-bd68-f119b59f864a","type":"DatetimeTicker"},{"attributes":{},"id":"a8fe59f8-7d30-46df-8218-db66bc9ecf90","type":"UnionRenderers"},{"attributes":{"formatter":{"id":"81d8cd61-bcba-4c6b-83fa-600eca5b97e6","type":"BasicTickFormatter"},"minor_tick_line_color":{"value":null},"plot":{"id":"f2bb602b-ca57-42ab-9505-2e5b9a8b122b","subtype":"Figure","type":"Plot"},"ticker":{"id":"58045773-3dcc-4b63-af36-27031276a285","type":"BasicTicker"}},"id":"0ceb56cb-e984-4b1f-af07-84e2ae0f5d10","type":"LinearAxis"},{"attributes":{"plot":null,"text":"Motion Graph"},"id":"ef0ed18b-76b2-4bbf-a563-2b66538082b3","type":"Title"},{"attributes":{"desired_num_ticks":1},"id":"58045773-3dcc-4b63-af36-27031276a285","type":"BasicTicker"},{"attributes":{"dimension":1,"plot":{"id":"f2bb602b-ca57-42ab-9505-2e5b9a8b122b","subtype":"Figure","type":"Plot"},"ticker":{"id":"58045773-3dcc-4b63-af36-27031276a285","type":"BasicTicker"}},"id":"364bb7de-ae6c-4ff0-bdf8-515b998a1b52","type":"Grid"},{"attributes":{"bottom_units":"screen","fill_alpha":{"value":0.5},"fill_color":{"value":"lightgrey"},"left_units":"screen","level":"overlay","line_alpha":{"value":1.0},"line_color":{"value":"black"},"line_dash":[4,4],"line_width":{"value":2},"plot":null,"render_mode":"css","right_units":"screen","top_units":"screen"},"id":"f567685c-084f-44db-80af-d68c98cca6de","type":"BoxAnnotation"},{"attributes":{"callback":null},"id":"1a58f062-0020-485b-8e31-f0e8c28c33ed","type":"DataRange1d"},{"attributes":{},"id":"5b19ab41-9c8c-46f0-ade4-721acf9f7b19","type":"PanTool"},{"attributes":{"bottom":{"value":0},"fill_alpha":{"value":0.1},"fill_color":{"value":"#1f77b4"},"left":{"field":"Start"},"line_alpha":{"value":0.1},"line_color":{"value":"#1f77b4"},"right":{"field":"End"},"top":{"value":1}},"id":"af4b0717-ddc4-484e-a5b8-8172a36f7e48","type":"Quad"},{"attributes":{"data_source":{"id":"b4221854-71d6-4914-ae6a-bd3815ee5b1d","type":"ColumnDataSource"},"glyph":{"id":"08491dde-fa80-4f64-99c5-1d975a1cb50d","type":"Quad"},"hover_glyph":null,"muted_glyph":null,"nonselection_glyph":{"id":"af4b0717-ddc4-484e-a5b8-8172a36f7e48","type":"Quad"},"selection_glyph":null,"view":{"id":"75ddb917-563b-402a-9b73-f298e41cd2de","type":"CDSView"}},"id":"03e5f81b-e144-4233-9e55-bdd1c5d39d56","type":"GlyphRenderer"},{"attributes":{},"id":"f48cfe29-8283-4d23-935a-52eb1947b395","type":"WheelZoomTool"},{"attributes":{"formatter":{"id":"4935fa83-ee99-45f7-a0c1-9a933f57a6a9","type":"DatetimeTickFormatter"},"plot":{"id":"f2bb602b-ca57-42ab-9505-2e5b9a8b122b","subtype":"Figure","type":"Plot"},"ticker":{"id":"9accc99b-1ddf-42b2-bd68-f119b59f864a","type":"DatetimeTicker"}},"id":"9fef2505-d78a-484e-a91e-141ccd195a68","type":"DatetimeAxis"},{"attributes":{"overlay":{"id":"f567685c-084f-44db-80af-d68c98cca6de","type":"BoxAnnotation"}},"id":"3047d68f-cc93-4f66-b358-2c270d95df8e","type":"BoxZoomTool"},{"attributes":{},"id":"7e5b8219-ea8b-4dce-91a1-226f5930a907","type":"SaveTool"},{"attributes":{},"id":"f162d65d-0c58-423e-83be-fbd9b6ce0c85","type":"ResetTool"},{"attributes":{"source":{"id":"b4221854-71d6-4914-ae6a-bd3815ee5b1d","type":"ColumnDataSource"}},"id":"75ddb917-563b-402a-9b73-f298e41cd2de","type":"CDSView"},{"attributes":{},"id":"99d3d3f8-30c0-4519-8074-c2054f295c74","type":"HelpTool"},{"attributes":{},"id":"5b90bdcc-95d0-424c-a774-9a507c13f105","type":"LinearScale"},{"attributes":{"below":[{"id":"9fef2505-d78a-484e-a91e-141ccd195a68","type":"DatetimeAxis"}],"left":[{"id":"0ceb56cb-e984-4b1f-af07-84e2ae0f5d10","type":"LinearAxis"}],"plot_height":100,"plot_width":500,"renderers":[{"id":"9fef2505-d78a-484e-a91e-141ccd195a68","type":"DatetimeAxis"},{"id":"fdb1c32c-78ae-4aba-ae41-8db08dc8b0cf","type":"Grid"},{"id":"0ceb56cb-e984-4b1f-af07-84e2ae0f5d10","type":"LinearAxis"},{"id":"364bb7de-ae6c-4ff0-bdf8-515b998a1b52","type":"Grid"},{"id":"f567685c-084f-44db-80af-d68c98cca6de","type":"BoxAnnotation"},{"id":"03e5f81b-e144-4233-9e55-bdd1c5d39d56","type":"GlyphRenderer"}],"sizing_mode":"scale_width","title":{"id":"ef0ed18b-76b2-4bbf-a563-2b66538082b3","type":"Title"},"toolbar":{"id":"5f2b4243-d7af-4c4c-9c40-a2f87a64656e","type":"Toolbar"},"x_range":{"id":"1a58f062-0020-485b-8e31-f0e8c28c33ed","type":"DataRange1d"},"x_scale":{"id":"3314b9a7-f7aa-4ffa-a15c-26027428b023","type":"LinearScale"},"y_range":{"id":"2d42547c-eb9e-4e15-8147-9c83be5a0479","type":"DataRange1d"},"y_scale":{"id":"5b90bdcc-95d0-424c-a774-9a507c13f105","type":"LinearScale"}},"id":"f2bb602b-ca57-42ab-9505-2e5b9a8b122b","subtype":"Figure","type":"Plot"}],"root_ids":["f2bb602b-ca57-42ab-9505-2e5b9a8b122b"]},"title":"Bokeh Application","version":"0.13.0"}}
44+
</script>
45+
<script type="text/javascript">
46+
(function() {
47+
var fn = function() {
48+
Bokeh.safely(function() {
49+
(function(root) {
50+
function embed_document(root) {
51+
52+
var docs_json = document.getElementById('e833eda6-990a-4f39-b512-58ddd675ce52').textContent;
53+
var render_items = [{"docid":"04a2799a-eece-4aa6-9993-0e71ed533ca5","roots":{"f2bb602b-ca57-42ab-9505-2e5b9a8b122b":"ba0d7700-6f18-4609-86b8-ebe145999aa6"}}];
54+
root.Bokeh.embed.embed_items(docs_json, render_items);
55+
56+
}
57+
if (root.Bokeh !== undefined) {
58+
embed_document(root);
59+
} else {
60+
var attempts = 0;
61+
var timer = setInterval(function(root) {
62+
if (root.Bokeh !== undefined) {
63+
embed_document(root);
64+
clearInterval(timer);
65+
}
66+
attempts++;
67+
if (attempts > 100) {
68+
console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing")
69+
clearInterval(timer);
70+
}
71+
}, 10, root)
72+
}
73+
})(window);
74+
});
75+
};
76+
if (document.readyState != "loading") fn();
77+
else document.addEventListener("DOMContentLoaded", fn);
78+
})();
79+
</script>
80+
81+
</body>
82+
83+
</html>

Project6-FaceDetection/Times.csv

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
,Start,End,END
2-
0,2018-07-11 16:15:50.329286,,2018-07-11 16:15:50.343558
3-
1,2018-07-11 16:15:50.371213,,2018-07-11 16:15:55.901013
2+
0,2018-07-14 11:52:48.363216,,2018-07-14 11:52:57.117491
3+
1,2018-07-14 11:52:57.381828,,2018-07-14 11:53:02.357403
4+
2,2018-07-14 11:53:02.485783,,2018-07-14 11:53:08.541854
5+
3,2018-07-14 11:53:09.330664,,2018-07-14 11:53:11.551983
6+
4,2018-07-14 11:53:11.683509,,2018-07-14 11:53:11.814517
7+
5,2018-07-14 11:53:12.863569,,2018-07-14 11:53:15.868537
8+
6,2018-07-14 11:53:17.047192,,2018-07-14 11:53:33.538832
9+
7,2018-07-14 11:53:34.059060,,2018-07-14 11:53:34.197151
Binary file not shown.

Project6-FaceDetection/motion_detector.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cv2 as cv
22
from datetime import datetime
3-
import pandas
3+
import pandas,imutils
44
first_frame=None #stores the first frame...
55
status_list=[None,None] #stroing the status if objects
66
times=[] #storing the datetime for objects
@@ -9,6 +9,7 @@
99
while True:
1010
#two attributes check->:boolean that tells video is recording..while frame :-> ndarray
1111
check,frame=video.read()
12+
frame = imutils.resize(frame, width=500)
1213
#this status=0 means there is no motion right now..
1314
status=0
1415
#print(check)
@@ -23,20 +24,23 @@
2324
continue #now if we continue then there will be no first frame,because it is pre generated.
2425

2526
delta_frame=cv.absdiff(first_frame,gray) #this finding the diff between the first frame(background) and other frames of video.
26-
thresh_frame=cv.threshold(delta_frame,30,255,cv.THRESH_BINARY)[1] #create threshold frame
27-
thresh_frame=cv.dilate(thresh_frame,None,iterations=2) #dilate means making tthe edges smoother
27+
#thresh_frame=cv.threshold(delta_frame,50,255,cv.THRESH_BINARY)[1] #create threshold frame
2828

29+
#thresh_frame=cv.adaptiveThreshold(delta_frame,255,cv.ADAPTIVE_THRESH_MEAN_C ,cv.THRESH_BINARY,11,2)
30+
thresh_frame=cv.threshold(delta_frame,160,255,cv.THRESH_BINARY)[1]
31+
thresh_frame=cv.dilate(thresh_frame,None,iterations=2 ) #dilate means making tthe edges smoother
2932
#finding the contours which helps to find out objects in a frame.
3033
(_,cnts,_)=cv.findContours(thresh_frame.copy(),cv.RETR_EXTERNAL,cv.CHAIN_APPROX_SIMPLE)
3134
for contour in cnts:
3235
#if area of object is less then 1000 then we will continue otherwise there is an object.
33-
if cv.contourArea(contour)<1000:
36+
if cv.contourArea(contour)<15000:
3437
continue
3538
status=1 #this implies there is an object in a frame
3639
(x,y,w,h)=cv.boundingRect(contour) # finding the corners of object in a frame.
37-
cv.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3) # making out rectangle for every objects
40+
cv.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2) # making out rectangle for every objects
3841
#appending all the incoming and outgoing of the object in an frame
3942
status_list.append(status)
43+
status_list=status_list[-2:]
4044

4145
#checking the datetime of apearing object
4246
if status_list[-1]==1 and status_list[-2]==0:

Project6-FaceDetection/plotting.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from motion_detector import df
2+
from bokeh.plotting import figure, show, output_file
3+
from bokeh.models import HoverTool, ColumnDataSource
4+
5+
df["Start_string"]=df["Start"].dt.strftime("%Y-%m-%d %H:%M:%S")
6+
df["End_string"]=df["End"].dt.strftime("%Y-%m-%d %H:%M:%S")
7+
8+
9+
cds=ColumnDataSource(df)
10+
11+
p=figure(x_axis_type='datetime',height=100, width=500, sizing_mode="scale_width",title="Motion Graph")
12+
p.yaxis.minor_tick_line_color=None
13+
p.ygrid[0].ticker.desired_num_ticks=1
14+
15+
hover=HoverTool(tooltips=[("Start","@Start_string"),("End","@End_string")])
16+
p.add_tools(hover)
17+
18+
q=p.quad(left="Start",right="End",bottom=0,top=1,color="green",source=cds)
19+
20+
output_file("Graph1.html")
21+
show(p)

0 commit comments

Comments
 (0)