-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
|
||
export const drawRect = (detections:any, ctx:any) =>{ | ||
// Loop through each prediction | ||
detections.forEach((prediction:any) => { | ||
try{ | ||
// Loop through each prediction | ||
detections.forEach((prediction:any) => { | ||
const lastElem=detections[detections.length-1] | ||
|
||
// Extract boxes and classes | ||
const [x, y, width, height] = prediction['bbox']; | ||
const text = prediction['class']; | ||
|
||
// Extract boxes and classes | ||
const [x, y, width, height] = prediction['bbox']; | ||
const text = prediction['class']; | ||
// Create a new instance of SpeechSynthesisUtterance | ||
var speech = new SpeechSynthesisUtterance(lastElem['class']); | ||
|
||
// Create a new instance of SpeechSynthesisUtterance | ||
var speech = new SpeechSynthesisUtterance(text); | ||
// Set the voice, rate, pitch, and language if desired | ||
speech.lang = 'en-US'; // You can change the language | ||
speech.rate = 1; // Speed (default is 1, range: 0.1 to 10) | ||
speech.pitch = 1; // Pitch (default is 1, range: 0 to 2) | ||
|
||
// Set the voice, rate, pitch, and language if desired | ||
speech.lang = 'en-US'; // You can change the language | ||
speech.rate = 1; // Speed (default is 1, range: 0.1 to 10) | ||
speech.pitch = 1; // Pitch (default is 1, range: 0 to 2) | ||
// Speak the text | ||
window.speechSynthesis.speak(speech); | ||
|
||
// Speak the text | ||
window.speechSynthesis.speak(speech); | ||
// Set styling | ||
const color = Math.floor(Math.random()*16777215).toString(16); | ||
ctx.strokeStyle = '#' + color | ||
ctx.font = '18px Arial'; | ||
|
||
// Set styling | ||
const color = Math.floor(Math.random()*16777215).toString(16); | ||
ctx.strokeStyle = '#' + color | ||
ctx.font = '18px Arial'; | ||
|
||
// Draw rectangles and text | ||
ctx.beginPath(); | ||
ctx.fillStyle = '#' + color | ||
ctx.fillText(text, x, y); | ||
ctx.rect(x, y, width, height); | ||
ctx.stroke(); | ||
}); | ||
// Draw rectangles and text | ||
ctx.beginPath(); | ||
ctx.fillStyle = '#' + color | ||
ctx.fillText(text, x, y); | ||
ctx.rect(x, y, width, height); | ||
ctx.stroke(); | ||
}); | ||
}catch(error:any){ | ||
console.log(error.message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters