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

With Context for MediaStream Classes #73

Open
pushkarnimkar opened this issue Feb 21, 2020 · 2 comments
Open

With Context for MediaStream Classes #73

pushkarnimkar opened this issue Feb 21, 2020 · 2 comments

Comments

@pushkarnimkar
Copy link

Creating MediaStream classes using a with context can be useful as it ensures that media devices will be closed at the end of context.

Example syntax:

constraints = {
    "facing_mode": "user",
    "audio": False,
    "video": {
        "width": 640,
        "height": 480
    }
}

with CameraStream(constraints=constraints) as camera:
    recorder = ImageRecorder(stream=camera)
    ...
@maartenbreddels
Copy link
Owner

I like it, would you want to make a pull request?

@pushkarnimkar
Copy link
Author

Sure! I'll need some help though as I've never worked on internals of any widget before.

The use-case I was looking for is somewhat like this:
I should be able to take multiple images from webcam (as training set) till my model builds enough confidence on the subject (for facial recognition). I was not actually looking for UI element of the widget in this case. So, I actually needed to take multiple images from webcam without any button click. I faced some issue when trying to do that. I had to eventually switch to button-based system.

For example, following snippet:

for _ in range(10):
    recorder.recording = True
    time.sleep(0.5)

    recorder.recording = False
    time.sleep(0.5)

    print(hash(recorder.image.value))

Prints the same hash which corresponds to previous state of the widget (initially it prints out zero as hash(b'') is 0.

Please tell me if this is not the correct way of taking multiple images in a loop. If this is a problem, I'll like to help in fixing this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants