View Single Post
  #21   Spotlight this post!  
Unread 21-12-2013, 14:39
Thad House Thad House is online now
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,107
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Fixing opencv lag

Quote:
Originally Posted by virtuald View Post
Not true. If you have ffmpeg support enabled (which it is by default in most opencv builds), you can retrieve the mjpeg stream directly from the camera via FFMPEG. Something similar to the following (error checking omitted):

Code:
vc = cv2.VideoCapture()
vc.open('http://%s/mjpg/video.mjpg' % camera_host)

h = vc.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
w = vc.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)

capture_buffer = np.empty(shape=(h, w, 3), dtype=np.uint8)

while True:
    retval, img = vc.read(capture_buffer)
Yeah I know I can recieve the MJPEG stream like this, and that is what I am doing. The camera still pushes frames into the stream at 30 FPS. If the vc.read does not occur faster then 30 times a second, The buffer will start to backlog and lag. In fact your code was what I started from, and I was doing exactly that. If you put at 50ms delay at the end of your processing function you will see that it starts to lag.

When people were talking about requesting images, they are talking about not opening the stream, but just directly requesting a single image, and working with that, so the camera does not push a buffer. Thats the part that does not work natively in openCV.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.