Skip to content

Commit

Permalink
remove track on preview
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Feb 18, 2024
1 parent 3bdcaa4 commit bf55e7c
Showing 1 changed file with 72 additions and 61 deletions.
133 changes: 72 additions & 61 deletions static/js/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export enum CameraConnectionState {
}

const UUID = new Date().getTime();

const showTracks = false;
interface CameraStats {
skippedFramesServer: number;
skippedFramesClient: number;
Expand Down Expand Up @@ -69,22 +69,22 @@ function restartCameraViewing() {
}

async function triggerTrap() {
document.getElementById("trigger-trap")!.innerText = 'Triggering trap';
document.getElementById("trigger-trap")!.innerText = "Triggering trap";
document.getElementById("trigger-trap")!.setAttribute("disabled", "true");
console.log("triggering trap");
fetch('/api/trigger-trap', {
method: 'PUT',
headers: {
'Authorization': 'Basic YWRtaW46ZmVhdGhlcnM='
}})

.then(response => console.log(response))
.then(data => console.log(data))
.catch(error => console.error(error))
fetch("/api/trigger-trap", {
method: "PUT",
headers: {
Authorization: "Basic YWRtaW46ZmVhdGhlcnM=",
},
})
.then((response) => console.log(response))
.then((data) => console.log(data))
.catch((error) => console.error(error));
//TODO handle errors better and check that recording was made properly instead of just waiting..
await new Promise(r => setTimeout(r, 3000));
await new Promise((r) => setTimeout(r, 3000));
document.getElementById("trigger-trap")!.removeAttribute("disabled");
document.getElementById("trigger-trap")!.innerText = 'Trigger trap';
document.getElementById("trigger-trap")!.innerText = "Trigger trap";
}

window.onload = function () {
Expand All @@ -94,7 +94,8 @@ window.onload = function () {
}
document.getElementById("snapshot-restart")!.onclick = restartCameraViewing;
document.getElementById("trigger-trap")!.onclick = triggerTrap;
document.getElementById("take-snapshot-recording")!.onclick = takeTestRecording;
document.getElementById("take-snapshot-recording")!.onclick =
takeTestRecording;
cameraConnection = new CameraConnection(
window.location.hostname,
window.location.port,
Expand All @@ -104,22 +105,28 @@ window.onload = function () {
};

async function takeTestRecording() {
document.getElementById("take-snapshot-recording")!.innerText = 'Making a test recording';
document.getElementById("take-snapshot-recording")!.setAttribute("disabled", "true");
document.getElementById("take-snapshot-recording")!.innerText =
"Making a test recording";
document
.getElementById("take-snapshot-recording")!
.setAttribute("disabled", "true");
console.log("making a test recording");
fetch('/api/camera/snapshot-recording', {
method: 'PUT',
headers: {
'Authorization': 'Basic YWRtaW46ZmVhdGhlcnM='
}})

.then(response => console.log(response))
.then(data => console.log(data))
.catch(error => console.error(error))
fetch("/api/camera/snapshot-recording", {
method: "PUT",
headers: {
Authorization: "Basic YWRtaW46ZmVhdGhlcnM=",
},
})
.then((response) => console.log(response))
.then((data) => console.log(data))
.catch((error) => console.error(error));
//TODO handle errors better and check that recording was made properly instead of just waiting..
await new Promise(r => setTimeout(r, 3000));
document.getElementById("take-snapshot-recording")!.removeAttribute("disabled");
document.getElementById("take-snapshot-recording")!.innerText = 'Take test recording';
await new Promise((r) => setTimeout(r, 3000));
document
.getElementById("take-snapshot-recording")!
.removeAttribute("disabled");
document.getElementById("take-snapshot-recording")!.innerText =
"Take test recording";
}

function stopSnapshots(message: string) {
Expand Down Expand Up @@ -197,13 +204,13 @@ async function processFrame(frame: Frame) {
if (canvas == null) {
return;
}
if( canvas.width != frame.frameInfo.Camera.ResX){
canvas.width = frame.frameInfo.Camera.ResX
trackCanvas.width = frame.frameInfo.Camera.ResX
if (canvas.width != frame.frameInfo.Camera.ResX) {
canvas.width = frame.frameInfo.Camera.ResX;
trackCanvas.width = frame.frameInfo.Camera.ResX;
}
if(canvas.height != frame.frameInfo.Camera.ResY){
canvas.height = frame.frameInfo.Camera.ResY
trackCanvas.height = frame.frameInfo.Camera.ResY
if (canvas.height != frame.frameInfo.Camera.ResY) {
canvas.height = frame.frameInfo.Camera.ResY;
trackCanvas.height = frame.frameInfo.Camera.ResY;
}
const context = canvas.getContext("2d") as CanvasRenderingContext2D;
const imgData = context.getImageData(
Expand All @@ -214,26 +221,26 @@ async function processFrame(frame: Frame) {
);
// gp hack to see if ir camera, dbus from python makes dictionary have to be all int type
let irCamera = frame.frameInfo.Camera.ResX >= 640;
if(irCamera){
if (irCamera) {
document.getElementById("trigger-trap")!.style.display = "";
}else{
} else {
document.getElementById("trigger-trap")!.style.display = "none";
}
let max=0;
let min=0;
let range=0;
if (!irCamera){
let max = 0;
let min = 0;
let range = 0;
if (!irCamera) {
max = Math.max(...frame.frame);
min = Math.min(...frame.frame);
range = max - min;
}
let maxI = 0;
for (let i = 0; i < frame.frame.length; i++) {
let pix = 0
if(irCamera){
pix = frame.frame[i]
}else{
pix = Math.min(255, ((frame.frame[i] - min) / range) * 255.0);
let pix = 0;
if (irCamera) {
pix = frame.frame[i];
} else {
pix = Math.min(255, ((frame.frame[i] - min) / range) * 255.0);
}
let index = i * 4;
imgData.data[index] = pix;
Expand All @@ -244,24 +251,28 @@ async function processFrame(frame: Frame) {
}
context.putImageData(imgData, 0, 0);

const trackContext = trackCanvas.getContext("2d") as CanvasRenderingContext2D;
trackContext.clearRect(0, 0, trackCanvas.width, trackCanvas.height);
if (showTracks) {
const trackContext = trackCanvas.getContext(
"2d"
) as CanvasRenderingContext2D;
trackContext.clearRect(0, 0, trackCanvas.width, trackCanvas.height);

let index = 0;
if (frame.frameInfo.Tracks) {
for (const track of frame.frameInfo.Tracks) {
let what = null;
if (track.predictions && track.predictions.length > 0) {
what = track.predictions[0].label;
let index = 0;
if (frame.frameInfo.Tracks) {
for (const track of frame.frameInfo.Tracks) {
let what = null;
if (track.predictions && track.predictions.length > 0) {
what = track.predictions[0].label;
}
drawRectWithText(
trackContext,
frame.frameInfo.Camera,
track.positions[track.positions.length - 1],
what,
index
);
index += 1;
}
drawRectWithText(
trackContext,
frame.frameInfo.Camera,
track.positions[track.positions.length - 1],
what,
index
);
index += 1;
}
}
document.getElementById(
Expand Down

0 comments on commit bf55e7c

Please sign in to comment.