Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromaticPanic committed Jun 4, 2024
1 parent 35e5c68 commit e2254cc
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 114 deletions.
1 change: 1 addition & 0 deletions src/common/cacheutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export const loadResultsToCache = (
...box.box,
inferenceId: inferenceData.inferenceId,
boxId: box.boxId,
classId: box.classId,
label: box.label,
};
}),
Expand Down
30 changes: 24 additions & 6 deletions src/common/imageutils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { BoxCSS, BoxCoordinates } from "./types";

export const getScaledBounds = (
containerWidth: number,
containerHeight: number,
itemWidth: number,
itemHeight: number,
box: {
topX: number;
topY: number;
bottomX: number;
bottomY: number;
},
box: BoxCoordinates,
): {
scaledWidth: number;
scaledHeight: number;
Expand All @@ -28,3 +25,24 @@ export const getScaledBounds = (
scaledTopY,
};
};

export const getUnscaledCoordinates = (
containerWidth: number,
containerHeight: number,
itemWidth: number,
itemHeight: number,
box: BoxCSS,
): BoxCoordinates => {
const scaleFactorWidth = itemWidth / containerWidth;
const scaleFactorHeight = itemHeight / containerHeight;
const topX = box.left * scaleFactorWidth;
const topY = box.top * scaleFactorHeight;
const bottomX = box.left + box.minWidth * scaleFactorWidth;
const bottomY = box.top + box.minHeight * scaleFactorHeight;
return {
topX,
topY,
bottomX,
bottomY,
};
};
8 changes: 8 additions & 0 deletions src/common/tests/loadresultstocache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ describe("loadResultsToCache", () => {

let inferenceData: ApiInferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box: {
Expand All @@ -38,6 +40,7 @@ describe("loadResultsToCache", () => {
},
{
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box: {
Expand All @@ -52,6 +55,7 @@ describe("loadResultsToCache", () => {
},
{
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box: {
Expand Down Expand Up @@ -87,10 +91,12 @@ describe("loadResultsToCache", () => {

inferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box: {
Expand All @@ -105,6 +111,7 @@ describe("loadResultsToCache", () => {
},
{
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box: {
Expand All @@ -119,6 +126,7 @@ describe("loadResultsToCache", () => {
},
{
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box: {
Expand Down
12 changes: 11 additions & 1 deletion src/common/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export interface ApiInferenceData {
filename: string;
imageId: string;
inferenceId: string;
boxes: Array<{
topN: Array<{ score: number; label: string }>;
score: number;
label: string;
classId: string;
boxId: string;
box: BoxCoordinates;
overlapping: boolean;
Expand Down Expand Up @@ -39,6 +41,7 @@ export interface BoxCoordinates {
export interface InferenceBox extends BoxCoordinates {
inferenceId: string;
boxId: string;
classId: string;
label: string;
}

Expand All @@ -65,6 +68,7 @@ export interface FeedbackDataPositive extends FeedbackData {
export interface FeedbackDataNegative extends FeedbackData {
boxes: Array<{
label: string;
classId: string;
boxId: string;
box: BoxCoordinates;
comment: string;
Expand All @@ -76,8 +80,14 @@ export interface LabelOccurrences {
}

// TODO: Redefine when the backend is updated
interface SpeciesData {
interface ClassData {
id: number;
classId: string;
label: string;
}

interface ApiSpeciesData {
classId: string;
label: string;
}

Expand Down
Loading

0 comments on commit e2254cc

Please sign in to comment.