0

I have a doubt with opencv and the backgroundsubtractor.

I'm using the next code:

int main(int argc, char** argv ) {
  VideoCapture cap(0);
    if(!cap.isOpened()) {
        cout << "aaaa" << endl;
        return -1;
    }

      cv::Ptr<cv::cuda::BackgroundSubtractorMOG2> pBackSub =        cv::cuda::createBackgroundSubtractorMOG2(5, 750, false);

    while(true) {
        Mat img;
        cap >> img;

        cv::cuda::GpuMat gpu;
        cv::cuda::GpuMat fgMask;
        gpu.upload(img);


    
      pBackSub->apply(gpu, fgMask, 0.2);

        Mat mask;
        fgMask.download(mask);


        imshow("patata", mask);
        waitKey(12);
    }

  return 0;
}

With this test code the subtractor works fine, but when I change the videocapture to a rtsp source I start to see the mask with a lot of noise and the camera is stopped, so it should be a black image as I see in the example above. Does anyone know what is happening?

Thanks in advance.

4
  • Does this answer your question? capturing rtsp camera using OpenCV python Commented Nov 24, 2020 at 15:33
  • Asked before. See stackoverflow.com/questions/40875846/… Commented Nov 24, 2020 at 15:33
  • I can open the camera, in these questions you suggest, the problem is that he can't open the camera, so I don't know how this solution can help with my problem Commented Nov 24, 2020 at 17:11
  • look closely. dont use VideoCapture cap(0); use VideoCapture("rtsp://192.168.1.2:8080/out.h264") Commented Nov 24, 2020 at 20:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.