Hi,
I was able to pull the dev branch of the jetson-interface repo build and deploy using the standard detectnet-camera model.
I had to add “static” to the create methods of the gstENcoder.h file otherwise I would receive the error " “cannot call gstEncoder function without object”.
I then went into the Camera.cpp to attempt to initialize the gstEncode as follows:
/*
* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "gstCamera.h"
#include "glDisplay.h"
#include "glTexture.h"
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "cudaMappedMemory.h"
#include "cudaNormalize.h"
#include "cudaFont.h"
#include "detectNet.h"
#include "gstEncoder.h"
#include "gstUtility.h"
#define DEFAULT_CAMERA 1 // -1 for onboard camera, or change to index of /dev/video V4L2 camera (>=0)
bool signal_recieved = false;
void sig_handler(int signo)
{
if( signo == SIGINT )
{
printf("received SIGINT\n");
signal_recieved = true;
}
}
int main( int argc, char** argv )
{
printf("detectnet-camera\n args (%i): ", argc);
for( int i=0; i < argc; i++ )
printf("%i [%s] ", i, argv[i]);
printf("\n\n");
/*
* parse network type from CLI arguments
*/
/*detectNet::NetworkType networkType = detectNet::PEDNET_MULTI;
if( argc > 1 )
{
if( strcmp(argv[1], "multiped") == 0 || strcmp(argv[1], "pednet") == 0 || strcmp(argv[1], "multiped-500") == 0 )
networkType = detectNet::PEDNET_MULTI;
else if( strcmp(argv[1], "ped-100") == 0 )
networkType = detectNet::PEDNET;
else if( strcmp(argv[1], "facenet") == 0 || strcmp(argv[1], "facenet-120") == 0 || strcmp(argv[1], "face-120") == 0 )
networkType = detectNet::FACENET;
}*/
if( signal(SIGINT, sig_handler) == SIG_ERR )
printf("\ncan't catch SIGINT\n");
/*
* create the camera device
*/
gstCamera* camera = gstCamera::Create(DEFAULT_CAMERA);
gstEncoder* enc = gstEncoder::Create(GST_CODEC_H264,1280,720,"192.168.108.163",8080);
if( !camera )
{
printf("\ndetectnet-camera: failed to initialize video device\n");
return 0;
}
printf("\ndetectnet-camera: successfully initialized video device\n");
printf(" width: %u\n", camera->GetWidth());
printf(" height: %u\n", camera->GetHeight());
printf(" depth: %u (bpp)\n\n", camera->GetPixelDepth());
/*
* create detectNet
*/
detectNet* net = detectNet::Create(argc, argv);
if( !net )
{
printf("detectnet-camera: failed to initialize imageNet\n");
return 0;
}
/*
* allocate memory for output bounding boxes and class confidence
*/
const uint32_t maxBoxes = net->GetMaxBoundingBoxes(); printf("maximum bounding boxes: %u\n", maxBoxes);
const uint32_t classes = net->GetNumClasses();
float* bbCPU = NULL;
float* bbCUDA = NULL;
float* confCPU = NULL;
float* confCUDA = NULL;
if( !cudaAllocMapped((void**)&bbCPU, (void**)&bbCUDA, maxBoxes * sizeof(float4)) ||
!cudaAllocMapped((void**)&confCPU, (void**)&confCUDA, maxBoxes * classes * sizeof(float)) )
{
printf("detectnet-console: failed to alloc output memory\n");
return 0;
}
/*
* create openGL window
*/
glDisplay* display = glDisplay::Create();
glTexture* texture = NULL;
if( !display ) {
printf("\ndetectnet-camera: failed to create openGL display\n");
}
else
{
texture = glTexture::Create(camera->GetWidth(), camera->GetHeight(), GL_RGBA32F_ARB/*GL_RGBA8*/);
if( !texture )
printf("detectnet-camera: failed to create openGL texture\n");
}
/*
* create font
*/
cudaFont* font = cudaFont::Create();
/*
* start streaming
*/
if( !camera->Open() )
{
printf("\ndetectnet-camera: failed to open camera for streaming\n");
return 0;
}
printf("\ndetectnet-camera: camera open for streaming\n");
//const size_t texSz = camera->GetWidth() * camera->GetHeight() * 3 / 2;
/*
* processing loop
*/
float confidence = 0.0f;
while( !signal_recieved )
{
void* imgCPU = NULL;
void* imgCUDA = NULL;
// get the latest frame
if( !camera->Capture(&imgCPU, &imgCUDA, 1000) )
printf("\ndetectnet-camera: failed to capture frame\n");
// convert from YUV to RGBA
void* imgRGBA = NULL;
if( !camera->ConvertRGBA(imgCUDA, &imgRGBA) )
printf("detectnet-camera: failed to convert from NV12 to RGBA\n");
// classify image with detectNet
int numBoundingBoxes = maxBoxes;
if( net->Detect((float*)imgRGBA, camera->GetWidth(), camera->GetHeight(), bbCPU, &numBoundingBoxes, confCPU))
{
printf("%i bounding boxes detected\n", numBoundingBoxes);
int lastClass = 0;
int lastStart = 0;
for( int n=0; n < numBoundingBoxes; n++ )
{
const int nc = confCPU[n*2+1];
float* bb = bbCPU + (n * 4);
printf("bounding box %i (%f, %f) (%f, %f) w=%f h=%f\n", n, bb[0], bb[1], bb[2], bb[3], bb[2] - bb[0], bb[3] - bb[1]);
if( nc != lastClass || n == (numBoundingBoxes - 1) )
{
if( !net->DrawBoxes((float*)imgRGBA, (float*)imgRGBA, camera->GetWidth(), camera->GetHeight(),
bbCUDA + (lastStart * 4), (n - lastStart) + 1, lastClass) )
printf("detectnet-console: failed to draw boxes\n");
lastClass = nc;
lastStart = n;
CUDA(cudaDeviceSynchronize());
}
}
/*if( font != NULL )
{
char str[256];
sprintf(str, "%05.2f%% %s", confidence * 100.0f, net->GetClassDesc(img_class));
font->RenderOverlay((float4*)imgRGBA, (float4*)imgRGBA, camera->GetWidth(), camera->GetHeight(),
str, 10, 10, make_float4(255.0f, 255.0f, 255.0f, 255.0f));
}*/
if( display != NULL )
{
char str[256];
sprintf(str, "TensorRT %i.%i.%i | %s | %04.1f FPS", NV_TENSORRT_MAJOR, NV_TENSORRT_MINOR, NV_TENSORRT_PATCH, precisionTypeToStr(net->GetPrecision()), display->GetFPS());
display->SetTitle(str);
}
}
// update display
if( display != NULL )
{
//enc->EncodeFrame((float4*)imgRGBA,texSz);
display->UserEvents();
display->BeginRender();
if( texture != NULL )
{
// rescale image pixel intensities for display
CUDA(cudaNormalizeRGBA((float4*)imgRGBA, make_float2(0.0f, 255.0f),
(float4*)imgRGBA, make_float2(0.0f, 1.0f),
camera->GetWidth(), camera->GetHeight()));
// map from CUDA to openGL using GL interop
void* tex_map = texture->MapCUDA();
if( tex_map != NULL )
{
cudaMemcpy(tex_map, imgRGBA, texture->GetSize(), cudaMemcpyDeviceToDevice);
texture->Unmap();
}
// draw the texture
texture->Render(100,100);
}
display->EndRender();
}
}
printf("\ndetectnet-camera: un-initializing video device\n");
/*
* shutdown the camera device
*/
if( camera != NULL )
{
delete camera;
camera = NULL;
}
if( display != NULL )
{
delete display;
display = NULL;
}
printf("detectnet-camera: video device has been un-initialized.\n");
printf("detectnet-camera: this concludes the test of the video device.\n");
return 0;
}
I essentially added “gstEncoder* enc = gstEncoder::Create(GST_CODEC_H264,1280,720,“192.168.108.163”,8080);” as a test.
I was then able to rebuild the project. However when I try and run ./detectnet-camera I get an error in the terminal “Segmentation fault (core dumped)”
What could be causing this? A quick google states that it is trying to access memory it does not have memory to. But I am not sure why this is happening.
Thanks