-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial RoboflowObjectDetector implementation, Redux state updates
- Loading branch information
Showing
8 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as express from 'roboflow'; | ||
|
||
|
||
export interface DetectedObject { | ||
bbox: [number, number, number, number]; | ||
class: string; | ||
score: number; | ||
} | ||
|
||
|
||
export class RoboflowObjectDetector { | ||
private static model; | ||
|
||
public static loadModel( | ||
publishableKey: string, | ||
modelId: string, | ||
modelVersion: number, | ||
onSuccess: () => unknown, | ||
onError: (error: Error) => unknown | ||
) { | ||
roboflow.auth({ | ||
publishable_key: publishableKey | ||
}).load({ | ||
model: modelId, | ||
version: modelVersion | ||
}).then((model) => { | ||
RoboflowObjectDetector.model = model | ||
onSuccess() | ||
}).catch((error) => { | ||
onError(error) | ||
}) | ||
} | ||
|
||
public static predict(image: HTMLImageElement, callback?: (predictions: DetectedObject[]) => unknown) { | ||
if (!RoboflowObjectDetector.model) return; | ||
|
||
RoboflowObjectDetector.model | ||
.detect(image) | ||
.then((predictions: DetectedObject[]) => { | ||
if (callback) { | ||
callback(predictions) | ||
} | ||
}) | ||
.catch((error) => { | ||
// TODO | ||
throw new Error(error as string); | ||
}) | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@import '../../../settings/Settings'; | ||
|
||
.load-roboflow-model-popup { | ||
display: flex; | ||
flex-direction: column; | ||
flex-wrap: nowrap; | ||
justify-content: center; | ||
align-items: center; | ||
align-content: center; | ||
padding: 40px 0; | ||
flex: 1; | ||
|
||
.message { | ||
align-self: stretch; | ||
color: white; | ||
font-size: 15px; | ||
padding: 0 40px 30px 40px; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
flex-wrap: nowrap; | ||
align-items: center; | ||
|
||
> a { | ||
max-width: 120px; | ||
margin-bottom: 30px; | ||
|
||
> img { | ||
max-width: 120px; | ||
user-select: none; | ||
} | ||
} | ||
} | ||
} |
89 changes: 85 additions & 4 deletions
89
src/views/PopupView/LoadRoboflowModelPopup/LoadRoboflowModelPopup.tsx
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