-
Notifications
You must be signed in to change notification settings - Fork 0
/
recognize.js
115 lines (100 loc) · 3.21 KB
/
recognize.js
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
import React, { Component } from 'react';
import Webcam from 'react-webcam';
import '../styles/register.css';
// material-ui component
import RaisedButton from 'material-ui/RaisedButton';
import RefreshIndicator from 'material-ui/RefreshIndicator';
import { Grid, Row, Col } from 'react-flexbox-grid';
import axios from 'axios';
import { connect } from 'react-redux';
import { recognizeUser, clearDisplayData } from '../actions';
import UserRecognize from './user-recognize';
// loader styling
const style = {
container: {
position: 'absolute',
},
refresh: {
display: 'inline-block',
position: 'absolute',
},
hide: {
display: 'none',
position: 'absolute',
},
};
class Recognize extends Component {
constructor(props) {
super(props);
this.state = {
load: false
};
}
componentDidMount() {
this.props.clearDisplayData();
}
setRef = (webcam) => {
this.webcam = webcam;
}
capture = () => {
this.setState({
load: true
});
const imageSrc = this.webcam.getScreenshot();
axios.post(`https://api.kairos.com/recognize`, {
gallery_name: 'newFaceGallery',
image: imageSrc
}, {
headers: {
app_id: 'some id',
app_key: 'some key'
}
}).then((response) => {
console.log('response', response);
this.props.recognizeUser(response.data);
this.setState({
load: false
});
}).catch((error) => {
console.log(error);
});
};
render() {
return (
<Grid fluid>
<Row>
<Col xs={12} md={4} mdOffset={4}>
<div style={{ 'textAlign': 'center' }}>
<h3>DETECT FACE</h3>
<Webcam
audio={false}
height={320}
ref={this.setRef}
screenshotFormat="image/png"
width={320}
/>
<RefreshIndicator
className='css-loader'
size={80}
left={70}
top={0}
loadingColor="#ADD8E6"
status="loading"
style={(this.state.load === false) ? style.hide : style.refresh}
/>
<br />
<RaisedButton onClick={this.capture} label="DETECT" primary={true} style={{ 'margin': 16 }} />
<UserRecognize detect={this.props.detData} />
</div>
</Col>
</Row>
</Grid>
);
}
}
function mapStateToProps(state) {
return {
detData: state.detData
}
}
export default connect(mapStateToProps, { recognizeUser, clearDisplayData })(Recognize);