How do I draw my own boxes on webcam frames?

I’ve successfully trained a custom model and integrated it into the detectnet-camera project (https://github.com/dusty-nv/jetson-inference/tree/master/detectnet-camera)

I am now trying to add “custom” boxes to the camera frames in addition to the bounding boxes from the model inferencing, but my custom boxes are not showing up.

Below is a list of modifications I made to accomplish my desired goal. What am I missing? Thanks!

In detectnet-camera.cpp:

float* targetBoxColorCPU = NULL;
float* targetBoxColorCUDA = NULL;

if( !cudaAllocMapped((void**)&targetBoxCPU, (void**)&targetBoxCUDA, sizeof(float4)) ||
    !cudaAllocMapped((void**)&targetBoxColorCPU, (void**)&targetBoxColorCUDA, sizeof(float4)) )
{
    printf("detectnet-console:  failed to alloc output memory\n");
    return 0;
}

//
// after net->Detect(...) if  block
//

targetBoxCPU[0] = 410.0f;
targetBoxCPU[1] = 60.0f;
targetBoxCPU[2] = 1000.0f;
targetBoxCPU[3] = 530.0f;
targetBoxColorCPU[0] = 250.0f;
targetBoxColorCPU[1] = 0.0f;
targetBoxColorCPU[2] = 0.0f;
targetBoxColorCPU[3] = 100.0f;
if( !net->DrawTargetBox((float*)imgRGBA, (float*)imgRGBA, camera->GetWidth(), camera->GetHeight(), targetBoxCUDA, targetBoxColorCUDA, 1) )
    printf("detect-console: failed to draw target boxes\n");

CUDA(cudaDeviceSynchronize());

in detectNet.cpp

// DrawTargetBox
bool detectNet::DrawTargetBox( float* input, float* output, uint32_t width, uint32_t height, const float* targetBoxes, const float* targetBoxColor, int numBoxes)
{
        if( !input || !output || width == 0 || height == 0 || !targetBoxes || !targetBoxColor || numBoxes < 1)
                return false;

        if( CUDA_FAILED(cudaRectOutlineOverlay((float4*)input, (float4*)output, width, height, (float4*)targetBoxes, numBoxes, (float&)targetBoxColor)) )
                return false;

        return true;
}

Hi,

It’s recommended to check the output behavior from here first:
[url]https://github.com/dusty-nv/jetson-inference/blob/master/detectNet.cpp#L558[/url]

Please check if the bounding box and confidence is as expected.
Thanks.

Hi AastaLLL,

I don’t have an issue with the model inference outputs. I would like to output my own rectangle with coordinates of my own choosing, similar to the call here (https://github.com/dusty-nv/jetson-inference/blob/bda3d60a6967d5c081162a940f0bbca399081a55/detectnet-camera/detectnet-camera.cpp#L207) but replacing the parameter “bbCUDA” with my own.

Something like this:

net->DrawBoxes((float*)imgRGBA, (float*)imgRGBA, camera->GetWidth(), camera->GetHeight(), myCustomRectangleCUDA, 1, 0)

Hi,

Could you try to add a synchronization call after assigning data with CPU to see if helps?

...
targetBoxColorCPU[3] = 100.0f;
<b>CUDA(cudaThreadSynchronize());</b>
if( !net->DrawTargetBox((float*)imgRGBA, (float*)imgRGBA, camera->GetWidth(), camera->GetHeight(), targetBoxCUDA, targetBoxColorCUDA, 1) )
    printf("detect-console: failed to draw target boxes\n");
...

Thanks.