🌐 한국어

    모션 감지 API#

    헤더 파일#

    OasisMotion.h

    MotionDetectObserver 인터페이스#

    class MotionDetectObserver : public std::enable_shared_from_this<MotionDetectObserver>
    {
    public:
        MotionDetectObserver();
        virtual ~MotionDetectObserver();
    
        virtual void onMotionDetected(int32_t camera_id, int32_t detected);
    };
    
    
    void onMotionDetected ( int32_t camera_id , int32_t detected )
    OasisMotion.h
    움직임이 감지 되었을 때 호출됩니다.
    매개변수
    camera_id  createMotionDetector 호출 시 key-value map 매개변수로 전달 된 카메라 ID 입니다.
    detected  움직감 감지 강도입니다.

    함수#

    MotionDetectorRef createMotionDetector ( const MediaSourceRef & source , key_value_map_t & parameters )
    OasisMotion.h
    모션 감지기를 생성합니다.
    매개변수
    source  모션 감지의 영상 소스 입니다. Camera나 미디어 플레이어의 playerGetVideoTrackSource 등 영상을 제공하는 MediaSource가 될 수 있습니다.
    parameters  모션 감지에 필요한 key-value map 매개변수입니다.
    리턴값
    성공하면 MotionDetector 객체를 리턴합니다. 실패하면 nullptr을 리턴합니다.

    모션 감지에 필요한 key-value map은 아래와 같습니다.

    기본값
    필수
    설명
    camera-id
     
    configCameras에서 설정한 카메라 장치 ID 입니다.
    track-id
     
    재생일 경우, source는 track-id에 해당하는 MediaSource입니다.
    enable
     
    "1"이면 모션 감지를 활성화 합니다. "0"이면 모션 감지를 비활성화합니다.
    fps
    6
     
    모션 감지용 fps입니다. CPU 부하에 따라 적정한 값을 지정합니다.
    use-g2d
    0
     
    "1"이면 칩셋의 하드웨어 가속 스케일링을 사용합니다. "0" 이면 SIMD 소프트웨어 스케일링을 사용합니다. 소프트웨어 스케일링은 최대 4배로 축소할 수 있습니다. 4배 초과하여 스케일링을 할 경우, 하드웨어 가속이 필요합니다.
    sensitivity-level
    5
     
    모션 감지 민감도를 설정합니다. 1~6 사이 값을 사용합니다. (사용하지 않습니다)
    version
    2
     
    모션 감지에 쓰일 엔진 버전을 선택합니다. 1또는 2값을 사용하며, 2값이 최신 버전입니다.
    threshold
    0
    모션 발생을 판단하는 최소 모션 감지 값입니다.
    state-size
    5
     
    내부 알고리즘용입니다.
    window-scale
    3.0
     
    내부 알고리즘용입니다.
    window-threshold
    3.5
     
    내부 알고리즘용입니다.
    shadow-factor
    0.5
     
    내부 알고리즘용입니다.
    weight-factor
    0.01
     
    내부 알고리즘용입니다.
    weight-threshold
    0.9
     
    내부 알고리즘용입니다.
    height-max
    100
     
    모션 감지를 위해 스케일한 영상의 최대 허용 높이입니다.
    is-player
    0
     
    미디어 재생에 사용할 경우, "1" 값을 지정합니다.
    buffer-count
    3
     
    영상 버퍼 개수입니다.
    MotionDetectorRef createMotionDetector ( key_value_map_t & parameters )
    OasisMotion.h
    카메라 장치 영상용 모션 감지기를 생성합니다. 카메라 장치는 "camera-id" 키값을 사용합니다.
    매개변수
    parameters  모션 감지와 카메라 장치에 필요한 key-value map 매개변수입니다.
    리턴값
    성공하면 MotionDetector 객체를 리턴합니다. 실패하면 nullptr을 리턴합니다.
    int32_t destroyMotionDetector ( MotionDetectorRef & motion_detector )
    OasisMotion.h
    createMotionDetector로 생성한 모션 감지기를 해제합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorId ( const MotionDetectorRef & motion_detector )
    OasisMotion.h
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    리턴값
    모션 감지기 ID를 리턴합니다. MediaSource 값과 동일합니다.
    int32_t motionDetectorStart ( const MotionDetectorRef & motion_detector , const std::shared_ptr<MotionDetectObserver> & observer )
    OasisMotion.h
    모션 감지를 시작합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    observer  모션 감지 이벤트 호출을 위한 MotionDetectObserver로 부터 유도된 사용자 정의 observer 객체입니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorStop ( const MotionDetectorRef & motion_detector )
    OasisMotion.h
    모션 감지를 중지합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorSetThreshold ( const MotionDetectorRef & motion_detector , int32_t threshold )
    OasisMotion.h
    모션 감지기의 감지 임계값을 설정합니다. 이 값보다 높은 픽셀 변동이 발생하면 모션 감지 이벤트가 발생됩니다. 임계값은 key-value map의 "height-max" 값에 따라서 결정됩니다. 최초 threshold 값을 "0"으로 하여 감지 이벤트에서 모션 감지 값을 확인하여, 운영에 맞는 적합한 값을 선택할 수 있습니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    threshold  모션 감지 임계값입니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorSetFrameRate ( const MotionDetectorRef & motion_detector , int32_t fps )
    OasisMotion.h
    모션 감지용 프레임 레이트를 설정합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    fps  프레임 레이트 값입니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorGetThreshold ( const MotionDetectorRef & motion_detector , int32_t & threshold )
    OasisMotion.h
    모션 감지기의 현재 설정된 감지 임계값을 리턴합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    threshold  OUT 모션 감지 임계값이 저장되어 리턴됩니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorGetFrameRate ( const MotionDetectorRef & motion_detector , int32_t & fps )
    OasisMotion.h
    모션 감지기에 현재 설정된 프레임 레이트를 리턴합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    fps  OUT 현재 설정된 프레임 레이트가 저장되어 리턴됩니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorAddROIRegion ( const MotionDetectorRef & motion_detector , int32_t left , int32_t top , int32_t width , int32_t height , bool enabled )
    OasisMotion.h
    모션 감지기에 영역을 추가합니다. 영역의 각 좌표값은 원본 영상 크기 기준입니다. 모션 감지기에 적어도 하나 이상의 모션 감지 영역을 설정하게 되면, 전체 모션 감지가 아닌 각 영역별 모션 감지가 이루어집니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    left  영역의 왼쪽 좌표입니다.
    top  영역의 위쪽 좌표입니다.
    width  영역의 너비입니다.
    height  영역의 높이입니다.
    enabled  이 영역에 모션 감지할 지 여부를 지정합니다. true이면 모션 감지를 합니다.
    리턴값
    성공하면, 모션 감지 영역의 ID 값을 리턴합니다. 실패하면 -1을 리턴합니다.
    int32_t motionDetectorEnableROIRegion ( const MotionDetectorRef & motion_detector , int32_t roi_id , bool enable )
    OasisMotion.h
    특정 영역의 모션 감지 여부를 설정합니다. 모든 영역을 비활성화하게 되면 전체 모션 감지를 시작합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    roi_id  motionDetectorAddROIRegion로 리턴받은 영역 ID입니다. -1이면 모든 영역을 설정합니다.
    enable  true이면 모션 감지를 합니다. false이면 모션 감지를 비활성화 합니다.
    리턴값
    • 0: 성공
    • -1: 실패
    int32_t motionDetectorRemoveROIRegion ( const MotionDetectorRef & motion_detector , int32_t roi_id )
    OasisMotion.h
    모션 감지 영역을 제거합니다. 모든 영역을 제거하게 되면 전체 모션 감지를 시작합니다.
    매개변수
    motion_detector  createMotionDetector로 생성한 모션 감지기를 지정합니다.
    roi_id  motionDetectorAddROIRegion로 리턴받은 영역 ID입니다. -1이면 모든 영역을 제거합니다.
    리턴값
    • 0: 성공
    • -1: 실패

    예제#

    아래는 카메라 장치 ID 0 영상으로 부터 모션 감지하는 예제입니다.

    #include "OasisAPI.h"
    #include "OasisLog.h"
    #include "OasisMedia.h"
    #include "OasisFS.h"
    #include "OasisUtil.h"
    #include "OasisMotion.h"
    
    #include <thread>
    #include <mutex>
    #include <memory>
    #include <condition_variable>
    
    #include <signal.h>
    
    #define DLOG_THIS   0x00010000
    #define DLOG_RECORD 0x00020000
    #define DLOG_FRAME  0x00040000
    #define DLOG_TRACE  0x00080000
    
    #undef DLOG_FLAGS
    #define  DLOG_FLAGS (DLOG_FLAGS_DEFAULT|DLOG_RECORD|DLOG_TRACE|DLOG_THIS/*|DLOG_FRAME*/)
    
    #undef DLOG_TAG
    #define DLOG_TAG "Motion"
    
    using namespace oasis;
    
    
    static bool continue_running_ = true;
    
    class MyMotionDetectObserver : public MotionDetectObserver 
    {
     public:
        MyMotionDetectObserver() {}
        virtual ~MyMotionDetectObserver() {}
    
        virtual void onMotionDetected(int32_t camera_id, int32_t detected) {
            TRACE0("camera<%d> motion detected#%d\n", camera_id, detected);
        }
    
    };
    
    void print_usage(const char *pname)
    {
        DLOG0(DLOG_INFO, "USAGE: %s\n", pname);
    }
    
    void cancel_handler(int signum)
    {
        continue_running_ = false;
    
    }
    
    int main(int argc, char* argv[])
    {
        int32_t err;
        int32_t i, c, n;
        std::thread t1, t2, t3;
    
        oasis::key_value_map_t parameters;
    
        srand(time(NULL));
    
        signal(SIGINT, cancel_handler);
    
        ////////////////////////////////////////////////////////////////////////////////////////////
        // init
        parameters["offs-disable"] = "1";
        //parameters["oasis-log-flags"] = std::to_string(OASIS_LOG_DEBUG/*|OASIS_LOG_ENCODE_BITRATE*/);
    
        if(oasis::initialize(parameters) < 0) {
            DLOG(DLOG_ERROR, "Oasis init failed\n");
            return -1;
        }
    
        ////////////////////////////////////////////////////////////////////////////////////////////
        // sources
        parameters.clear();
    
        parameters["source-count"] = "1";
    
        parameters["source1-camera-id"] = "0";
        parameters["source1-isp-id"] = "0";
        parameters["source1-isp-wdr-mode"] = "0";
        parameters["source1-capture-format"] = "YUV420";
        parameters["source1-capture-buffers"] = "5";
        parameters["source1-fps"] = "30";
        parameters["source1-subchannel-rotation"] = "0";
        parameters["source1-loc"] = "front";
        parameters["source1-capture-resolution"] = "1080p";
        parameters["source1-sensor-config"] = "./Resource_tp2863/VIC/0/tp2863_1920x1080_ch0.cfg";
        parameters["source1-autoscene-config"] = "./Resource_tp2863/AutoScene/autoscene_conf.cfg";
        parameters["source1-resource-dir"] = "./Resource_tp2863/";
    
        configCameras(parameters);
    
        ////////////////////////////////////////////////////////////////////////////////////////////
        //motion detector settings
    
        std::shared_ptr<MyMotionDetectObserver> motion_detect_observer = std::make_shared<MyMotionDetectObserver>();    
    
        parameters.clear();
    
        parameters["camera-id"] = "0";
        parameters["enable"] = "1";
        parameters["use-g2d"] = "1";
        parameters["buffer-count"] = "3";
        parameters["sensitivity-level"] = "5";
        parameters["fps"] = "6";
        parameters["version"] = "2";
        parameters["height-max"] = "135";
    
        MotionDetectorRef motion_detector = createMotionDetector(parameters);
    
        err = motionDetectorStart(motion_detector, motion_detect_observer);
        if(err < 0) {
            DLOG0(DLOG_ERROR, "MotionDetectgor start failed\n");
        } else {
            TRACE0("MotionDetector<%d> started\n", motionDetectorId(motion_detector));
        }
    
    
        printf("Ctrl+C to exit...\n");
    
        do {
            usleep(100000);
        } while (continue_running_ == true);
    
        if(motion_detector) {
            destroyMotionDetector(motion_detector);
        }
    
        oasis::finalize();
    
        printf("goodbye.\n");
    
        return 0;
    }