Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ qtcreator-*
# Emacs
.#*

# Python cache
__pycache__/

# Catkin custom files
CATKIN_IGNORE

Expand Down
176 changes: 176 additions & 0 deletions nuclio_function/CVAT_INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# CVAT Integration Example

This document provides an example of how to integrate the AOC Fruit Detector nuclio function with CVAT.

## Prerequisites

1. CVAT is installed and running
2. Nuclio is installed in your Kubernetes cluster or Docker environment
3. AOC Fruit Detector nuclio function is deployed

## Step 1: Deploy the Function

```bash
cd nuclio_function
./deploy.sh
```

Note the function endpoint URL from the deployment output.

## Step 2: Configure CVAT Model

1. **Access CVAT Admin Interface**
- Go to CVAT admin panel (usually at `http://your-cvat-url/admin`)
- Login with admin credentials

2. **Add New Model**
- Navigate to `Models` → `Add Model`
- Fill in the following details:

```
Name: AOC Fruit Detector
Owner: <your-username>
URL: http://<nuclio-function-endpoint>
Labels: strawberry,tomato,apple,pear
Model type: Detector
Storage method: Local
Enabled: ✓
```

3. **Configure Labels**
Create labels that match your fruit detection types:
```
- strawberry
- strawberry_ripe
- strawberry_unripe
- strawberry_overripe
- tomato
- tomato_ripe
- tomato_unripe
- tomato_overripe
```

## Step 3: Use in CVAT Tasks

1. **Create or Open Task**
- Create a new task or open an existing one
- Upload images containing fruits

2. **Run Automatic Annotation**
- Go to `Actions` → `Automatic Annotation`
- Select "AOC Fruit Detector" from the model dropdown
- Configure parameters:
```
Threshold: 0.5 (adjust based on your needs)
Maximum annotations per frame: 100
```
- Click "Submit"

3. **Review Results**
- The function will process each frame
- Review and adjust annotations as needed
- Use CVAT's annotation tools to refine results

## Example API Request

For direct testing, you can send requests to the nuclio function:

```bash
# Test with a sample image
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"image": "'$(base64 -w 0 /path/to/fruit_image.jpg)'",
"threshold": 0.5
}' \
http://<nuclio-function-endpoint>
```

Expected response:
```json
[
{
"confidence": 0.95,
"label": "strawberry_ripe",
"points": [123.4, 56.7, 234.5, 167.8],
"type": "rectangle",
"attributes": {
"variety": "unknown",
"quality": "High",
"ripeness_category": "Ripe",
"ripeness_level": 0.85
}
}
]
```

## Troubleshooting

### Common Issues

1. **Function Not Responding**
- Check if nuclio function is running: `nuctl get functions`
- Check function logs: `nuctl logs aoc-fruit-detector`

2. **No Detections Returned**
- Lower the confidence threshold
- Check if fruit detector ROS2 node is running
- Verify ROS2 domain configuration

3. **CVAT Integration Issues**
- Ensure function URL is accessible from CVAT
- Check CVAT logs for error messages
- Verify model configuration in CVAT admin panel

### Performance Tuning

1. **Confidence Threshold**
- Start with 0.5 and adjust based on results
- Lower values will detect more objects but may include false positives

2. **Function Resources**
- Adjust CPU/memory limits in `function.yaml`
- Scale replicas based on load requirements

3. **Timeout Settings**
- Increase timeout in ROS2 bridge if processing is slow
- Configure CVAT model timeout appropriately

## Advanced Configuration

### Custom Labels

To add custom fruit types or ripeness categories:

1. **Update the converter**
Edit `cvat_converter.py` to add new fruit type mappings:
```python
self.fruit_type_mapping = {
'strawberry': 'strawberry',
'tomato': 'tomato',
'apple': 'apple', # Add new types
'pear': 'pear',
# ... more types
}
```

2. **Rebuild and redeploy**
```bash
docker build -t aoc-fruit-detector:latest .
nuctl deploy aoc-fruit-detector --run-image aoc-fruit-detector:latest
```

3. **Update CVAT labels**
Add corresponding labels in CVAT model configuration

### Multi-Model Setup

You can deploy multiple versions of the function for different use cases:

```bash
# Deploy for strawberries only
nuctl deploy aoc-strawberry-detector --env FRUIT_TYPE=strawberry

# Deploy for tomatoes only
nuctl deploy aoc-tomato-detector --env FRUIT_TYPE=tomato
```
61 changes: 61 additions & 0 deletions nuclio_function/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Dockerfile for nuclio function deployment
FROM ros:humble-base

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV ROS_DISTRO=humble
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
python3-pip \
python3-dev \
python3-opencv \
python3-numpy \
python3-pil \
python3-colcon-common-extensions \
ros-humble-cv-bridge \
ros-humble-sensor-msgs \
ros-humble-geometry-msgs \
ros-humble-std-msgs \
ros-humble-visualization-msgs \
&& rm -rf /var/lib/apt/lists/*

# Create workspace for AOC messages
WORKDIR /opt/ros_ws
RUN mkdir -p src/aoc_fruit_detector

# Copy package files for building messages
COPY ../CMakeLists.txt src/aoc_fruit_detector/
COPY ../package.xml src/aoc_fruit_detector/
COPY ../msg src/aoc_fruit_detector/msg/

# Build the AOC message package
RUN bash -c "source /opt/ros/humble/setup.bash && colcon build --packages-select aoc_fruit_detector"

# Set working directory for function
WORKDIR /opt/nuclio

# Copy function files
COPY main.py .
COPY ros2_bridge.py .
COPY cvat_converter.py .
COPY requirements.txt .

# Install Python dependencies
RUN pip3 install --no-cache-dir -r requirements.txt

# Set up environment for ROS2
ENV ROS_DOMAIN_ID=0
ENV RMW_IMPLEMENTATION=rmw_cyclonedx_cpp
ENV PYTHONPATH="/opt/ros_ws/install/aoc_fruit_detector/lib/python3.10/site-packages:${PYTHONPATH}"

# Source both ROS2 and AOC messages setup
RUN echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc && \
echo "source /opt/ros_ws/install/setup.bash" >> ~/.bashrc

# Expose port for nuclio
EXPOSE 8080

# Set entrypoint
CMD ["/bin/bash", "-c", "source /opt/ros/humble/setup.bash && source /opt/ros_ws/install/setup.bash && python3 main.py"]
Loading
Loading