1 Star 0 Fork 2

Admin/github-dusty-nv-jetson-inference

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
detectnet.cpp 4.82 KB
一键复制 编辑 原始数据 按行查看 历史
Dustin Franklin 提交于 5年前 . updated EOS logging
/*
* Copyright (c) 2020, 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 "videoSource.h"
#include "videoOutput.h"
#include "detectNet.h"
#include <signal.h>
#ifdef HEADLESS
#define IS_HEADLESS() "headless" // run without display
#else
#define IS_HEADLESS() (const char*)NULL
#endif
bool signal_recieved = false;
void sig_handler(int signo)
{
if( signo == SIGINT )
{
LogVerbose("received SIGINT\n");
signal_recieved = true;
}
}
int usage()
{
printf("usage: detectnet [--help] [--network=NETWORK] [--threshold=THRESHOLD] ...\n");
printf(" input_URI [output_URI]\n\n");
printf("Locate objects in a video/image stream using an object detection DNN.\n");
printf("See below for additional arguments that may not be shown above.\n\n");
printf("positional arguments:\n");
printf(" input_URI resource URI of input stream (see videoSource below)\n");
printf(" output_URI resource URI of output stream (see videoOutput below)\n\n");
printf("%s", detectNet::Usage());
printf("%s", videoSource::Usage());
printf("%s", videoOutput::Usage());
printf("%s", Log::Usage());
return 0;
}
int main( int argc, char** argv )
{
/*
* parse command line
*/
commandLine cmdLine(argc, argv, IS_HEADLESS());
if( cmdLine.GetFlag("help") )
return usage();
/*
* attach signal handler
*/
if( signal(SIGINT, sig_handler) == SIG_ERR )
LogError("can't catch SIGINT\n");
/*
* create input stream
*/
videoSource* input = videoSource::Create(cmdLine, ARG_POSITION(0));
if( !input )
{
LogError("detectnet: failed to create input stream\n");
return 0;
}
/*
* create output stream
*/
videoOutput* output = videoOutput::Create(cmdLine, ARG_POSITION(1));
if( !output )
LogError("detectnet: failed to create output stream\n");
/*
* create detection network
*/
detectNet* net = detectNet::Create(cmdLine);
if( !net )
{
LogError("detectnet: failed to load detectNet model\n");
return 0;
}
// parse overlay flags
const uint32_t overlayFlags = detectNet::OverlayFlagsFromStr(cmdLine.GetString("overlay", "box,labels,conf"));
/*
* processing loop
*/
while( !signal_recieved )
{
// capture next image image
uchar3* image = NULL;
if( !input->Capture(&image, 1000) )
{
// check for EOS
if( !input->IsStreaming() )
break;
LogError("detectnet: failed to capture video frame\n");
continue;
}
// detect objects in the frame
detectNet::Detection* detections = NULL;
const int numDetections = net->Detect(image, input->GetWidth(), input->GetHeight(), &detections, overlayFlags);
if( numDetections > 0 )
{
LogVerbose("%i objects detected\n", numDetections);
for( int n=0; n < numDetections; n++ )
{
LogVerbose("detected obj %i class #%u (%s) confidence=%f\n", n, detections[n].ClassID, net->GetClassDesc(detections[n].ClassID), detections[n].Confidence);
LogVerbose("bounding box %i (%f, %f) (%f, %f) w=%f h=%f\n", n, detections[n].Left, detections[n].Top, detections[n].Right, detections[n].Bottom, detections[n].Width(), detections[n].Height());
}
}
// render outputs
if( output != NULL )
{
output->Render(image, input->GetWidth(), input->GetHeight());
// update the status bar
char str[256];
sprintf(str, "TensorRT %i.%i.%i | %s | Network %.0f FPS", NV_TENSORRT_MAJOR, NV_TENSORRT_MINOR, NV_TENSORRT_PATCH, precisionTypeToStr(net->GetPrecision()), net->GetNetworkFPS());
output->SetStatus(str);
// check if the user quit
if( !output->IsStreaming() )
signal_recieved = true;
}
// print out timing info
net->PrintProfilerTimes();
}
/*
* destroy resources
*/
LogVerbose("detectnet: shutting down...\n");
SAFE_DELETE(input);
SAFE_DELETE(output);
SAFE_DELETE(net);
LogVerbose("detectnet: shutdown complete.\n");
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leetoptech_wenjoyu/jetson-inference.git
git@gitee.com:leetoptech_wenjoyu/jetson-inference.git
leetoptech_wenjoyu
jetson-inference
github-dusty-nv-jetson-inference
master

搜索帮助