Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically change resolution #1182

Open
Princic-1837592 opened this issue Apr 22, 2024 · 4 comments
Open

Programmatically change resolution #1182

Princic-1837592 opened this issue Apr 22, 2024 · 4 comments
Labels
out of scope Beyond the scope of free support type:support Support issue

Comments

@Princic-1837592
Copy link

Plugin Version or Commit ID

v0.14.3

Unity Version

2022.3.18f1

Your Host OS

Windows 11

Target Platform

Android

Description

Using the Hand Tracking sample as a starting point I'm trying to add a button that, when pressed, takes the current picture from the webcam. I need this picture to have the highest resolution as possible, so when the button is clicked I'd like to:

  1. temporarily switch resolution to the best one
  2. take the picture
  3. go back to the original resolution

I managed to pause the video, change resolution take a picture and go back to the original resolution, but after this the video won't start again

Code to Reproduce the issue

I added a button to the UI and this is what I'm trying to do in its OnClick function

/*    some code to find the current and the best resolution    */
var imageSource = ImageSourceProvider.ImageSource;
isPaused = true;
imageSource.Stop();
imageSource.SelectResolution(bestResId); // select the new temporary resolution
yield return imageSource.Play();
yield return new WaitForSeconds(2); // wait for the webcam to be ready

var picture = imageSource.GetCurrentTexture(); // take picture with new resolution

imageSource.Stop();
imageSource.SelectResolution(oldResId); // go back to original resolution
yield return imageSource.Play();
yield return new WaitForSeconds(2);
isPaused = false;

And it actually takes the picture with best quality, but the video stream won't restart with the old resolution after this process

Additional Context

I have looked at the code for ImageSource Config Button and I think to understand that when the "Exit" button is pressed (after manually changing resolution from the modal panel) the whole HandTrackingSolution is restarted, but I'd like to do this without restarting

@Princic-1837592 Princic-1837592 added the type:support Support issue label Apr 22, 2024
@homuler
Copy link
Owner

homuler commented Apr 22, 2024

the whole HandTrackingSolution is restarted, but I'd like to do this without restarting

I guess calling the Close method instead of CloseAndResume would do.

By the way, the sample code (under the Assets folder) isn't written to be easily modified, so usually it's better to write your own code as needed while using only the code under Packages.

@Princic-1837592
Copy link
Author

the sample code (under the Assets folder) isn't written to be easily modified

I noticed. This is just for the prototype of a project, the team is already working on a whole new application and UI from scratch but we need a working prototype first.

I guess calling the Close method instead of CloseAndResume would do.

But I'm not calling any of them, and I intend not to because I'm not using any modal panel. I need the user to press a button and, without any other interaction, the application switches resolution, takes a picture, and goes back to the old resolution. To do this i looked at the code for CloseAndResume and tried to reproduce the behavior in my application, but I see that in order to apply the changes it restarts the solution (if I understand the code correctly).

if (forceRestart)
{
if (_solution != null)
{
_solution.Play();
}
if (_taskApiRunner != null)
{
_taskApiRunner.Play();
}
}

Is there a way to change resolution without calling Play? I guess I have to reproduce the same steps as the method Play, at least those that have an effect on ImageSourceProvider?

@homuler
Copy link
Owner

homuler commented Apr 23, 2024

But I'm not calling any of them, and I intend not to because I'm not using any modal panel.

If you're switching resolutions using the sample app, I meant to say that you should change the code to call Close instead of CloseAndResume because the latter API will be called when closing the modal. If not, since the sample app's API is not meant to be reused, I'd like you to resolve the issue yourself.

Is there a way to change resolution without calling Play?

If you've written code to change the resolution yourself, wouldn't it be sufficient to just not call Play?

The sample app assumes that the resolution of the input image won't change while TaskApiRunner is running for simplicity. However, TaskApiRunner.TryDetect should not care if the input resolution changes every time, so you'll need to refactor the code accordingly.

@Princic-1837592
Copy link
Author

wouldn't it be sufficient to just not call Play

The code I sent in the first comment doesn't work because the video stream doesn't restart after changing resolution, and the only alternative I found so far is to use Play

@homuler homuler added the out of scope Beyond the scope of free support label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
out of scope Beyond the scope of free support type:support Support issue
Projects
None yet
Development

No branches or pull requests

2 participants