Azaion Suite to the web. First commit. Only rough sketches of future components is done.

This commit is contained in:
Alex Bezdieniezhnykh
2025-03-18 16:28:15 +02:00
commit 2ab732c6b4
32 changed files with 28735 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
.idea
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
+70
View File
@@ -0,0 +1,70 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
+17581
View File
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
{
"name": "azaion.webui",
"version": "0.1.1",
"private": true,
"dependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^13.5.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-dropzone": "^14.3.8",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
+28
View File
@@ -0,0 +1,28 @@
{
"classes": [
{ "Id": 0, "Name": "Heavy truck" },
{ "Id": 1, "Name": "Truck" },
{ "Id": 2, "Name": "Car" },
{ "Id": 3, "Name": "Big Foot" },
{ "Id": 4, "Name": "Shadow" },
{ "Id": 5, "Name": "Pit" },
{ "Id": 6, "Name": "Person" },
{ "Id": 7, "Name": "TyreTracks" },
{ "Id": 8, "Name": "Bus" },
{ "Id": 9, "Name": "Smoke" },
{ "Id": 10, "Name": "Plane" },
{ "Id": 11, "Name": "Moto" },
{ "Id": 12, "Name": "Mesh" },
{ "Id": 13, "Name": "Branches" }
],
"colors": [
"#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF", "#000000",
"#800000", "#008000", "#000080", "#808000", "#800080", "#008080", "#808080",
"#C00000", "#00C000", "#0000C0", "#C0C000", "#C000C0", "#00C0C0", "#C0C0C0",
"#400000", "#004000", "#000040", "#404000", "#400040", "#004040", "#404040",
"#200000", "#002000", "#000020", "#202000", "#200020", "#002020", "#202020",
"#600000", "#006000", "#000060", "#606000", "#600060", "#006060", "#606060",
"#A00000", "#00A000", "#0000A0", "#A0A000", "#A000A0", "#00A0A0", "#A0A0A0",
"#E00000", "#00E000", "#0000E0", "#E0E000", "#E000E0", "#00E0E0", "#E0E0E0"
]
}
+24
View File
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo128.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Azaion Suite</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
+128
View File
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
viewBox="0 0 299.9 317.1" style="enable-background:new 0 0 299.9 317.1;" xml:space="preserve">
<style type="text/css">
.st0{fill:#2668B0;}
.st1{fill:#DEC354;}
.st2{fill:url(#SVGID_1_);}
.st3{fill:url(#SVGID_00000165956440124760579960000011888077842116744085_);}
.st4{fill:url(#SVGID_00000085942576275962151710000009003104917087656334_);}
.st5{fill:url(#SVGID_00000065057939898373943770000009142597344814158991_);}
.st6{fill:url(#SVGID_00000042707575094020397520000008210262669309136559_);}
.st7{fill:url(#SVGID_00000132081218125063996810000014374475908356398251_);}
.st8{fill:#FFFFFF;}
</style>
<g id="Layer_2_00000152245310683770285410000018119804670128610436_">
<polygon class="st0" points="0.1,169.5 12.1,166.5 12.1,51.2 0,20.1 "/>
<polygon class="st1" points="241,169.1 229.1,166.1 229,50.7 241.1,19.7 "/>
<polygon class="st0" points="119.6,153.6 107.7,158.3 107.7,18 119.8,0 "/>
<polygon class="st1" points="119.5,153.8 131.8,158.3 131.9,18 119.8,0 "/>
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="120.3286" y1="259.6066" x2="120.3286" y2="78.8283" gradientTransform="matrix(1 0 0 -1 0 320)">
<stop offset="3.000000e-02" style="stop-color:#FFFFFF"/>
<stop offset="0.1" style="stop-color:#EDEDED"/>
<stop offset="0.26" style="stop-color:#C0BEBF"/>
<stop offset="0.48" style="stop-color:#767474"/>
<stop offset="0.7" style="stop-color:#231F20"/>
</linearGradient>
<polygon class="st2" points="0.1,169.5 47,153.1 82.2,166.3 102.5,157.3 119.5,149.8 157.9,166.7 194,153.3 240.6,168.8 121.1,255
"/>
<linearGradient id="SVGID_00000114788463727787464510000017845518411005303225_" gradientUnits="userSpaceOnUse" x1="58.437" y1="149.7064" x2="68.2775" y2="175.7949" gradientTransform="matrix(1 0 0 -1 0 320)">
<stop offset="0.27" style="stop-color:#231F20"/>
<stop offset="0.28" style="stop-color:#2C2829"/>
<stop offset="0.37" style="stop-color:#767474"/>
<stop offset="0.44" style="stop-color:#B1AFB0"/>
<stop offset="0.51" style="stop-color:#DBDADA"/>
<stop offset="0.56" style="stop-color:#F5F5F5"/>
<stop offset="0.59" style="stop-color:#FFFFFF"/>
</linearGradient>
<polygon style="fill:url(#SVGID_00000114788463727787464510000017845518411005303225_);" points="47,153.1 42,154.8 76.9,169.3
82.1,166.4 "/>
<linearGradient id="SVGID_00000102533530282145531860000014371344717116336017_" gradientUnits="userSpaceOnUse" x1="-45.5872" y1="149.6743" x2="-35.8351" y2="175.5215" gradientTransform="matrix(-1 0 0 -1 136.44 320)">
<stop offset="0.27" style="stop-color:#231F20"/>
<stop offset="0.28" style="stop-color:#2C2829"/>
<stop offset="0.37" style="stop-color:#767474"/>
<stop offset="0.44" style="stop-color:#B1AFB0"/>
<stop offset="0.51" style="stop-color:#DBDADA"/>
<stop offset="0.56" style="stop-color:#F5F5F5"/>
<stop offset="0.59" style="stop-color:#FFFFFF"/>
</linearGradient>
<polygon style="fill:url(#SVGID_00000102533530282145531860000014371344717116336017_);" points="194,153.3 199,155 163.6,169.4
157.9,166.7 "/>
<linearGradient id="SVGID_00000075841790156840098560000006699003196656470950_" gradientUnits="userSpaceOnUse" x1="119.6532" y1="175.4803" x2="119.6532" y2="164.7475" gradientTransform="matrix(1 0 0 -1 0 320)">
<stop offset="3.000000e-02" style="stop-color:#FFFFFF"/>
<stop offset="0.44" style="stop-color:#9B9A9A"/>
<stop offset="0.83" style="stop-color:#454142"/>
<stop offset="1" style="stop-color:#231F20"/>
</linearGradient>
<polygon style="fill:url(#SVGID_00000075841790156840098560000006699003196656470950_);" points="119.5,149.8 133.7,156.1
119.5,154.4 105.6,156 "/>
<linearGradient id="SVGID_00000080899814652598392920000002338730188455222667_" gradientUnits="userSpaceOnUse" x1="19.1991" y1="43.9763" x2="111.4936" y2="184.9104" gradientTransform="matrix(1 0 0 -1 0 320)">
<stop offset="0.1" style="stop-color:#FFFFFF"/>
<stop offset="0.17" style="stop-color:#FCFCFC"/>
<stop offset="0.2" style="stop-color:#F5F4F4"/>
<stop offset="0.23" style="stop-color:#E7E7E7"/>
<stop offset="0.26" style="stop-color:#D4D4D4"/>
<stop offset="0.28" style="stop-color:#BCBBBB"/>
<stop offset="0.3" style="stop-color:#9E9C9D"/>
<stop offset="0.32" style="stop-color:#7A7878"/>
<stop offset="0.33" style="stop-color:#524F50"/>
<stop offset="0.35" style="stop-color:#252122"/>
<stop offset="0.35" style="stop-color:#231F20"/>
<stop offset="0.37" style="stop-color:#262324"/>
<stop offset="0.39" style="stop-color:#322F30"/>
<stop offset="0.4" style="stop-color:#464344"/>
<stop offset="0.42" style="stop-color:#625F60"/>
<stop offset="0.44" style="stop-color:#868484"/>
<stop offset="0.46" style="stop-color:#B2B0B0"/>
<stop offset="0.47" style="stop-color:#E5E4E4"/>
<stop offset="0.47" style="stop-color:#E7E6E6"/>
</linearGradient>
<polygon style="fill:url(#SVGID_00000080899814652598392920000002338730188455222667_);" points="0.1,169.5 0.9,169.3 122.5,253.9
121.1,255 "/>
<linearGradient id="SVGID_00000182519911580066729170000000492446570726535336_" gradientUnits="userSpaceOnUse" x1="-393.4447" y1="33.4059" x2="-285.4408" y2="198.3462" gradientTransform="matrix(-1 0 0 -1 -163.84 320)">
<stop offset="0.1" style="stop-color:#FFFFFF"/>
<stop offset="0.17" style="stop-color:#FCFCFC"/>
<stop offset="0.2" style="stop-color:#F5F4F4"/>
<stop offset="0.23" style="stop-color:#E7E7E7"/>
<stop offset="0.26" style="stop-color:#D4D4D4"/>
<stop offset="0.28" style="stop-color:#BCBBBB"/>
<stop offset="0.3" style="stop-color:#9E9C9D"/>
<stop offset="0.32" style="stop-color:#7A7878"/>
<stop offset="0.33" style="stop-color:#524F50"/>
<stop offset="0.35" style="stop-color:#252122"/>
<stop offset="0.35" style="stop-color:#231F20"/>
<stop offset="0.37" style="stop-color:#262324"/>
<stop offset="0.39" style="stop-color:#322F30"/>
<stop offset="0.4" style="stop-color:#464344"/>
<stop offset="0.42" style="stop-color:#625F60"/>
<stop offset="0.44" style="stop-color:#868484"/>
<stop offset="0.46" style="stop-color:#B2B0B0"/>
<stop offset="0.47" style="stop-color:#E5E4E4"/>
<stop offset="0.47" style="stop-color:#E7E6E6"/>
</linearGradient>
<polygon style="fill:url(#SVGID_00000182519911580066729170000000492446570726535336_);" points="241.1,169 240.4,168.7 119.7,254
121.1,255 "/>
</g>
<g id="Layer_3">
<g>
<path class="st8" d="M175.3,195.5h-1.6v-10.9l19.7,8.5v-8.5h1.6v10.9l-19.7-8.5V195.5L175.3,195.5L175.3,195.5z"/>
<path class="st8" d="M150.7,195.6c-0.6,0-1.2-0.1-1.7-0.3c-0.5-0.2-1-0.5-1.4-0.9c-0.4-0.4-0.7-0.9-0.9-1.4
c-0.2-0.5-0.3-1.1-0.3-1.7v-2.4c0-0.6,0.1-1.2,0.3-1.7c0.2-0.5,0.5-1,0.9-1.4c0.4-0.4,0.9-0.7,1.4-0.9s1.1-0.3,1.7-0.3h12.6
c0.6,0,1.2,0.1,1.7,0.3s1,0.5,1.4,0.9c0.4,0.4,0.7,0.9,0.9,1.4c0.2,0.5,0.3,1.1,0.3,1.7v2.4c0,0.6-0.1,1.2-0.3,1.7s-0.5,1-0.9,1.4
c-0.4,0.4-0.9,0.7-1.4,0.9c-0.5,0.2-1.1,0.3-1.7,0.3H150.7z M150.7,186.1c-0.4,0-0.7,0.1-1.1,0.2c-0.3,0.1-0.6,0.3-0.9,0.6
c-0.2,0.2-0.5,0.5-0.6,0.9s-0.2,0.7-0.2,1.1v2.4c0,0.4,0.1,0.7,0.2,1.1c0.1,0.3,0.3,0.6,0.6,0.9c0.3,0.2,0.5,0.5,0.9,0.6
c0.3,0.1,0.7,0.2,1.1,0.2h12.6c0.4,0,0.7-0.1,1.1-0.2c0.3-0.1,0.6-0.3,0.9-0.6c0.2-0.3,0.5-0.5,0.6-0.9c0.1-0.3,0.2-0.7,0.2-1.1
v-2.4c0-0.4-0.1-0.7-0.2-1.1c-0.1-0.3-0.3-0.6-0.6-0.9c-0.3-0.2-0.5-0.4-0.9-0.6c-0.3-0.2-0.7-0.2-1.1-0.2H150.7z"/>
<path class="st8" d="M137.2,195.6v-13h1.9v13L137.2,195.6L137.2,195.6z"/>
<path class="st8" d="M57,184.5l11.9,11.1H51.4l1.5-1.6h12l-7.8-7.3l-9.5,8.9h-2.3L57,184.5L57,184.5L57,184.5z"/>
<path class="st8" d="M96,184.6v1.6L78.7,194H96v1.6H75v-1.6l17.4-7.8H75v-1.6H96L96,184.6z"/>
<path class="st8" d="M116.1,182.6l13.8,13h-20.4l1.8-1.8h14l-9.1-8.6L105,195.6h-2.7L116.1,182.6L116.1,182.6L116.1,182.6z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+25
View File
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo128.png",
"type": "image/png",
"sizes": "128x128"
},
{
"src": "logo256.png",
"type": "image/png",
"sizes": "256x256"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
+3
View File
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
+38
View File
@@ -0,0 +1,38 @@
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
+13
View File
@@ -0,0 +1,13 @@
import React from 'react';
import AnnotationMain from './components/AnnotationMain';
function App() {
return (
<div style={{ width: '100%', height: '100vh' }}> {/* Use full viewport height */}
<AnnotationMain />
</div>
);
}
export default App;
+8
View File
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
+8
View File
@@ -0,0 +1,8 @@
const saveAnnotation = async (time, annotations, imageData) => {
// Implement save logic here, including YOLO format conversion
console.log("Saving annotation", time, annotations, imageData);
//Save the image data to a folder.
//Save the annotations to a .txt file in YOLO format.
};
export default saveAnnotation;
+15
View File
@@ -0,0 +1,15 @@
import React from 'react';
function AnnotationControls({ onFrameBackward, onPlayPause, isPlaying, onFrameForward, onSaveAnnotation, onDelete }) {
return (
<div style={{ display: 'flex', justifyContent: 'center', position: 'relative', zIndex: 1 }}>
<button style={{ padding: '10px 20px', fontSize: '16px', margin: '0 5px' }} onClick={onFrameBackward}></button>
<button style={{ padding: '10px 20px', fontSize: '16px', margin: '0 5px' }} onClick={onPlayPause}>{isPlaying ? 'Pause' : 'Play'}</button>
<button style={{ padding: '10px 20px', fontSize: '16px', margin: '0 5px' }} onClick={onFrameForward}></button>
<button style={{ padding: '10px 20px', fontSize: '16px', margin: '0 5px' }} onClick={onSaveAnnotation}>Save Annotation</button>
<button style={{ padding: '10px 20px', fontSize: '16px', margin: '0 5px' }} onClick={onDelete}>Delete</button>
</div>
);
}
export default AnnotationControls;
+20
View File
@@ -0,0 +1,20 @@
// src/components/AnnotationList.js
// No changes
import React from 'react';
function AnnotationList({ annotations, onAnnotationClick }) {
return (
<div>
<h3>Annotations</h3>
<ul>
{annotations.map((annotation, index) => (
<li key={index} onClick={() => onAnnotationClick(annotation.time)}>
Frame {index + 1} - {annotation.annotations.length} objects
</li>
))}
</ul>
</div>
);
}
export default AnnotationList;
+156
View File
@@ -0,0 +1,156 @@
import React, { useState, useEffect } from 'react';
import VideoPlayer from './VideoPlayer';
import AnnotationList from './AnnotationList';
import MediaList from './MediaList';
import DetectionClassList from './DetectionClassList';
import CanvasEditor from './CanvasEditor';
import * as AnnotationService from '../services/AnnotationService';
import AnnotationControls from './AnnotationControls'; // Import the new component
function AnnotationMain() {
const [files, setFiles] = useState([]);
const [selectedFile, setSelectedFile] = useState(null);
const [annotations, setAnnotations] = useState({});
const [currentTime, setCurrentTime] = useState(0);
const [selectedClass, setSelectedClass] = useState(null);
const [detections, setDetections] = useState([]);
const [selectedDetectionIndices, setSelectedDetectionIndices] = useState([]);
const [isPlaying, setIsPlaying] = useState(false); // Add isPlaying state here
const videoRef = React.createRef();
useEffect(() => {
const initialFiles = [];
setFiles(initialFiles);
}, []);
const handleFileSelect = (file) => {
console.log("handleFileSelect called with:", file);
setSelectedFile(file);
setAnnotations({});
setDetections([]);
setSelectedDetectionIndices([]);
setCurrentTime(0);
setIsPlaying(false); // Reset playing state
};
const handleDropNewFiles = (newFiles) => {
setFiles(prevFiles => [...prevFiles, ...newFiles]);
if (!selectedFile) {
setSelectedFile(newFiles[0]);
}
};
const handleAnnotationSave = () => {
const containerRef = { current: { offsetWidth: videoRef.current.videoWidth, offsetHeight: videoRef.current.videoHeight } };
const annotationSelectedClass = selectedClass;
const imageData = AnnotationService.createAnnotationImage(videoRef, detections, null, annotationSelectedClass, containerRef);
if (imageData) {
setAnnotations(prevAnnotations => ({
...prevAnnotations,
[currentTime]: { time: currentTime, detections: detections, imageData },
}));
}
};
const handleDelete = () => {
const newDetections = detections.filter((_, index) => !selectedDetectionIndices.includes(index));
setDetections(newDetections);
};
const handleAnnotationClick = (time) => {
setCurrentTime(time);
const annotation = annotations[time];
if (annotation) {
setDetections(annotation.detections);
setSelectedDetectionIndices([]);
}
if (videoRef.current) {
videoRef.current.currentTime = time;
}
setIsPlaying(false); // Pause when clicking an annotation
};
const handleClassSelect = (cls) => {
setSelectedClass(cls);
};
const handleDetectionsChange = (newDetections) => {
setDetections(newDetections);
};
const handleSelectionChange = (newSelection) => {
setSelectedDetectionIndices(newSelection);
};
const handlePlayPause = () => { // Moved from VideoPlayer
setIsPlaying(prev => !prev);
if (videoRef.current) {
if (isPlaying) {
videoRef.current.pause();
} else {
videoRef.current.play();
}
}
};
const handleFrameForward = () => { // Moved from VideoPlayer
if (videoRef.current) {
videoRef.current.currentTime += 1 / 30;
setCurrentTime(videoRef.current.currentTime)
}
};
const handleFrameBackward = () => { // Moved from VideoPlayer
if (videoRef.current) {
videoRef.current.currentTime -= 1 / 30;
setCurrentTime(videoRef.current.currentTime)
}
};
return (
<div style={{ display: 'flex' }}>
<div style={{ width: '15%', paddingRight: '10px', display: 'flex', flexDirection: 'column' }}>
<MediaList
files={files}
selectedFile={selectedFile}
onFileSelect={handleFileSelect}
onDropNewFiles={handleDropNewFiles}
/>
<div style={{ marginTop: 'auto' }}>
<DetectionClassList onClassSelect={handleClassSelect} />
</div>
<AnnotationList annotations={Object.values(annotations)} onAnnotationClick={handleAnnotationClick} />
</div>
<div style={{ width: '85%' }}>
<VideoPlayer
videoFile={selectedFile}
currentTime={currentTime}
videoRef={videoRef}
isPlaying = {isPlaying}
>
<CanvasEditor
width={videoRef.current ? videoRef.current.videoWidth : 0}
height={videoRef.current ? videoRef.current.videoHeight : 0}
detections={detections}
selectedDetectionIndices={selectedDetectionIndices}
onDetectionsChange={handleDetectionsChange}
onSelectionChange={handleSelectionChange}
detectionClass={selectedClass}
/>
</VideoPlayer>
<AnnotationControls
onFrameBackward={handleFrameBackward}
onPlayPause={handlePlayPause}
isPlaying={isPlaying}
onFrameForward={handleFrameForward}
onSaveAnnotation={handleAnnotationSave}
onDelete={handleDelete}
/>
</div>
</div>
);
}
export default AnnotationMain;
+229
View File
@@ -0,0 +1,229 @@
import React, { useRef, useState, useEffect } from 'react';
import * as AnnotationService from '../services/AnnotationService';
import DetectionContainer from './DetectionContainer';
function CanvasEditor({
width,
height,
detections,
initialCurrentDetection = null,
selectedDetectionIndices,
onDetectionsChange,
onSelectionChange,
children,
detectionClass
}) {
const containerRef = useRef(null);
const [currentDetection, setCurrentDetection] = useState(initialCurrentDetection);
const [mouseDownPos, setMouseDownPos] = useState(null);
const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });
const [resizeData, setResizeData] = useState(null);
const [localDetections, setLocalDetections] = useState(detections || []);
const [localSelectedIndices, setLocalSelectedIndices] = useState(selectedDetectionIndices || []);
useEffect(() => {
setLocalDetections(detections || []);
}, [detections]);
useEffect(() => {
setLocalSelectedIndices(selectedDetectionIndices || []);
}, [selectedDetectionIndices]);
const handleMouseDown = (e) => {
e.preventDefault();
if (!containerRef.current) return;
const { x: mouseX, y: mouseY } = AnnotationService.calculateRelativeCoordinates(e, containerRef);
setMouseDownPos({ mouseX, mouseY });
let detectionFound = false;
for (let i = localDetections.length - 1; i >= 0; i--) {
if (AnnotationService.isMouseOverDetection(e.clientX, e.clientY, localDetections[i], containerRef)) {
if (e.ctrlKey) {
const newSelectedIndices = localSelectedIndices.includes(i)
? localSelectedIndices.filter(index => index !== i)
: [...localSelectedIndices, i];
setLocalSelectedIndices(newSelectedIndices);
if (onSelectionChange) {
onSelectionChange(newSelectedIndices);
}
} else {
const newSelectedIndices = [i];
setLocalSelectedIndices(newSelectedIndices);
if (onSelectionChange) {
onSelectionChange(newSelectedIndices);
}
}
setDragOffset({
x: mouseX - localDetections[i].x1,
y: mouseY - localDetections[i].y1,
});
detectionFound = true;
break; // Stop the loop once a detection is found
}
}
if (!detectionFound) {
if (!e.ctrlKey) {
setLocalSelectedIndices([]);
if (onSelectionChange) {
onSelectionChange([]);
}
}
if (detectionClass) {
setCurrentDetection({ x1: mouseX, y1: mouseY, x2: mouseX, y2: mouseY, class: detectionClass });
}
}
};
const handleMouseMove = (e) => {
if (!containerRef.current) return;
const { x: mouseX, y: mouseY } = AnnotationService.calculateRelativeCoordinates(e, containerRef);
if (localSelectedIndices.length > 0 && mouseDownPos && !resizeData) {
// Dragging logic
const newDetections = [...localDetections];
const firstSelectedIndex = localSelectedIndices[0];
// Check for valid index before accessing.
if (firstSelectedIndex === undefined || !newDetections[firstSelectedIndex]) return;
const firstSelectedDetection = newDetections[firstSelectedIndex];
const { newX1, newY1, newX2, newY2 } = AnnotationService.calculateNewPosition(mouseX, mouseY, dragOffset, firstSelectedDetection, containerRef);
const deltaX = newX1 - firstSelectedDetection.x1;
const deltaY = newY1 - firstSelectedDetection.y1;
localSelectedIndices.forEach(index => {
// Check for valid index before accessing.
if (newDetections[index] === undefined) return;
const detection = newDetections[index];
let updatedX1 = detection.x1 + deltaX;
let updatedY1 = detection.y1 + deltaY;
let updatedX2 = detection.x2 + deltaX;
let updatedY2 = detection.y2 + deltaY;
const bounds = AnnotationService.calculateNewPosition(updatedX1 + dragOffset.x, updatedY1 + dragOffset.y, dragOffset, { ...detection, x1: updatedX1, y1: updatedY1, x2: updatedX2, y2: updatedY2 }, containerRef);
detection.x1 = bounds.newX1;
detection.y1 = bounds.newY1;
detection.x2 = bounds.newX2;
detection.y2 = bounds.newY2;
});
setLocalDetections(newDetections);
if (onDetectionsChange) {
onDetectionsChange(newDetections); // Notify about changes
}
} else if (currentDetection && !resizeData) {
// Drawing a new detection.
setCurrentDetection(prev => ({ ...prev, x2: mouseX, y2: mouseY }));
} else if (resizeData) {
const { index, position } = resizeData;
if (localDetections[index] === undefined) return;
const newDetections = [...localDetections];
const detection = newDetections[index];
const updatedDetection = AnnotationService.calculateResizedPosition(mouseX, mouseY, position, detection, containerRef);
newDetections[index] = updatedDetection;
setLocalDetections(newDetections);
if (onDetectionsChange) {
onDetectionsChange(newDetections);
}
}
};
const handleMouseUp = () => {
if (currentDetection && mouseDownPos) {
const dx = Math.abs(currentDetection.x2 - currentDetection.x1);
const dy = Math.abs(currentDetection.y2 - currentDetection.y1);
if (dx > 5 && dy > 5) {
const newDetections = [...localDetections, currentDetection];
setLocalDetections(newDetections);
if (onDetectionsChange) {
onDetectionsChange(newDetections);
}
}
}
setCurrentDetection(null);
setMouseDownPos(null);
setDragOffset({ x: 0, y: 0 });
setResizeData(null);
};
const handleDetectionMouseDown = (e, index) => {
e.stopPropagation();
if (!localSelectedIndices.includes(index)) {
if (!e.ctrlKey) {
const newSelectedIndices = [index];
setLocalSelectedIndices(newSelectedIndices);
onSelectionChange && onSelectionChange(newSelectedIndices);
} else {
const newSelectedIndices = [...localSelectedIndices, index];
setLocalSelectedIndices(newSelectedIndices);
onSelectionChange && onSelectionChange(newSelectedIndices);
}
}
const { x: mouseX, y: mouseY } = AnnotationService.calculateRelativeCoordinates(e, containerRef);
setDragOffset({
x: mouseX - localDetections[index].x1,
y: mouseY - localDetections[index].y1,
});
setMouseDownPos({x: mouseX, y: mouseY})
};
const handleResize = (e, index, position) => {
e.stopPropagation();
setResizeData({ index, position });
if (!localSelectedIndices.includes(index)) {
if (!e.ctrlKey) {
setLocalSelectedIndices([index]);
onSelectionChange && onSelectionChange([index]);
}
else{
const newSelectedIndices = [...localSelectedIndices, index];
setLocalSelectedIndices(newSelectedIndices);
onSelectionChange && onSelectionChange(newSelectedIndices);
}
}
};
return (
<div
style={{
position: 'relative',
width: `${width}px`,
height: `${height}px`,
pointerEvents: 'auto',
}}
>
<div ref={containerRef}
style={{
position: 'relative',
width: '100%',
height: '100%',
pointerEvents: 'auto',
}}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp}
>
{children}
<DetectionContainer
detections={localDetections}
selectedDetectionIndices={localSelectedIndices}
onDetectionMouseDown={handleDetectionMouseDown}
currentDetection={currentDetection}
onResize={handleResize}
/>
</div>
</div>
);
}
export default CanvasEditor;
+85
View File
@@ -0,0 +1,85 @@
// src/components/Detection.js
import React from 'react';
function Detection({ detection, isSelected, onDetectionMouseDown, onResize }) { // Corrected prop name
if (!detection || !detection.class) {
return null;
}
const { Color: color } = detection.class;
if (!color) {
console.error("Color is undefined for detection class:", detection.class);
return null;
}
// Use startsWith to correctly handle RGBA and hex colors
const backgroundColor = color.startsWith('rgba') ? color : color.replace('1', '0.4'); // Ensure opacity for background
const borderColor = color.startsWith('rgba') ? color.replace('0.4', '1') : color; // Ensure full opacity for border
const resizeHandleSize = 8;
const resizeHandles = [
{ position: 'top-left', cursor: 'nwse-resize', x: -resizeHandleSize, y: -resizeHandleSize, },
{ position: 'top-right', cursor: 'nesw-resize', x: detection.x2 - detection.x1 , y: -resizeHandleSize,},
{ position: 'bottom-left', cursor: 'nesw-resize', x: -resizeHandleSize, y: detection.y2 - detection.y1, },
{ position: 'bottom-right', cursor: 'nwse-resize', x: detection.x2 - detection.x1, y: detection.y2 - detection.y1 , },
{ position: 'top-middle', cursor: 'ns-resize', x: (detection.x2 - detection.x1) / 2 - resizeHandleSize / 2, y: -resizeHandleSize },
{ position: 'bottom-middle', cursor: 'ns-resize', x: (detection.x2 - detection.x1) / 2 - resizeHandleSize / 2, y: detection.y2 - detection.y1 },
{ position: 'left-middle', cursor: 'ew-resize', x: -resizeHandleSize, y: (detection.y2 - detection.y1) / 2 - resizeHandleSize / 2 },
{ position: 'right-middle', cursor: 'ew-resize', x: detection.x2 - detection.x1, y: (detection.y2 - detection.y1) / 2 - resizeHandleSize / 2 },
];
const style = {
position: 'absolute',
left: `${detection.x1}px`,
top: `${detection.y1}px`,
width: `${detection.x2 - detection.x1}px`,
height: `${detection.y2 - detection.y1}px`,
backgroundColor: backgroundColor, // Use the calculated backgroundColor
border: `2px solid ${borderColor}`, // Use the calculated borderColor
boxSizing: 'border-box',
cursor: isSelected ? 'move' : 'default',
pointerEvents: 'auto',
};
if (isSelected) {
style.border = `3px solid black`;
style.boxShadow = `0 0 4px 2px ${borderColor}`; // Use calculated border color
}
const handleMouseDown = (e) => {
e.stopPropagation();
onDetectionMouseDown(e); // Corrected prop name
};
const handleResizeMouseDown = (e, position) => {
e.stopPropagation();
e.preventDefault();
onResize(e, position);
};
return (
<div style={style} onMouseDown={handleMouseDown}>
{isSelected && resizeHandles.map((handle) => (
<div
key={handle.position}
style={{
position: 'absolute',
left: `${handle.x}px`,
top: `${handle.y}px`,
width: `${resizeHandleSize}px`,
height: `${resizeHandleSize}px`,
backgroundColor: 'black',
cursor: handle.cursor,
pointerEvents: 'auto',
}}
onMouseDown={(e) => handleResizeMouseDown(e, handle.position)}
/>
))}
<span style={{ color: 'white', fontSize: '12px', position: "absolute", top: "-18px", left: "0px" }}>{detection.class.Name}</span>
</div>
);
}
export default Detection;
+85
View File
@@ -0,0 +1,85 @@
// --- START OF FILE DetectionClassList.js --- (No changes needed)
import React, { useEffect, useState } from 'react';
import DetectionClass from '../models/DetectionClass';
function DetectionClassList({ onClassSelect }) {
const [detectionClasses, setDetectionClasses] = useState([]);
const [selectedClassId, setSelectedClassId] = useState(null); // Use an ID for selection
const colors = [ // Define colors *inside* the component
"#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF", "#000000",
"#800000", "#008000", "#000080", "#808000", "#800080", "#008080", "#808080",
"#C00000", "#00C000", "#0000C0", "#C0C000", "#C000C0", "#00C0C0", "#C0C0C0",
"#400000", "#004000", "#000040", "#404000", "#400040", "#004040", "#404040",
"#200000", "#002000", "#000020", "#202000", "#200020", "#002020", "#202020",
"#600000", "#006000", "#000060", "#606000", "#600060", "#006060", "#606060",
"#A00000", "#00A000", "#0000A0", "#A0A000", "#A000A0", "#00A0A0", "#A0A0A0",
"#E00000", "#00E000", "#0000E0", "#E0E000", "#E000E0", "#00E0E0", "#E0E0E0"
];
// Calculate color with opacity
const calculateColor = (id, opacity = '0.2') => {
const hexColor = colors[id % colors.length];
const r = parseInt(hexColor.slice(1, 3), 16);
const g = parseInt(hexColor.slice(3, 5), 16);
const b = parseInt(hexColor.slice(5, 7), 16);
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
};
useEffect(() => {
fetch('config.json') // Make sure this path is correct
.then(response => response.json())
.then(data => {
const classObjects = data.classes.map(cls => {
const color = calculateColor(cls.Id, '1'); // Full opacity for border
return new DetectionClass(cls.Id, cls.Name, color);
});
setDetectionClasses(classObjects);
if (classObjects.length > 0 && onClassSelect) {
onClassSelect(classObjects[0]); // Select the first class by default
}
})
.catch(error => console.error("Error loading detection classes:", error));
}, [onClassSelect]);
const handleClassClick = (cls) => {
setSelectedClassId(cls.Id); // Update the selected ID
onClassSelect && onClassSelect(cls);
};
return (
<div>
<h3 style={{ marginTop: '15px', fontSize: '14px' }}>Classes</h3>
<ul style={{ listStyleType: 'none', padding: 0, margin: 0 }}>
{detectionClasses.map((cls) => {
const backgroundColor = calculateColor(cls.Id); // Calculate background color (0.2 opacity)
const darkBg = calculateColor(cls.Id, '0.8'); // Calculate selected background color (0.4 opacity)
const isSelected = selectedClassId === cls.Id;
return (
<li
key={cls.Id}
style={{
cursor: 'pointer',
padding: '8px',
border: `1px solid ${isSelected ? '#000' : '#eee'}`, // Use cls.Color for the selected border
backgroundColor: isSelected ? darkBg : backgroundColor, // Conditional background
fontSize: '14px',
marginBottom: '2px',
display: 'flex',
alignItems: 'center',
borderRadius: '4px',
}}
onClick={() => handleClassClick(cls)}
>
{cls.Name}
</li>
);
})}
</ul>
</div>
);
}
export default DetectionClassList;
+30
View File
@@ -0,0 +1,30 @@
// src/components/DetectionContainer.js
import React from 'react';
import Detection from './Detection';
function DetectionContainer({ detections, selectedDetectionIndices, calculateColor, onDetectionMouseDown, currentDetection, onResize }) {
return (
<>
{detections.map((detection, index) => (
<Detection
key={index}
detection={detection}
isSelected={selectedDetectionIndices.includes(index)}
onDetectionMouseDown={(e) => onDetectionMouseDown(e, index)}
onResize={(e, position) => onResize(e, index, position)}
/>
))}
{currentDetection && (
<Detection
detection={currentDetection}
isSelected={false}
onDetectionMouseDown={() => {}} // No-op handler for the current detection
onResize={() => {}} // No-op handler for the current detection
/>
)}
</>
);
}
export default DetectionContainer;
+41
View File
@@ -0,0 +1,41 @@
import React from 'react';
import { useDropzone } from 'react-dropzone';
function MediaList({ files, selectedFile, onFileSelect, onDropNewFiles }) {
const { getRootProps, getInputProps, isDragActive } = useDropzone({
onDrop: onDropNewFiles,
});
return (
<div>
<h3 style={{ fontSize: '14px' }}>Files</h3>
<ul style={{ listStyleType: 'none', padding: 0 }}>
{files.map((file) => (
<li
key={file.name}
style={{
cursor: 'pointer',
padding: '6px',
borderBottom: '1px solid #eee',
backgroundColor: selectedFile === file ? '#f0f0f0' : 'transparent',
fontSize: '12px',
}}
onClick={() => onFileSelect(file)}
>
{file.name}
</li>
))}
</ul>
<div {...getRootProps()} style={{ border: '2px dashed #ccc', padding: '8px', textAlign: 'center', marginTop: '10px', cursor: 'pointer' }}>
<input {...getInputProps()} />
{isDragActive ? (
<p style={{ fontSize: '12px' }}>Drop here</p>
) : (
<p style={{ fontSize: '12px' }}>Drag new files</p>
)}
</div>
</div>
);
}
export default MediaList;
+48
View File
@@ -0,0 +1,48 @@
import React, {useEffect } from 'react';
function VideoPlayer({ children, videoFile, currentTime, videoRef, isPlaying }) {
useEffect(() => {
console.log("useEffect Videoplayer");
if (!(videoFile && videoRef.current))
return;
console.log("Setting video source:", videoFile);
videoRef.current.src = URL.createObjectURL(videoFile);
videoRef.current.onloadedmetadata = () => {
};
}, [videoFile]);
// useEffect(() => {
// if(videoRef.current){
// videoRef.current.currentTime = currentTime;
// }
// }, [currentTime, videoRef])
//
// useEffect(() => {
// if (videoRef.current) {
// if(isPlaying){
// videoRef.current.play()
// }
// else{
// videoRef.current.pause()
// }
// }
// }, [isPlaying, videoRef])
return (
<div style={{ position: 'relative'}}>
{/* Video Element */}
<div style={{ width: '100%', height: '100%'}}>
{children}
<video
ref={videoRef}
style={{ width: '100%', height: '100%', pointerEvents: isPlaying ? 'none' : 'auto' }}
/>
</div>
</div>
);
}
export default VideoPlayer;
+13
View File
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
+17
View File
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

+9
View File
@@ -0,0 +1,9 @@
class DetectionClass {
constructor(id, name, color) {
this.Id = id;
this.Name = name;
this.Color = color;
}
}
export default DetectionClass;
+13
View File
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
+138
View File
@@ -0,0 +1,138 @@
export const calculateRelativeCoordinates = (e, containerRef) => {
if (!containerRef.current) return { x: 0, y: 0 };
const containerRect = containerRef.current.getBoundingClientRect();
return {
x: e.clientX - containerRect.left,
y: e.clientY - containerRect.top,
};
};
export const isMouseOverDetection = (x, y, detection, containerRef) => {
if (!containerRef.current) return false;
const { x: relativeX, y: relativeY } = calculateRelativeCoordinates({ clientX: x, clientY: y }, containerRef);
return relativeX >= detection.x1 && relativeX <= detection.x2 && relativeY >= detection.y1 && relativeY <= detection.y2;
};
// Function to create an annotation image
export const createAnnotationImage = (videoRef, detections, currentDetection, selectedClass, containerRef) => {
const canvas = document.createElement('canvas');
if (!containerRef.current) return null;
const container = containerRef.current;
canvas.width = container.offsetWidth;
canvas.height = container.offsetHeight;
const ctx = canvas.getContext('2d');
ctx.drawImage(videoRef.current, 0, 0, canvas.width, canvas.height);
const defaultColor = 'rgba(0,0,0,0.4)'
detections.forEach(detection => {
const color = selectedClass && (detection.class.Id === selectedClass.Id) ? selectedClass.Color : detection.class.Color || defaultColor;
ctx.fillStyle = color.replace('1', '0.4');
ctx.fillRect(detection.x1, detection.y1, detection.x2 - detection.x1, detection.y2 - detection.y1);
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.strokeRect(detection.x1, detection.y1, detection.x2 - detection.x1, detection.y2 - detection.y1);
ctx.fillStyle = 'white';
ctx.font = '12px Arial';
ctx.fillText(detection.class.Name, detection.x1, detection.y1 - 5);
});
if (currentDetection) {
const color = selectedClass ? selectedClass.Color : defaultColor;
ctx.fillStyle = color.replace('1', '0.4');
ctx.fillRect(currentDetection.x1, currentDetection.y1, currentDetection.x2 - currentDetection.x1, currentDetection.y2 - currentDetection.y1);
ctx.strokeStyle = color; // Full opacity
ctx.lineWidth = 2;
ctx.strokeRect(currentDetection.x1, currentDetection.y1, currentDetection.x2 - currentDetection.x1, currentDetection.y2 - currentDetection.y1);
ctx.fillStyle = 'white';
ctx.font = '12px Arial';
ctx.fillText(currentDetection.class.Name, currentDetection.x1, currentDetection.y1 - 5);
}
return canvas.toDataURL('image/png');
};
export const calculateNewPosition = (mouseX, mouseY, dragOffset, detection, containerRef) => {
let newX1 = mouseX - dragOffset.x;
let newY1 = mouseY - dragOffset.y;
let newX2 = newX1 + (detection.x2 - detection.x1);
let newY2 = newY1 + (detection.y2 - detection.y1);
if (!containerRef.current) {
return { newX1, newY1, newX2, newY2 }; // Return early with unchanged values
}
let containerWidth = containerRef.current.offsetWidth;
let containerHeight = containerRef.current.offsetHeight;
if (newX1 < 0) {
newX1 = 0;
newX2 = detection.x2 - detection.x1;
}
if (newY1 < 0) {
newY1 = 0;
newY2 = detection.y2 - detection.y1;
}
if (newX2 > containerWidth) {
newX2 = containerWidth;
newX1 = newX2 - (detection.x2 - detection.x1);
}
if (newY2 > containerHeight) {
newY2 = containerHeight;
newY1 = newY2 - (detection.y2 - detection.y1);
}
return { newX1, newY1, newX2, newY2 };
};
export const calculateResizedPosition = (mouseX, mouseY, position, detection, containerRef) => {
let { x1, y1, x2, y2 } = detection;
const containerWidth = containerRef.current.offsetWidth;
const containerHeight = containerRef.current.offsetHeight;
switch (position) {
case 'top-left':
x1 = Math.min(mouseX, detection.x2 - 5);
y1 = Math.min(mouseY, detection.y2 - 5);
break;
case 'top-right':
x2 = Math.max(mouseX, detection.x1 + 5);
y1 = Math.min(mouseY, detection.y2 - 5);
break;
case 'bottom-left':
x1 = Math.min(mouseX, detection.x2 - 5);
y2 = Math.max(mouseY, detection.y1 + 5);
break;
case 'bottom-right':
x2 = Math.max(mouseX, detection.x1 + 5);
y2 = Math.max(mouseY, detection.y1 + 5);
break;
case 'top-middle':
y1 = Math.min(mouseY, detection.y2 - 5);
break;
case 'bottom-middle':
y2 = Math.max(mouseY, detection.y1 + 5);
break;
case 'left-middle':
x1 = Math.min(mouseX, detection.x2 - 5);
break;
case 'right-middle':
x2 = Math.max(mouseX, detection.x1 + 5);
break;
default:
break;
}
// Boundary checks
x1 = Math.max(0, x1);
y1 = Math.max(0, y1);
x2 = Math.min(containerWidth, x2);
y2 = Math.min(containerHeight, y2);
return { x1, y1, x2, y2 };
};
+5
View File
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
+9841
View File
File diff suppressed because it is too large Load Diff