chore: video section issues
This commit is contained in:
@@ -69,18 +69,22 @@ export const useFrameDetectionMap = (data: DetectionData, detectionType: string)
|
||||
return map;
|
||||
}, [data, detectionType]);
|
||||
|
||||
const getNearestDetections = (frame: number, sortedFrameIndices: number[], maxSkip = 3) => {
|
||||
const sortedDetectionIndices = useMemo(() => {
|
||||
return Array.from(frameDetectionMap.keys()).sort((a, b) => a - b);
|
||||
}, [frameDetectionMap]);
|
||||
|
||||
const getNearestDetections = (frame: number, sortedIndices: number[], maxSkip = 3) => {
|
||||
const exact = frameDetectionMap.get(frame);
|
||||
if (exact) return exact;
|
||||
|
||||
let low = 0,
|
||||
high = sortedFrameIndices.length - 1,
|
||||
high = sortedIndices.length - 1,
|
||||
targetIndex = -1;
|
||||
|
||||
while (low <= high) {
|
||||
const mid = Math.floor((low + high) / 2);
|
||||
if (sortedFrameIndices[mid] <= frame) {
|
||||
targetIndex = sortedFrameIndices[mid];
|
||||
if (sortedIndices[mid] <= frame) {
|
||||
targetIndex = sortedIndices[mid];
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
@@ -92,5 +96,5 @@ export const useFrameDetectionMap = (data: DetectionData, detectionType: string)
|
||||
: undefined;
|
||||
};
|
||||
|
||||
return { frameDetectionMap, getNearestDetections };
|
||||
return { frameDetectionMap, getNearestDetections, sortedDetectionIndices };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user