MCPcopy Create free account
hub / github.com/OSVR/OSVR-Core / update

Function update

plugins/videobasedtracker/com_osvr_VideoBasedHMDTracker.cpp:330–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328 }
329
330 OSVR_ReturnCode update() {
331#ifdef VBHMD_FAKE_IMAGES
332 // Wrap the image count back around if it has gone too
333 // high.
334 if (m_currentImage >= m_images.size()) {
335 m_currentImage = 0;
336 }
337 // Read an image if there is one to be had, and
338 // increment the frame count. Otherwise, fail.
339 if (m_currentImage >= m_images.size()) {
340 return OSVR_RETURN_FAILURE;
341 } else {
342 m_frame = m_images[m_currentImage++];
343 }
344
345// Sleep 1/120th of a second, to simulate a reasonable
346// frame rate.
347// vrpn_SleepMsecs(1000 / 120);
348#else
349 if (!m_camera->isOpened()) {
350 // Couldn't open the camera. Failing silently for now. Maybe the
351 // camera will be plugged back in later.
352 return OSVR_RETURN_SUCCESS;
353 }
354
355//==================================================================
356// Trigger a camera grab. Pull it into an OpenCV matrix named
357// m_frame.
358#ifdef VBHMD_USE_DIRECTSHOW
359 if (!m_camera->read_image_to_memory()) {
360 // Couldn't open the camera. Failing silently for now. Maybe the
361 // camera will be plugged back in later.
362 return OSVR_RETURN_SUCCESS;
363 }
364 int minx, miny, maxx, maxy;
365 m_camera->read_range(minx, maxx, miny, maxy);
366 int height = maxy - miny + 1;
367 int width = maxx - minx + 1;
368 m_frame = cv::Mat(height, width, CV_8UC3,
369 (BYTE *)(m_camera->get_pixel_buffer_pointer()));
370
371 //==================================================================
372 // Flip the image in Y to take it from DirectShow space into
373 // OpenCV space.
374 cv::flip(m_frame, m_frame, 0);
375#else
376 if (!m_camera->grab()) {
377 // No frame available.
378 return OSVR_RETURN_SUCCESS;
379 }
380 if (!m_camera->retrieve(m_frame, m_channel)) {
381 return OSVR_RETURN_FAILURE;
382 }
383#endif
384
385#ifdef VBHMD_SAVE_IMAGES
386 // If we're supposed to save images, make file names that match the
387 // format we need to read them back in again and save the images.

Callers 3

mainloopMethod · 0.85
mainloopMethod · 0.85
pollMethod · 0.85

Calls 10

osvrTimeValueGetNowFunction · 0.85
isOpenedMethod · 0.80
read_image_to_memoryMethod · 0.80
read_rangeMethod · 0.80
strMethod · 0.80
pollMethod · 0.80
processImageMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected