Skip to content

Commit

Permalink
it works
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Lei authored and Brandon Lei committed Oct 4, 2024
1 parent 754c4c3 commit 29851ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion LineDetection.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
this.canvas.height = height;
this.ctx = this.canvas.getContext('2d');
this.lastDetectedLine = [];
this.frameCount = 0;
this.allCoordinates = [];
}

async detectLine() {
Expand All @@ -39,6 +41,14 @@
this.lastDetectedLine = lineCoordinates;
}

if (this.frameCount < 7) {
this.allCoordinates.push(lineCoordinates);
this.frameCount++;
if (this.frameCount === 7) {
this.writeCoordinatesToFile(this.allCoordinates);
}
}

this.drawLine(this.lastDetectedLine);
return this.canvas.toDataURL();
} catch (error) {
Expand Down Expand Up @@ -83,6 +93,18 @@
});
this.ctx.stroke();
}

writeCoordinatesToFile(allCoordinates) {
const content = allCoordinates.map((frame, index) =>
`Frame ${index + 1}:\n${frame.map(coord => coord.join(',')).join('\n')}\n`
).join('\n');
const blob = new Blob([content], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'coordinates.txt';
a.click();
URL.revokeObjectURL(a.href);
}
}

let detector;
Expand Down Expand Up @@ -119,4 +141,3 @@ <h1>Line Detection</h1>
<img id="outputImage" alt="Processed Image">
</body>
</html>

1 change: 1 addition & 0 deletions extensions/src/doodlebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class DoodlebotBlocks extends extension(details, "ui", "indicator
text: "displayLine"
})
async displayLine() {
console.log("displayLine");
if (!this.lineDetector) {
const ipAddress = await this.doodlebot?.getIPAddress();
if (!ipAddress) {
Expand Down

0 comments on commit 29851ea

Please sign in to comment.