microsoft / psi

Platform for Situated Intelligence
https://github.com/microsoft/psi/wiki
Other
538 stars 96 forks source link

Using Kinect and a Webcam #314

Open sanmii opened 4 months ago

sanmii commented 4 months ago

Hi!

I am planning to use a Kinect camera and a webcam to gather data. To gather data from Kinect I have tried and I know that this works:

// Kinect Camera 1
    var cam = new AzureKinectSensor(p, new AzureKinectSensorConfiguration()
    {
        DeviceIndex = 0,
        OutputColor = true,
        CameraFPS = FPS.FPS30,
        //WiredSyncMode = WiredSyncMode.Master,
        PowerlineFrequency = AzureKinectSensorConfiguration.PowerlineFrequencyTypes.SixtyHz,
        ExposureTime = TimeSpan.FromTicks(80000),
        ColorResolution = ColorResolution.R720p
    });
    var imageStream = cam.ColorImage.EncodeJpeg(75, DeliveryPolicy.LatestMessage);
    imageStream.Write("Image1", store);
    var decodedImageStream = imageStream.Decode();

However I am not certain at all how to gather the information from the webcam. Should be this way? var webcam = new Microsoft.Psi.Media.MediaCapture(pipeline, 1920, 1080, 30);

How do I know that this will take data from the Webcam and not from the Kinect camera? is there any way to specify the name of the camera you want to gather the data from?

Thank you in advance.

chitsaw commented 4 months ago

Yes, you can specify the name of the camera via the deviceId string parameter in the MediaCapture constructor.

sanmii commented 4 months ago

Is there any example? Since all the examples with DeviceId I have found are for Kinect or AudioSource functions.

chitsaw commented 4 months ago

I'm not sure if there are any examples with deviceId specifically, but based on your example above, you would so something like this:

var webcam = new Microsoft.Psi.Media.MediaCapture(pipeline, 1920, 1080, 30, deviceId: "Integrated Webcam");

Replace "Integrated Webcam" with a string that represents the device friendly-name of the webcam you want to capture from. Note that the selected device must support the specified width/height/framerate combination. If you pass in an invalid deviceId/capture combination, you should get a helpful exception message with a list of available deviceIds and capture formats.