VideoAnalysis.js
4.04 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
Row,
Col,
Button,
Form,
FormGroup,
} from 'reactstrap';
import Widget from '../../components/Widget/Widget';
var fireResultImages=[];
var unknownResultImages=[];
class Dashboard extends React.Component {
constructor(props) {
super(props);
this.onChangeInputVideo = this.onChangeInputVideo.bind(this);
this.onClickSaveVideo = this.onClickSaveVideo.bind(this);
// this.analysisVideo = this.analysisVideo.bind(this);
this.state = {
videoFiles: [],
videoAnalysisResult:null,
};
}
importAll(r){
return r.keys().map(r);
}
onChangeInputVideo(e) {
const files = [];
const reader = new FileReader();
files.push(e.target.files[0]);
reader.onloadend = () => {
files[0].preview = reader.result;
files[0].toUpload = true;
this.setState({
videoFiles: files,
});
};
reader.readAsDataURL(e.target.files[0]);
}
onClickSaveVideo(e) {
e.preventDefault();
console.log("upload video");
// post request
fetch('http://localhost:3004/api/videoResult',{
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
redirect: 'follow',
referrer: 'no-referrer',
body: JSON.stringify(this.state.videoFiles)
})
.then(res=>res.json())
.then(data=>this.setState({videoAnalysisResult:data}))
console.log(this.state.videoAnalysisResult);
}
static propTypes = {
visits: PropTypes.any,
performance: PropTypes.any,
};
componentWillMount(){
fireResultImages= this.importAll(require.context('../../../../Back-end/fire/', false, /\.(png|jpg|svg)$/))
unknownResultImages= this.importAll(require.context('../../../../Back-end/unknown/', false, /\.(png|jpg|svg)$/))
}
render() {
console.log(this.state.videoAnalysisResult);
return (
<div>
<h1 className="page-title">Video Analysis <small><small>Performance</small></small></h1>
<Row>
<Col lg={9} xs={12}>
<Widget
title={<h5> Registrate <span className="fw-semi-bold">Video</span></h5>}
>
<Form>
<FormGroup style={{margin:'15px'}}>
<Col md="8">
<input
accept="video/*" onChange={this.onChangeInputVideo}
id="fileupload"
type="file" name="file" className="display-none"
/>
<div>
<Button type="button" color="default" onClick={this.onClickSaveVideo} style={{margin:'10px 0px 0px 0px'}}>Analysis Video</Button>
</div>
</Col>
</FormGroup>
</Form>
</Widget>
</Col>
</Row>
<Row>
<Col lg={9} xs={12}>
<Widget
title={<h5><span className="fw-semi-bold">Results</span></h5>}
>
<div>
{fireResultImages.length > 0 ? <div>
<p className="fw-semi-bold"> 불났어요!!
</p>
{fireResultImages.map(
(image, index) => <img style={{height: '200px', margin: '10px 10px 10px 10px'}}alt="..." key={index} src={image}/>)}
</div> : <div/>}
</div>
<div>
{unknownResultImages.length > 0 ? <div>
<p className="fw-semi-bold"> 침입자 발생!!
</p>
{unknownResultImages.map(
(image, index) => <img style={{height: '200px', margin: '10px 10px 10px 10px'}}alt="..." key={index} src={image}/>)}
</div> : <div/>}
</div>
</Widget>
</Col>
</Row>
</div>
);
}
}
function mapStateToProps(state) {
return {
filters: state.filters,
}
}
export default connect(mapStateToProps)(Dashboard);