0

I'm using Opencv 2.4.5 with python 2.7 to track people in video surveillance. At the beginning I used .avi and .mpeg videos to test my code, now I want to use a hcv-m100c camera. I am using a simple difference between frames (an initial frame compared with each frame) to identify the objects in movement, It works very well with the .avi and .mpeg videos I have, but when I use the camera the results are so bad because a lot of noise and stains appear in my video. I thought that the problem was my camera, but I made an .avi video with the same camera and I tested that video with my code and it works fine. Now, I'm using the cv2.BackgroundSubtractorMOG but the problem is still there. So, I think I need to do a pre-processing when I use the camera

Gab Hum
  • 75
  • 1
  • 4
  • 11
  • Is it because video codecs use filters to smooth out changes between frames and so that could be removing the noise? – dilbert Jun 25 '13 at 00:26
  • I have tried that with the Gaussian Smoothing, same problem – Gab Hum Jun 25 '13 at 06:19
  • Possibly you could [stream](http://ffmpeg.org/trac/ffmpeg/wiki/Streaming%20media%20with%20ffserver) the [video camera](http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20capture%20a%20webcam%20input) with something like ffmpeg which can transcode as well and then use OpenCV to read the [network stream](http://stackoverflow.com/questions/8513304/is-it-possible-to-read-video-stream-with-opencv) – dilbert Jun 25 '13 at 06:43
  • It might be easier to use [VLC](http://geraldnaveen.blogspot.com.au/2009/04/streaming-webcam-using-vlc.html) to stream instead. – dilbert Jun 25 '13 at 06:51
  • I am using this function to capture the video from the camera, `cap = cv2.VideoCapture(0)` so, How to use the VLC stream in this case? thank you in advance – Gab Hum Jun 25 '13 at 15:56
  • I think if you follow that VLC link above, change the cap = cv2.VideoCapture(0) to cap = cv2.VideoCapture("VLC_IP"), maybe cap = cv2.VideoCapture("127.0.0.1"). – dilbert Jun 25 '13 at 21:39
  • I forgot to post my solution, I made a local streamming with VLC creating an RTSP with this code `vlc "http://192.168.180.60:82/videostream.cgi?user=admin&pwd=" --sout "#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=rtp{sdp=rtsp://:8554/output.mpeg},dst=display}" --sout-keep` , so, I got this link rtsp://:8554/output.mpeg and now I can use it in OpenCV as follows: `cap=cv2.VideoCapture("rtsp://:8554/output.mpeg")` .. Thank you @dilbert – Gab Hum Jun 27 '13 at 18:38
  • Has it helped with the noise problem? – dilbert Jun 27 '13 at 22:07

1 Answers1

1

Just for completeness:

Solution concept:

Possibly you could stream the video camera with something like ffmpeg which can transcode as well and then use OpenCV to read the network stream. It might be easier to use VLC to stream instead.

Solution detail:

VLC Stream code (Shell):

vlc "http://192.168.180.60:82/videostream.cgi?user=admin&pwd=" --sout "#transcode{vcodec=mp2v,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=??44100}:duplicate{dst=rtp{sdp=rtsp://:8554/output.mpeg},dst=display}" --sout-keep

OpenCV Code (Python):

cap=cv2.VideoCapture("rtsp://:8554/output.mpeg")
dilbert
  • 3,008
  • 1
  • 25
  • 34