Skip to content

Commit

Permalink
Fix yolo demo for iOS and macOS Safari (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkat0 committed Sep 14, 2021
1 parent 9fb9c20 commit 6782126
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/components/common/WebcamModelUI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ export default class WebcamModelUI extends Vue {
this.webcamElement,
beginWidth,
beginHeight,
this.videoOrigWidth,
this.videoOrigHeight,
size,
size,
0,
0,
this.webcamElement.width,
this.webcamElement.height
canvas.width,
canvas.height
);
return context;
}
Expand Down Expand Up @@ -575,6 +575,7 @@ export default class WebcamModelUI extends Vue {
height: 416px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
& :nth-child(n + 3) {
Expand Down
1 change: 1 addition & 0 deletions src/components/models/Emotion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class Emotion extends Vue {
) {
const rect = document.createElement("div");
const label = document.createElement("div");
rect.style.cssText = `top: 0px;`;
label.style.cssText = "font-size: 24px";
label.innerText = text;
rect.appendChild(label);
Expand Down
7 changes: 5 additions & 2 deletions src/components/models/Yolo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ export default class Yolo extends Vue {
text = "",
color = "red"
) {
const webcamContainerElement = document.getElementById("webcam-container") as HTMLElement;
// Depending on the display size, webcamContainerElement might be smaller than 416x416.
const [ox, oy] = [(webcamContainerElement.offsetWidth - 416) / 2, (webcamContainerElement.offsetHeight - 416) / 2];
const rect = document.createElement("div");
rect.style.cssText = `top: ${y}px; left: ${x}px; width: ${w}px; height: ${h}px; border-color: ${color};`;
rect.style.cssText = `top: ${y+oy}px; left: ${x+ox}px; width: ${w}px; height: ${h}px; border-color: ${color};`;
const label = document.createElement("div");
label.innerText = text;
rect.appendChild(label);
(document.getElementById("webcam-container") as HTMLElement).appendChild(
webcamContainerElement.appendChild(
rect
);
}
Expand Down

0 comments on commit 6782126

Please sign in to comment.