Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use the new detectNet::Detection class from jetson_inference #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,44 @@ target_link_libraries(ros_deep_learning_nodelets ${catkin_LIBRARIES} jetson-infe
# add_dependencies(ros_deep_learning_nodelets ${catkin_EXPORTED_LIBRARIES})
#endif()

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables and/or libraries for installation
# install(TARGETS image_to_rtsp image_to_rtsp_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
FILES_MATCHING PATTERN "*.launch"
)

install(FILES ros_deep_learning_nodelets.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(DIRECTORY config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
26 changes: 8 additions & 18 deletions src/node_detectnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ imageConverter* cvt = NULL;
uint32_t objClasses = 0;
uint32_t maxBoxes = 0;

float* bbCPU = NULL;
float* bbGPU = NULL;
float* confCPU = NULL;
float* confGPU = NULL;
detectNet::Detection* detections = NULL;

ros::Publisher* detection_pub = NULL;

Expand All @@ -70,11 +67,10 @@ void img_callback( const sensor_msgs::ImageConstPtr& input )
}

// classify the image
int numBoundingBoxes = maxBoxes;
const bool result = net->Detect(cvt->ImageGPU(), cvt->GetWidth(), cvt->GetHeight(), bbCPU, &numBoundingBoxes, confCPU);
int numBoundingBoxes = net->Detect(cvt->ImageGPU(), cvt->GetWidth(), cvt->GetHeight(), detections, 0);

// verify success
if( !result )
if( numBoundingBoxes < 0 )
{
ROS_ERROR("failed to run detection on %ux%u image", input->width, input->height);
return;
Expand All @@ -91,11 +87,11 @@ void img_callback( const sensor_msgs::ImageConstPtr& input )
for( int n=0; n < numBoundingBoxes; n++ )
{
// extract class/confidence pairs
const float obj_conf = confCPU[n*2];
const int obj_class = confCPU[n*2+1];
const float obj_conf = detections[n].Confidence;
const int obj_class = detections[n].ClassID;

// extract the bounding box
float* bb = bbCPU + (n * 4);
float bb[4] = {detections[n].Left, detections[n].Top, detections[n].Right, detections[n].Bottom};

const float bbWidth = bb[2] - bb[0];
const float bbHeight = bb[3] - bb[1];
Expand Down Expand Up @@ -202,18 +198,12 @@ int main(int argc, char **argv)
* alloc memory for bounding box & confidence value outputs
*/
objClasses = net->GetNumClasses();
maxBoxes = net->GetMaxBoundingBoxes();
maxBoxes = net->GetMaxDetections();

ROS_INFO("object classes: %u", objClasses);
ROS_INFO("maximum bounding boxes: %u\n", maxBoxes);

if( !cudaAllocMapped((void**)&bbCPU, (void**)&bbGPU, maxBoxes * sizeof(float) * 4) ||
!cudaAllocMapped((void**)&confCPU, (void**)&confGPU, maxBoxes * objClasses * sizeof(float)) )
{
ROS_ERROR("detectnet: failed to alloc bounding box output memory");
return 0;
}

detections = new detectNet::Detection [maxBoxes];

/*
* create the class labels parameter vector
Expand Down