Register
Handmade Hero»Forums»Code»Motion tracking - Getting camera data without any libraries
Matyas
16 posts
Motion tracking - Getting camera data without any libraries
2 months, 2 weeks ago Edited by Matyas on Aug. 28, 2019, 4:59 p.m.
Hi everyone!

I've been playing around with the idea of integrating motion tracking into the hmh engine.

Currently, I'm using the DirectShow api to get raw camera footage. The issue is that DirectShow is complete garbage, and seems deprecated.

Is there another api to get camera data?

I want the simplest thing possible, so I would definetly not use OpenCV (if possible!)

- Matyas
Mārtiņš Možeiko
1983 posts / 1 project
Motion tracking - Getting camera data without any libraries
2 months, 2 weeks ago Edited by Mārtiņš Možeiko on Aug. 28, 2019, 8:27 p.m.
Media Foundation is the API you want. MF is api (since Vista) to deal with different kind of video/audio related things - playback, capture, encoding, decoding, etc...

What you want to look at is IMFSourceReader and IMFMediaSource.
Here are instructions how to create IMFMediaSource (representing camera): https://docs.microsoft.com/en-us/...video-capture-in-media-foundation
And here are instructions how to use IMFSourceReader to read data from it: https://docs.microsoft.com/en-us/...media-data-with-the-source-reader
Matyas
16 posts
Motion tracking - Getting camera data without any libraries
2 months, 2 weeks ago
Thank you very much Martins!
This is definetly what I've been looking for.

- Matyas
Mārtiņš Možeiko
1983 posts / 1 project
Motion tracking - Getting camera data without any libraries
2 months, 2 weeks ago
I've found some of my old code that can be used as example: https://gist.github.com/mmozeiko/a5adab1ad11ea6d0643ceb67bb8e3e19

If you run it without arguments it will enumerate available devices:
1
2
3
C:\tets>test.exe
Detected 1 devices:
Integrated Webcam = \\?\usb#vid_0bda&pid_5686&mi_00#6&153a3df0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global


To capture to file you run with that long path:
1
2
C:\tets>test.exe "\\?\usb#vid_0bda&pid_5686&mi_00#6&153a3df0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
Size = 848x480

And output is written to image.jpg file.
Matyas
16 posts
Motion tracking - Getting camera data without any libraries
2 months, 2 weeks ago Edited by Matyas on Aug. 28, 2019, 10:30 p.m.
Wow, thank you very much!!
This helps me _a lot_, since Microsoft's docs aren't always that clearly written.

I'll probably write an stb-style cross-platform lib, and then post it here later so the handmade folks can use it too ;)

- Matyas