gpt4 book ai didi

javascript - 使用 p5.js 通过 ajax 从相机上传图像

转载 作者:行者123 更新时间:2023-11-28 05:11:08 25 4
gpt4 key购买 nike

我正在使用 p5.js 及其视频捕获功能来使用相机。我想使用 ajax 获取其中一些图像并将其上传到服务器。我不知道如何将 p5.js Image 对象转换为可用于通过 ajax 进行发送的格式。我得到的错误是:

Uncaught TypeError: Illegal invocation

有人可以帮我解决这个问题吗,这是代码:

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);

}

最佳答案

您在 var url = "http://random.com/process_image;

中缺少引号
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);
}

关于javascript - 使用 p5.js 通过 ajax 从相机上传图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41370309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com