Jump to content

Pupil Diameter (Unreal C++)


Franka

Recommended Posts

I try to get the pupil diameter data in Unreal/ C++ which is not included as a function in the SRanipal_FunctionLibrary_Eye. That's the reason why I tried to directly get the verboseData or EyeData through SRanipal_Eye eg. like this: 

int result = SRanipal_Eye::Instance()->GetEyeData_(&eye_data)

For some reason I always get the compiler error "error LINK2019: unresolved external symbol". So far I could not work out my mistake so I would be very grateful for a short example/ code snippet on how to access the pupil diameter data in Unreal/ C++ with SRanipal (not Tobii!).

Thanks in advance

@MariosBikos_HTC

  • Like 1
Link to comment
Share on other sites

Hey @Franka, you are right, we currently don't have a function exposed to Blueprints for GetPupilDiameter but I have already informed the SDK team about it so that they can add one in a future version of the SDK. Meanwhile, here are some screenshots that will help to add that yourself.

What you need to do is define a GetPupilDiameter function inside USRanipalEye_FunctionLibrary (similarly to how GetPupilPosition is structured) and then also create a function GetPupilDiameter() inside SRanipalEye_Core that will be called from the first function I mentioned. 

Here are the cpp files I used to achieve that. You need to of course modify the header files as well.

 

oKu8armCFApEtM1pgUB0oE5upB_E8yO72qB1NGQDjCvR7o-oQ7vjOzzTAPXHsaDOti8dg3AG6Zo60onTuOzaw-dHN2ITJcfsrQtGWefcZ1MYHonBCIoPK_93Fk84K2l7YpQ0N4_a

Xv8SbkgS_z5_vJeXBgR4Jxppl1etKE1s0laEkUbn3RkYWA8jM-De8tpWOhZTanJ_b1zAhBqREyjorcnbiOFjztTnXd0VTUyEPHP2Grl5JgUmjv0oSicNkgCti3CQP34ob89ntStt

 

  • Thanks 1
Link to comment
Share on other sites

Thank you for the fast reply! 

Do you mean the SRanipal_FunctionLibrary_Eye instead of USRanipalEye_FunctionLibrary and SRanipal_Eye instead of SRanipalEye_Core?

I cannot find neither the USRanipalEye_FunctionLibrary nor the SRanipalEye_Core...

Link to comment
Share on other sites

Thank you again - you really helped a lot!

 

So I added following to the SRanipal_FunctionLibrary_Eye.cpp (and of course adjusted the header file)

image.png.d52423dfffc2c742345a51f194a1df3b.png

and following to the SRanipal_Eye.cpp

image.png.257c0a0c1a69aac85f721dbe9576d1f0.png

 

And it seems to work - at least I do not get any errors. 

But I only get the 0.0f as diameter result and I check the validity first so that cannot be the reason...

@MariosBikos_HTC

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hey @MariosBikos_HTC

till now I could not figure out why I do not get proper pupil size values. Sometimes the data is not valid and therefore the returned pupil size equals 0.0f. In other cases (without changing anything) the data is valdi but still equals 0.0f. 

Any ideas on that?

I really appreciate your help!

 

  • Like 1
Link to comment
Share on other sites

@Franka I'm trying to get some pupil dilation data as well.

I wanted to run this fix but wasn't sure what you meant by header file.

I'm also thinking of extracting this data and writing to a file of some kind for processing in R or Python.

Sounds like the detection isn't working great though so I'm going to try my hand at figuring it out and will let you know if I can get something.

-CTE

Link to comment
Share on other sites

  • 2 weeks later...

Glad that it worked @Franka!
Yes you need to make sure the Eye_Framework is in your scene, as it's required to initialize the Eye tracking process.

@cte the header file in C++ holds the declaration(signature) of a function so it's exactly the same as the function above but without implementation details. You can check the header files to get an idea.

 

  • Thanks 2
Link to comment
Share on other sites

@Franka & @MariosBikos_HTC thanks for the help.

For reference, I'm working off of the latest version of the SRanipal Framework so had to alter some of the code.

Now I'm having a little trouble understanding what I need to feed into the blueprints I'm calling and assume I have put something wrong in here as I want diameter MM as a string output rather than an input so I can write it to a csv.

Here is the function in blueprints:

image.png.c5820c83540c2232b8f99de0ceb5e30b.png

 

Question: What do I need to alter to get the diameter Mm as a string output variable?

> I'm going to look into this but would love a response here if someone knows how this would.

 

----------------------------------------------------------------------------------------------------------------------------------

👇👇👇 Changed Code 👇👇👇👇

➡️ SRanipalEye_Core.cpp:

Added:

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 {
		UpdateData();

		Eye::SingleEyeData EyeData = eye == EyeIndex::LEFT ? EyeData_.verbose_data.left : EyeData_.verbose_data.right;
		valid = EyeData.GetValidity(Eye::SingleEyeDataValidity::SINGLE_EYE_DATA_PUPIL_DIAMETER_VALIDITY);
		if (valid) {
			diameter_mm = EyeData.pupil_diameter_mm;
		}
		else {
			diameter_mm = 0.0f;
		}
	}

	return valid;
}

 

➡️  SRanipalEye_FunctionLibrary.h

Added:

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

 

➡️ SRanipalEye_FunctionLibrary.cpp

Added:

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

 

Link to comment
Share on other sites

@Franka & @MariosBikos_HTC thanks for the help.

For reference, I'm working off of the latest version of the SRanipal Framework so had to alter some of the code.

Now I'm having a little trouble understanding what I need to feed into the blueprints I'm calling and assume I have put something wrong in here as I want diameter MM as a string output rather than an input so I can write it to a csv.

Here is the function in blueprints:

image.png.c5820c83540c2232b8f99de0ceb5e30b.png

 

Question: What do I need to alter to get the diameter Mm as a string output variable?

> I'm going to look into this but would love a response here if someone knows how this would.

- I've looked into this a little bit and it seems that the absence of the framework is what is really creating issues here.

Question: Based on the updates to SRanipal SDK what do I call instead of the framework for getting the data?

----------------------------------------------------------------------------------------------------------------------------------

👇👇👇 Changed Code 👇👇👇👇

➡️ SRanipalEye_Core.cpp:

Added:

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 {
		UpdateData();

		Eye::SingleEyeData EyeData = eye == EyeIndex::LEFT ? EyeData_.verbose_data.left : EyeData_.verbose_data.right;
		valid = EyeData.GetValidity(Eye::SingleEyeDataValidity::SINGLE_EYE_DATA_PUPIL_DIAMETER_VALIDITY);
		if (valid) {
			diameter_mm = EyeData.pupil_diameter_mm;
		}
		else {
			diameter_mm = 0.0f;
		}
	}

	return valid;
}

 

➡️  SRanipalEye_FunctionLibrary.h

Added:

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

 

➡️ SRanipalEye_FunctionLibrary.cpp

Added:

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

 

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...