Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the mirror web issue #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
transform: translateZ(0);
opacity: 1;
}

100% {
-webkit-transform: translateZ(-1100px);
transform: translateZ(-1100px);
opacity: 0;
}
}

@keyframes slide-out-bck-center {
0% {
-webkit-transform: translateZ(0);
transform: translateZ(0);
opacity: 1;
}

100% {
-webkit-transform: translateZ(-1100px);
transform: translateZ(-1100px);
Expand All @@ -40,18 +43,21 @@
transform: scale(0);
opacity: 1;
}

100% {
-webkit-transform: scale(1);
transform: scale(1);
opacity: 1;
}
}

@keyframes scale-in-center {
0% {
-webkit-transform: scale(0);
transform: scale(0);
opacity: 1;
}

100% {
-webkit-transform: scale(1);
transform: scale(1);
Expand All @@ -64,16 +70,19 @@
-webkit-transform: rotate(0);
transform: rotate(0);
}

100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@keyframes rotate-center {
0% {
-webkit-transform: rotate(0);
transform: rotate(0);
}

100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
Expand Down Expand Up @@ -238,7 +247,8 @@
}

#image-wrapper {
height: 56px; /* .image(height) + 2*.image(margin)*/
height: 56px;
/* .image(height) + 2*.image(margin)*/
}

#image-wrapper .text {
Expand Down Expand Up @@ -524,19 +534,21 @@ form {
}

.slide-out-bck-center {
-webkit-animation: slide-out-bck-center 0.5s
cubic-bezier(0.55, 0.085, 0.68, 0.53) both;
animation: slide-out-bck-center 0.5s cubic-bezier(0.55, 0.085, 0.68, 0.53)
both;
-webkit-animation: slide-out-bck-center 0.5s cubic-bezier(0.55, 0.085, 0.68, 0.53) both;
animation: slide-out-bck-center 0.5s cubic-bezier(0.55, 0.085, 0.68, 0.53) both;
}

.scale-in-center {
-webkit-animation: scale-in-center 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94)
both;
-webkit-animation: scale-in-center 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
animation: scale-in-center 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.plus:hover {
-webkit-animation: rotate-center 0.6s ease-in-out both;
animation: rotate-center 0.6s ease-in-out both;
}

.videoflip {
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
}
58 changes: 30 additions & 28 deletions frontend/src/Cam.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@ class Cam extends React.Component {
}

componentDidMount() {
new Promise((resolve, reject) => {
new Promise((resolve, reject) => {
const navigatorAny = navigator;
navigator.getUserMedia = navigator.getUserMedia ||
navigatorAny.webkitGetUserMedia || navigatorAny.mozGetUserMedia ||
navigatorAny.msGetUserMedia;
navigatorAny.webkitGetUserMedia || navigatorAny.mozGetUserMedia ||
navigatorAny.msGetUserMedia;
if (navigator.getUserMedia) {
navigator.mediaDevices.getUserMedia(
{video: true}).then(stream => {
this.webcam.current.srcObject = stream;
this.setState({working: true, videoWidth: stream.getVideoTracks()[0].getSettings()['width'],
videoHeight: stream.getVideoTracks()[0].getSettings()['height']});
}).catch(error => {this.setState({working: false}); });
{ video: true }).then(stream => {
this.webcam.current.srcObject = stream;
this.setState({
working: true, videoWidth: stream.getVideoTracks()[0].getSettings()['width'],
videoHeight: stream.getVideoTracks()[0].getSettings()['height']
});
}).catch(error => { this.setState({ working: false }); });
} else {
reject(this.setState({working: false}));
reject(this.setState({ working: false }));
}
});
}

static getDerivedStateFromProps(props, state) {
if(props.currentLabel !== state.currentLabel && props.currentLabel !== state.homeLabel) {
return {currentLabel: props.currentLabel, homeLabel: props.currentLabel};
if (props.currentLabel !== state.currentLabel && props.currentLabel !== state.homeLabel) {
return { currentLabel: props.currentLabel, homeLabel: props.currentLabel };
}
return null;
}

handleDropdownSelect(selectedLabel) {
this.setState({currentLabel: selectedLabel})
this.setState({ currentLabel: selectedLabel })
}

loadedData() {
Expand All @@ -57,7 +59,7 @@ class Cam extends React.Component {
* Returns a batched image (1-element batch) of shape [1, w, h, c].
*/
async capture() {
const result = tf.tidy((video=this.webcam) => {
const result = tf.tidy((video = this.webcam) => {
//console.log("Inside Webcam")
// Reads the image as a Tensor from the webcam <video> element.
const webcamImage = tf.browser.fromPixels(video.current);
Expand Down Expand Up @@ -94,7 +96,7 @@ class Cam extends React.Component {
const beginWidth = centerWidth - (size / 2);
return img.slice([beginHeight, beginWidth, 0], [size, size, 3]);
}

/**
* Adjusts the video size so we can make a centered square crop without
* including whitespace.
Expand All @@ -110,30 +112,30 @@ class Cam extends React.Component {
}
}

render () {
render() {
return (
<div className="record-box">
{!this.props.testing? <div className="recording-for-dropdown-wrapper">
{!this.props.testing ? <div className="recording-for-dropdown-wrapper">
<p className="record-p">CAPTURING FOR: &nbsp;</p>
<DropdownButton
<DropdownButton
disabled={this.props.allLabels.length === 0}
title={this.props.allLabels.length === 0 ? "No Labels" : this.state.currentLabel}
size="sm"
title={this.props.allLabels.length === 0 ? "No Labels" : this.state.currentLabel}
size="sm"
variant="outline-light">
{this.props.allLabels.map(l => {
return (
<Dropdown.Item key={l} onClick={() => this.handleDropdownSelect(l)}>{l}</Dropdown.Item>
)
{this.props.allLabels.map(l => {
return (
<Dropdown.Item key={l} onClick={() => this.handleDropdownSelect(l)}>{l}</Dropdown.Item>
)
})}
</DropdownButton>
</div> : <div/>}
<video hidden={this.state && this.state.working ? '' : 'hidden'} autoPlay playsInline muted id="webcam" width="100" height="100" onLoadedData={this.loadedData} ref={this.webcam}></video>
</div> : <div />}
<video className='videoflip' hidden={this.state && this.state.working ? '' : 'hidden'} autoPlay playsInline muted id="webcam" width="100" height="100" onLoadedData={this.loadedData} ref={this.webcam}></video>
<div id="no-webcam" hidden={this.state && this.state.working ? 'hidden' : ''}>
No webcam found. <br/>
No webcam found. <br />
To use this interface, use a device with a webcam.
</div>
<div className="record-and-countdown">
<Button onClick={this.capture} disabled={this.props.allLabels.length === 0} variant= "outline-light" className="record-button">
<Button onClick={this.capture} disabled={this.props.allLabels.length === 0} variant="outline-light" className="record-button">
{"Capture"}
</Button>
</div>
Expand Down