I developed some working code on the p5.js Web editor and wanted to port it to Codepen for further work. Even the following example from the processing website fails to work:
let capture;
function setup() {
createCanvas(390, 240);
capture = createCapture(VIDEO);
capture.size(320, 240);
//capture.hide();
}
function draw() {
background(255);
image(capture, 0, 0, 320, 240);
filter(INVERT);
}
When I try to run the code, I enable my webcam which turns on for about 2 seconds before shutting down. No image is captured. There is no error message in the console. I have found some pens that do have working webcams (and others that seem to have the same issue), but none that I saw tried to do it through the p5.dom library.
Is this a known issue? Are there any workarounds?
Related
I have a big problem when making a screen share demo between chrome browser depends on WebRTC.
Environment:MacBookPro macOS 10.13.3, chrome: 64.0.3282.119
In order to get screen media sourceId, I also make a chrome extention, the background-script.js code as follows:
var screenOptions = ['screen', 'window'];
......
chrome.desktopCapture.chooseDesktopMedia(screenOptions, port.sender.tab, onAccessApproved);
When get media sourceId in my html javascript, a request screen media as follows:
var constraints = {
video: {
mandatory: {
chromeMediaSource: 'desktop',
maxWidth: 1280,
maxHeight: 720,
maxFrameRate: 30,
minAspectRatio: 1.77,
chromeMediaSourceId: sourceId
}
}
};
navigator.mediaDevices.getUserMedia(constraints).then(gotLocalStream).catch(function (e) {
alert('getUserMedia() error: ' + e.name);
});
The problem comes: when I inspect WebRTC stats in chrome://webrtc-internals, I found the googFrameRateInput was very low (<=10) when I play a video in main display, while googFrameRateInput can reach 30 when a do nothing in main display.
googFrameRateInput
I also try this in windows chrome, googFrameRateInput can reach 24~30 even when play a video.
Why googFrameRateInput is too low in mac chrome?
Thank a lot.
Updating electron 6.0.2 solved the issue.
I am currently trying to load a gif into a processing sketch from a url. I am using the gifAnimation library and when I load a gif stored on my computer it works fine. I just cant seem to get it when I load from url, nothing shows up. Currently I can load the first frame using default Processing like this:
webGif= loadImage(url, "gif");
image(webGif,0,0,720,720);
If I try and load a gif using the library from the url
webGif= new Gif(this, url);
image (webGif, 0 , 0);
webGif.loop();
It doesn't load anything and my program freezes.
Loading a gif from URL seems to work as expected:
import gifAnimation.*;
Gif loopingGif;
public void setup() {
size(400, 200);
frameRate(100);
loopingGif = new Gif(this, "https://s-media-cache-ak0.pinimg.com/originals/1f/d4/83/1fd4831252c28010546e872d5b85bb70.gif");
loopingGif.loop();
}
void draw() {
background(255 / (float)height * mouseY);
image(loopingGif, 10, height / 2 - loopingGif.height / 2);
}
tested with gifAnimation 3.1 using Processing 3.2.3
Also double check the URL is valid and the file is a valid gif, before checking Processing and library versions.
I am making an app where an photo is taken and sent to the server, but the files that get sent are of low quality. It seems that when I take a photo using iOS native camera app it come out as a very sharp picture, but when using PhoneGap it reduces the quality massively.
I have set the image quality to 100 etc:
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoURISuccess, onPhotoURIFail, {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
//destinationType: Camera.DestinationType.DATA_URL,
//destinationType: Camera.DestinationType.NATIVE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
correctOrientation: true,
saveToPhotoAlbum: true,
encodingType: Camera.EncodingType.PNG
});
}
But still seems to give a real blurry image.
Has anyone else had this problem? I have also tried using the DATA_URL to get the base64 encoded image, but this makes the app go so slow that I couldn't get to a stage to send to the server.
Is there a way to use the original LOSSLESS file?
Thanks
function capturePhoto() {
navigator.camera.getPicture(onPhotoURISuccess, onPhotoURIFail, {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
correctOrientation: false,
encodingType: Camera.EncodingType.PNG,
targetWidth: 1500,
targetHeight: 1500
});
}
Im not sure why mine wouldn't work before, but it may have been because I was trying it on my iPad? I can't quite remember if I had the same problem with my iPhone also at that time.
Also the way the imageURI is retrieved may have made a difference, not sure about that either, but here is my code to get the image URI:
function onPhotoURISuccess(imageURI){
$('#imagePreview img.smallImage').attr("src", imageURI);
}
And then just get the URI from the image when you want to send. It prety much exactly like all the examples but for some reason didn't work before.
Make sure you have your plugins using the latest version too. That's about it!
The Processing size() documentation says:
In addition to the default renderer, other renderers are: P2D, P3D, PDF
So what's the difference between Default and J2D?
There used to be JAVA2D, P2D, P3D and OPENGL before v2 and I believe that P3D is now just OPENGL.
This link has some relevant info Life Saving Tips For Processing
There are 4 render modes in Processing 2.0:
default ("slow" but very accurate 2D render mode)
P2D (OPENGL, faster but less accurate 2D render mode)
P3D (OPENGL and well, 3D)
PDF (for PDF output)
default | P2D | P3D
Code I used to create these images:
void setup() {
//size(200, 200);
//size(200, 200, P2D);
size(200, 200, P3D);
}
void draw() {
background(153);
strokeWeight(10);
ellipse(100, 100, 100, 100);
}
You can find a more detailed explanation including a guide on choosing the right mode at What is P3D?
Not sure what would be causing this, but when I upload some images to my remote server via FileTransfer(), the images sometimes show up either sideways or upside down. However, when I view the images locally on the iPhone, they are positioned in the correct way.
For example, when I select an image like this to upload: http://sharefa.st/view/WBe2QNSK8r8z
It will turn out like this: http://sharefa.st/view/EWdW1Z4G8r8z
I am using the local path to transfer the file, so I don't understand why the image would rotate "randomly".
Here is my upload function:
function uploadPhoto() {
var options = new FileUploadOptions();
options.fileKey = 'file';
options.fileName = imgURI.substr(imgURI.lastIndexOf('/')+1);
options.mimeType = 'image/jpeg';
var params = new Object();
if(logged_in == true) {
params.unique_id = app_unique_id;
params.secret_key = user_secret_key;
}
options.params = params;
loadingStart();
var ft = new FileTransfer();
ft.upload(imgURI, 'http://' + remote_server + '/API/upload', uploadDetails, fail, options);
}
imgURI value looks like this:
file://localhost/var/mobile/Applications/<snip>/tmp/photo_015.jpg
Any insight is appreciated.
Thanks to Humanoidism pointing out that the issue was in fact with the iPhone, and the way it stored images, I was able to figure out a solutuion.
To upload photos in the correct orientation you must add the correctOrientation setting to the options array in getPicture(), and set it to true.
Here are two examples:
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 30, correctOrientation: true });
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 30,
destinationType: destinationType.FILE_URI,
sourceType: source,
correctOrientation: true });
}
The problem is not PhoneGap but iPhone. The iPhone was designed to be used as a wide lens camera. Turn the phone sideways when taking pictures or capturing video if you intend to view them on desktop. Your phone will display them correctly, because it "knows" how you took them, but the computer that you're viewing it on dosen't.
What you could do to prevent this is to rotate the picture before the upload. This is not a recommended fix but at least people on desktop computers will be able to see it. Though when viewing them on iPhone they'll be rotated - maybe a check for mobile devices wether or not to rotate the image could come in handy - but still again, not recommended.