Handmade Hero»Forums»Code
Matyas
15 posts
Motion tracking - Getting camera data without any libraries
Edited by Matyas on
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!)
Mārtiņš Možeiko
2562 posts / 2 projects
Motion tracking - Getting camera data without any libraries
Edited by Mārtiņš Možeiko on
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
15 posts
Motion tracking - Getting camera data without any libraries
Thank you very much Martins!
This is definetly what I've been looking for.
Mārtiņš Možeiko
2562 posts / 2 projects
Motion tracking - Getting camera data without any libraries
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
15 posts
Motion tracking - Getting camera data without any libraries
Edited by Matyas on
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 ;)