I am using p5.js and its video capture capability to use the camera. I want to use ajax to take some of those images and upload them to a server. I dont know how to convert a p5.js Image object into a format that I can use to send over the wire with ajax. The error I get is:
Uncaught TypeError: Illegal invocation
Can someone please help me with this, here is the code:
function process_image(img) {
var url = "http://random.com/process_image";
$.ajax({
url: url,
type: " POST ",
crossDomain: true,
dataType: " json ",
data: {
image: img
},
// Work with the response
success: function (response) {
console.log(response); // server response
},
error: function (response) {
console.log(response);
}
});
}
function setup() {
createCanvas(900, 900);
capture = createCapture(VIDEO);
capture.size(320, 240);
//capture.hide();
}
function draw() {
background(255);
image(capture, 0, 0, 320, 240);
filter('INVERT');
process_image(capture);
}