Skip to content

Commit

Permalink
Reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong1120 committed Aug 9, 2024
1 parent 47677e4 commit e20f031
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
31 changes: 22 additions & 9 deletions examples/YOLOv8_server_api/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ def find_overlapping_indices(index1, indices2, datas, threshold):
Returns:
set: Indices of overlapping labels to remove.
"""
to_remove = set()
for index2 in indices2:
if calculate_overlap(datas[index1][:4], datas[index2][:4]) > threshold:
to_remove.add(index2)
return to_remove
return {index2 for index2 in indices2 if calculate_overlap(datas[index1][:4], datas[index2][:4]) > threshold}


def calculate_overlap(bbox1, bbox2):
Expand Down Expand Up @@ -313,8 +309,25 @@ def find_contained_indices(index1, indices2, datas):
"""
to_remove = set()
for index2 in indices2:
if is_contained(datas[index2][:4], datas[index1][:4]):
to_remove.add(index2)
elif is_contained(datas[index1][:4], datas[index2][:4]):
to_remove.add(index1)
to_remove.update(check_containment(index1, index2, datas))
return to_remove


def check_containment(index1, index2, datas):
"""
Check if one bounding box is contained within another.
Args:
index1 (int): The first index.
index2 (int): The second index.
datas (list): Detection data.
Returns:
set: Indices of contained labels to remove.
"""
to_remove = set()
if is_contained(datas[index2][:4], datas[index1][:4]):
to_remove.add(index2)
elif is_contained(datas[index1][:4], datas[index2][:4]):
to_remove.add(index1)
return to_remove
7 changes: 6 additions & 1 deletion examples/streaming_web/static/js/label.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
$(document).ready(() => {
// Automatically detect the current page protocol to decide between ws and wss
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
// Ensure io is defined
if (typeof io === 'undefined') {
console.error('Socket.IO is not defined. Please ensure it is included in your HTML.');
return;
}
// Create WebSocket connection and configure reconnection strategy
const socket = io.connect(protocol + document.domain + ':' + location.port, {
transports: ['websocket'],
Expand Down Expand Up @@ -82,7 +87,7 @@ function createCameraDiv({ image, imageName, label }) {
* @param {...any} messages - The messages to log
*/
function debugLog(...messages) {
if (process.env.NODE_ENV === 'development') {
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development') {
console.log(...messages);
}
}

0 comments on commit e20f031

Please sign in to comment.