Software Archive
Read-only legacy content
17061 Discussions

I want to know how to get the focal length of the camera

a_a_
Beginner
1,130 Views

According to the document, we can get the focal length of the depth camera from the function QueryDepthFocalLengthMM. However, I do not know how to use it. Could anyone can show me the example code to get the focal length? Thank you!

0 Kudos
1 Reply
Austin_C_
Beginner
1,130 Views

This is how I do it in C# with Unity:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Example: MonoBehaviour {
// Color Image info
	public int colorWidth = 848;
	public int colorHeight = 480;
	public float colorFPS = 60f;
	
	// Depth Image info
	public int depthWidth = 640;
	public int depthHeight = 480;
	public float depthFPS = 60f;

// psm is the manager that controls access to streams, acquiring frames, etc
PXCMSenseManager psm;

void Start() {
psm = PXCMSenseManager.CreateInstance();
		if(psm == null) {
			Debug.LogError("Unable to create the PXCSenseManager");
			return;
		}
// tell the PSM that we want to enable depth at this resolution and fps
		if(psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, depthWidth, depthHeight, depthFPS)
			 != pxcmStatus.PXCM_STATUS_NO_ERROR)
		{
			Debug.LogError("Unable to start depth stream");
			return;
		}
		// tell the PSM that we want to enable color at this resolution and fps
		if(psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, colorWidth, colorHeight, colorFPS)
		   != pxcmStatus.PXCM_STATUS_NO_ERROR)
		{
			Debug.LogError("Unable to start depth stream");
			return;
		}
		// initialize the PSM
		if(psm.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
		{
			Debug.Log("Unable to Init the PXCSenseManager");
			OnDisable();	// clean up
			return;
		}
// now we get the focal length:
float focalLengthMM = psm.captureManager.device.QueryColorFocalLengthMM();
Debug.Log("Focal length: " + focalLengthMM);
}

void OnDisable()
	{
		if(psm != null)
		{
			psm.Dispose();
		}
	}
}

Hope that makes sense. Make sure you have imported the SDK into your project as well.

0 Kudos
Reply