-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
capture = createCapture(VIDEO); Can we reference a different Camera on phone? #1496
Comments
On http://p5js.org/reference/#/p5/createCapture you will find the full documentation.
For instance possible constraints are listed on:
You can define a facing mode, e.g. user: function setup() {
createCapture({
audio: false,
video: {
facingMode: "user"
}
});
} To use the rear camera you choose the environment facing mode. I tested it successfully with my desktop camera (as fallback I guess). function setup() {
createCapture({
audio: false,
video: {
facingMode: {
exact: "environment"
}
}
});
} The list shows the different facing modes:
Image source: https://w3c.github.io/mediacapture-main/getusermedia.html#dom-mediatrackconstraintset-facingmode Nevertheless you should check the browser support and read the security specifications (https):
Darius |
Thanks a lot i did read the reference i just didn't follow through the link to the other constraints. Might be worth updating the demo as well btw as this doesn't show using any constraints at all - let alone my request but also in that reference you linked me it only shows setup function. As I dug in the reference it states using constraints creates a video object to be displayed using video() but no example code on how to implement this. Using image(capture) just leaves me with black box canvas regardless of mode chosen. And yeh - i have it on my own server online which has secure hosting. It also has to point to https:// for the scripts which i have hosted on my server as well. Thanks a lot for the response |
If you wish to look. Even with the 'desktop' mode you suggest I cant show the image to the canvas yet the camera is clearly streaming. Can you let me know what i'm doing wrong. |
First of all the second sentence of the description of
It can't work with the Here is my working example: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script language="javascript" type="text/javascript" src="https://ashleyjamesbrown.com/p5js/p5.js"></script>
<script language="javascript" type="text/javascript" src="https://ashleyjamesbrown.com/p5js/p5.dom.js"></script>
<script src="sketch.js"></script>
<style>
video {
display: none;
}
</style>
</head>
<body>
</body>
</html> The method var capture;
function setup() {
createCanvas(640, 480);
var constraints = {
audio: false,
video: {
facingMode: "user"
}
};
capture = createCapture(constraints);
}
function draw() {
image(capture, 0, 0, 640, 480);
// filter(INVERT); // ;-)
} For testing I use Google Chrome (Version 51.0.2704.103 (64-bit)): http://caniuse.com/#feat=stream |
Did not realise i needed a style tag element in the html. Thanks. It works fine in the browser and on the phone now and as you say it hides the capture automatically without calling the old function This code though
does not change the phone camera to use the front facing one. On the desktop it calls the same webcam, on the phone it calls the front facing one the same as using user Could we update the reference docs btw about that error line and the html line that needs to go in - i mean once we have a use for this working as currently it does the same as the standard code? |
Thanks, I didn't know this method, but in general it does the same: https://github.com/processing/p5.js/blob/master/lib/addons/p5.dom.js#L1451-L1465 The The The constraints will be passed to I tested your implementation on my phone (Galaxy S6) with the Firefox for Android and Google Chrome. By using the Chrome browser I just see a black box. By using the Firefox browser I see a stretched version of myself: Using the phone was very laggy. I suppose because of the transformation from the streaming source to the In addition maybe the Chrome browser uses another technologies like the |
hallo. anyone find a solution? |
here is an example of printing out available sources and then specifying one by id to use for capture: |
thanks @lmccart it was extremely usefull.!!!!!!!!!!! |
I am trying to make a simple live feed using Thanks for any help. |
here's an example: https://github.com/ITPNYU/ICM-2015/blob/master/09_video_sound/02_capture/13_get_sources/sketch.js @todo add an example like this to the reference or examples page somewhere |
thank you for the reply. maybe I wasn't clear in my question as to what I wanted to achieve. I want to use a live feed of a camera connected to my raspberry pi as the background image for my p5js sketch. So i can overlay other elements relative to this feed and track my cat movement to play a game. but i cannot seem to proceed because when I open to sketch from a different computer, the feed switches to the local camera from the laptop, which I don't want (it should only be using the raspberry pi cam) so my question is:
Am still not sure if I've explained it clearly. So just for clarity, am repeating myself:
thanks for all the help. I tried your sketch but it only shows the camera attached to the local machine from which am accessing the sketch. |
@balsimpson If you are thinking of streaming the Raspberry Pi camera feed footage to a sketch running on your laptop, you will be some kind of server setup. I would start with WebRTC as a possible solution, others might have better suggestion. |
I get MediaStreamTrack.getSources is not a function, what have I missed? |
@CharlesFr does your browser support WebRTC? E.g. Safari doesn't support it yet |
I'm running it on Chrome Version 57.0.2987.133 (64-bit) |
@CharlesFr does this example work? If it does then we will need to provide more detail about your sketch, if not then we need more detail about your setup. |
This code though facingMode: { Changed to: facingMode: "environment" Worked for me. |
I'm trying to connect an IP Camera instead of a droidcam or webcam. Is it possible ? If yes, Please suggest on how to use an IP Camera with p5.js |
Hi! For the pi camera part, we've been able to stream to a canvas from a pi camera using this code: ...while the pi is running a pi camera web interface, we have a standard as card image you can use here, that also starts up a wifi net from the pi: http://publiclab.org/pi-camera Hope that helps! |
Also I believe the demo here isn't working due to an API change in webrtc video... If that's correct I can submit a fix soon! Thanks all. |
Sorry, that's not it (the API change), at least as far as I can tell. It works normally on Chrome/ChromeOS but not on Chrome Android 73.0.3683.90. I'll look for or open a new issue. 👍 |
False alarm, sorry -- it is working in that environment; the video is just cut off the side of the screen. https://github.com/processing/p5.js/issues/3699 |
capture = createCapture(VIDEO);
Using this on a mobile phone web page generally in my small test calls the front facing camera.
Was wondering about extending so we can have a default, but also pass a parameter to call any other subsequent devices attached (or at least try to) so for example we can call the standard back facing camera ? Please forgive i have missed this in any documentation
Ashley
The text was updated successfully, but these errors were encountered: