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.

talonmies
  • 70,661
  • 34
  • 192
  • 269
sej
  • 46
  • 4
  • Does this answer your question? [capturing rtsp camera using OpenCV python](https://stackoverflow.com/questions/40875846/capturing-rtsp-camera-using-opencv-python) – Dr Yuan Shenghai Nov 24 '20 at 15:33
  • Asked before. See https://stackoverflow.com/questions/40875846/capturing-rtsp-camera-using-opencv-python – Dr Yuan Shenghai Nov 24 '20 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 – sej Nov 24 '20 at 17:11
  • look closely. dont use VideoCapture cap(0); use VideoCapture("rtsp://192.168.1.2:8080/out.h264") – Dr Yuan Shenghai Nov 24 '20 at 20:16

0 Answers0