基本的な使用方法

ビデオストリームのリアルタイム認識のサンプルについては 、 Example アプリを参照してください。

続行する前 に、「プロジェクトへの SDK の追加」および「アプリケーションの認証」で説明されている手順に従っていることを確認してください。

Linux for Live Sense SDK の最も基本的な用途は、静止画での車、歩行者、標識、その他のサポート対象物の検出です。 各モデルで検出できる内容の詳細について は、「モデル」を参照してください。

この機能は、 1 つのモデルまたは複数のモデルを実行する場合に使用できます。 このタイプの使用を有効にするには、次の手順を実行します。

// Live Sense namespace
using namespace ls;

// Initialize Live Sense SDK.
LivesenseEngine::init();

// Activate one of the below options to run the model with precision fp16 or int8.
// ENABLE ONLY 1 of fp16 or int8, or leave both false to use fp32
ModelOptions mOptions;
mOptions.setRunInFp16(true);
mOptions.setRunInInt8(true);

// Initialize options for road basics model.
RoadBasicsModelOptions roadBasicsModelOptions;

// Activate traffic light model, default is off.
roadBasicsModelOptions.runTrafficLight = false;

// Activate road basics night model, default is off.
roadBasicsModelOptions.runRoadBasicsNight = false;

//Setting the confidence threshold for individual models.
roadBasicsModelOptions.roadBasicsConfidenceThresh = 0.55;
roadBasicsModelOptions.trafficLightConfidenceThresh = 0.55;

// Initialize road basics model.
RoadBasicsModel roadBasicsModel(mOptions, roadBasicsModelOptions);

// Initialize options for road signs model.
RoadSignsModelOptions roadSignsModelOptions;
//Setting the confidence threshold for RoadSignsModel
roadSignsModelOptions.roadSignsConfidenceThresh = 0.6;
// Initialize road signs model.
RoadSignsModel roadSignsModel(mOptions, roadSignsModelOptions);

// Initialize options for road hazards model.
// Each distinct `RoadHazardsModelType` in the vector will be loaded by `RoadHazardsModel` 
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}};
// Initialize road hazards model
RoadHazardsModel roadHazardsModel(mOptions, roadHazardsModelOptions);


// Initialize options for brake light model.
BrakeLightModelOptions brakeLightModelOptions;
// Initialize brake light model.
BrakeLightModel brakeLight(mOptions, brakeLightModelOptions);

// cv::Mat `frame` is the image to process
cv::Mat frameRGB;
cv::cvtColor(frame, frameRGB, COLOR_BGR2RGB);

// The input frame is required to be of colorspace `RGB`, and be resized to
// aspect ratio expected by `recognizeImage()`. This aspect ratio is
// LivesenseModel::getInputWidth() x LivesenseModel::getInputWidth().
// OpenCV is the recommended library for such input image transformations.
// However, Live Sense also provides resize functions via ImageTransform in the
// event that OpenCV is not available.

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 = /* Resized input frame */

// Get recognitions for the road basics model. Note: the original frame is
// optional here but required if brake light and traffic signal classification
// is enabled via the above ModelOptions.
auto roadBasicsDet = roadBasicsModel.recognizeImage(resizedInput,
                                                    resizedInputWidth,
                                                    resizedInputHeight,
                                                    origWidth,
                                                    origHeight,
                                                    origInput);

// Each model may have its own input shape. For code to assist in
// managing the different input shapes, see the example applications
// provided alongside the SDK.
resizedInputWidth = roadSignsModel.getInputWidth();
resizedInputHeight = roadSignsModel.getInputHeight();
numChannels = roadSignsModel.getInputDepth();
resizedInput = /* Resized input frame */

// Get recognitions for the road signs model. Note: the original frame is
// required for proper and accurate sign classification.
auto roadSignsDet = roadSignsModel.recognizeImage(resizedInput,
                                                  resizedInputWidth,
                                                  resizedInputHeight,
                                                  origWidth,
                                                  origHeight,
                                                  origInput);

// Get shape for the next model and resize frame
resizedInputWidth = roadHazardsModel.getInputWidth();
resizedInputHeight = roadHazardsModel.getInputHeight();
numChannels = roadHazardsModel.getInputDepth();
resizedInput = /* Resized input frame */

// Get recognitions for the road hazards model. Note: the original
// frame is not passed in as no classifications are executed.
auto roadHazardsDet = roadHazardsModel.recognizeImage(resizedInput,
                                                      resizedInputWidth,
                                                      resizedInputHeight,
                                                      origWidth,
                                                      origHeight);

// Get shape for the next model and resize frame
resizedInputWidth = brakeLight.getInputWidth();
resizedInputHeight = brakeLight.getInputHeight();
numChannels = brakeLight.getInputDepth();
resizedInput = /* Resized input frame */

// Get recognitions for the brake light model. Note again the original
// frame is not passed in as no classifications are executed.
auto brakeLightDet = brakeLight.recognizeImage(resizedInput,
                                               resizedInputWidth,
                                               resizedInputHeight,
                                               origWidth,
                                               origHeight);

アプリケーションで Live Sense SDK for Linux を使用する場合の推奨事項については 、「推奨事項」を参照してください

」に一致する結果は 件です

    」に一致する結果はありません