Jump to content

Pupil Diameter (Unreal C++)


Recommended Posts


🎉🎉Found the fix and now have functional dilation extraction going. 🎉🎉



bool USRanipalEye_FunctionLibrary::GetPupilDiameter(EyeIndex eye, float& diameter_mm)
	return SRanipalEye_Core::Instance()->GetPupilDiameter(eye, diameter_mm);


bool SRanipalEye_Core::GetPupilDiameter(EyeIndex eye, float &diameter_mm)
	bool valid = false;
	if (SRanipalEye_Framework::Instance()->GetStatus() == SRanipalEye_Framework::FrameworkStatus::NOT_SUPPORT) {
		valid = true;
		diameter_mm = 0.0f;
	else {

		Eye::SingleEyeData eyeData;
		switch (SRanipalEye_Framework::Instance()->GetEyeVersion())
		case SupportedEyeVersion::version1:
			eyeData = eye == EyeIndex::LEFT ? EyeData_.verbose_data.left : EyeData_.verbose_data.right;
		case SupportedEyeVersion::version2:
			eyeData = eye == EyeIndex::LEFT ? EyeData_v2.verbose_data.left : EyeData_v2.verbose_data.right;

		valid = eyeData.GetValidity(Eye::SingleEyeDataValidity::SINGLE_EYE_DATA_PUPIL_DIAMETER_VALIDITY);
		if (valid) {
			diameter_mm = eyeData.pupil_diameter_mm;
			diameter_mm = 0.0f;
	return valid;


	bool GetPupilDiameter(EyeIndex eye, float& diameter_mm);


UFUNCTION(BlueprintCallable, Category = "SRanipal|Eye")
		static bool GetPupilDiameter(EyeIndex eye, float& diameter_mm);


  • Thanks 2
Link to comment
Share on other sites

  • 3 months later...

@cte, thank you so much! Works like a charm on UE 4.25. For those who are completely new to modifying the .cpp and .h files, a few more things to note in order to not get lost:

  • The "SRanipal_Core.h" file is actually called "SRanipalEye_Core.h" (as of the Release, perhaps previously it was named differently or just a type from cte)
  • After adding all the above code, you may need to right-click on your .uproject file in Explorer and select "generate visual studio project files" in order for the new BP node to appear (I also reopened the project from Epic Games Launcher for the node to finally become available, not sure if this is a needed step though).


  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...

thank you very much @cte and also @MadisV, I confirm that it works, tested in 4.27, although for the node to finally become available I had to recompile the whole project in visual. I don't know why they don't include this code directly in the release...

Edited by cifulicitico
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...