Basic usage
Note
For a complete sample of real-time recognition of a video stream, see example app.
Before proceeding, make sure you have followed the steps described in Add SDK to a Project and Authenticating Applications.
The most basic use of Live Sense SDK for Linux includes the detection of cars, pedestrians, signs, and other supported objects in a still image. For details on what can be detected by each model, see Models.
This feature can be used for running a single model or multiple models. To enable this type of usage, do the following:
using namespace ls;
LivesenseEngine::init();
ModelOptions mOptions;
mOptions.setRunInFp16(true);
mOptions.setRunInInt8(true);
RoadBasicsModelOptions roadBasicsModelOptions;
roadBasicsModelOptions.runTrafficLight = false;
roadBasicsModelOptions.runRoadBasicsNight = false;
roadBasicsModelOptions.roadBasicsConfidenceThresh = 0.55;
roadBasicsModelOptions.trafficLightConfidenceThresh = 0.55;
RoadBasicsModel roadBasicsModel(mOptions, roadBasicsModelOptions);
RoadSignsModelOptions roadSignsModelOptions;
roadSignsModelOptions.roadSignsConfidenceThresh = 0.6;
RoadSignsModel roadSignsModel(mOptions, roadSignsModelOptions);
std::vector<ls::RoadHazardsModelOptions> roadHazardsModelOptions = {
{ls::RoadHazardsModelType::RH_CONE_CONSTRUCTION, 0.6},
{ls::RoadHazardsModelType::RH_POTHOLES, 0.6},
{ls::RoadHazardsModelType::RH_SPEED_BUMP_OBJECT, 0.55},
{ls::RoadHazardsModelType::RH_SPEED_BUMP_SIGNAGE, 0.55},
{ls::RoadHazardsModelType::RH_BRIDGE_TUNNEL, 0.75},
{ls::RoadHazardsModelType::RH_HEIGHT_RESTRICTION_SIGNS, 0.6}};
RoadHazardsModel roadHazardsModel(mOptions, roadHazardsModelOptions);
BrakeLightModelOptions brakeLightModelOptions;
BrakeLightModel brakeLight(mOptions, brakeLightModelOptions);
cv::Mat frameRGB;
cv::cvtColor(frame, frameRGB, COLOR_BGR2RGB);
unsigned char* origInput = &frameRGB.data[0];
int origWidth = frameRGB.cols;
int origHeight = frameRGB.rows;
int resizedInputWidth = roadBasicsModel.getInputWidth();
int resizedInputHeight = roadBasicsModel.getInputHeight();
int numChannels = roadBasicsModel.getInputDepth();
unsigned char* resizedInput =
auto roadBasicsDet = roadBasicsModel.recognizeImage(resizedInput,
resizedInputWidth,
resizedInputHeight,
origWidth,
origHeight,
origInput);
resizedInputWidth = roadSignsModel.getInputWidth();
resizedInputHeight = roadSignsModel.getInputHeight();
numChannels = roadSignsModel.getInputDepth();
resizedInput =
auto roadSignsDet = roadSignsModel.recognizeImage(resizedInput,
resizedInputWidth,
resizedInputHeight,
origWidth,
origHeight,
origInput);
resizedInputWidth = roadHazardsModel.getInputWidth();
resizedInputHeight = roadHazardsModel.getInputHeight();
numChannels = roadHazardsModel.getInputDepth();
resizedInput =
auto roadHazardsDet = roadHazardsModel.recognizeImage(resizedInput,
resizedInputWidth,
resizedInputHeight,
origWidth,
origHeight);
resizedInputWidth = brakeLight.getInputWidth();
resizedInputHeight = brakeLight.getInputHeight();
numChannels = brakeLight.getInputDepth();
resizedInput =
auto brakeLightDet = brakeLight.recognizeImage(resizedInput,
resizedInputWidth,
resizedInputHeight,
origWidth,
origHeight);
For recommendations on using the Live Sense SDK for Linux in your application, see Recommendations