문제

aforge.net 프레임 워크를 사용하여 MotionDetection을 설정하려고합니다. 제공된 정보를 사용하고 있습니다 이것 페이지.

스트림을 통해 데스크탑의 일부를 공급하는 DirectShow VideoStream을 설정합니다. Aforge와 함께 제공되는 샘플 VideoPlayer 프로젝트 에서이 스트림을 선택할 수 있습니다. (그리고 나는 플레이어를 통해 내 데스크탑을 본다).

그러나 아래 코드를 실행하면 NullReferenceException을받습니다. 내가 무엇을 놓치고 있습니까?

    // New frame received by the player
    private void videoSourcePlayer_NewFrame( object sender, ref Bitmap image )
    {
        if (this.detector.ProcessFrame(image) > 0.02)
        {
            Console.WriteLine("Motion");
        }
        else
        {
            Console.WriteLine("No motion");
        }
    }

그만큼 detector 비디오 스트림을 선택할 때 개인 클래스 변수로 초기화됩니다.

    private MotionDetector detector;
    private BlobCountingObjectsProcessing motionProcessor;

    // Open video source
    private void OpenVideoSource( IVideoSource source )
    {
        BlobCountingObjectsProcessing motionProcessor = new BlobCountingObjectsProcessing();

        MotionDetector detector = new MotionDetector(
            new SimpleBackgroundModelingDetector(),
            motionProcessor);
    }
도움이 되었습니까?

해결책

살펴보십시오 BlobCountingObjectsProcessing motionProcessor, 한 번 초기화되지 않고 일단 초기화되지 않은 변수를 두 번 선언 한 것 같습니다.

하나의 외부 메소드 범위와 하나의 내부 메소드 범위.

나는 그것이 당신의 NullReferenceException이 오는 곳이라고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top