mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
webcam fixes
This commit is contained in:
parent
095f263fdf
commit
acd806dda8
@ -87,14 +87,18 @@ const image_input = {
|
|||||||
dest_height: dim,
|
dest_height: dim,
|
||||||
})
|
})
|
||||||
Webcam.attach(this.target.find(".webcam_box")[0]);
|
Webcam.attach(this.target.find(".webcam_box")[0]);
|
||||||
io.target.find(".webcam").click(function() {
|
if (io.io_master.config.live) {
|
||||||
Webcam.snap(function(image_data) {
|
io.target.find(".webcam span").hide();
|
||||||
io.target.find(".webcam").hide();
|
} else {
|
||||||
io.target.find(".image_display").removeClass("hide");
|
io.target.find(".webcam").click(function() {
|
||||||
io.set_image_data(image_data, /*update_editor=*/true);
|
Webcam.snap(function(image_data) {
|
||||||
io.state = "IMAGE_LOADED";
|
io.target.find(".webcam").hide();
|
||||||
});
|
io.target.find(".image_display").removeClass("hide");
|
||||||
})
|
io.set_image_data(image_data, /*update_editor=*/true);
|
||||||
|
io.state = "IMAGE_LOADED";
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (this.source == "canvas") {
|
} else if (this.source == "canvas") {
|
||||||
io.target.find(".sketchpad").removeClass("hide");
|
io.target.find(".sketchpad").removeClass("hide");
|
||||||
var dimension = Math.min(this.target.find(".canvas_holder").width(),
|
var dimension = Math.min(this.target.find(".canvas_holder").width(),
|
||||||
@ -156,12 +160,20 @@ const image_input = {
|
|||||||
io.io_master.input(io.id, this.image_data);
|
io.io_master.input(io.id, this.image_data);
|
||||||
}
|
}
|
||||||
} else if (this.source == "webcam") {
|
} else if (this.source == "webcam") {
|
||||||
|
if (!Webcam.loaded) {
|
||||||
|
io.io_master.no_input();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Webcam.snap(function(image_data) {
|
Webcam.snap(function(image_data) {
|
||||||
io.target.find(".webcam").hide();
|
if (io.io_master.config.live) {
|
||||||
io.target.find(".image_display").removeClass("hide");
|
io.io_master.input(io.id, image_data);
|
||||||
io.set_image_data(image_data, /*update_editor=*/true);
|
} else {
|
||||||
io.state = "IMAGE_LOADED";
|
io.target.find(".webcam").hide();
|
||||||
io.io_master.input(io.id, image_data);
|
io.target.find(".image_display").removeClass("hide");
|
||||||
|
io.set_image_data(image_data, /*update_editor=*/true);
|
||||||
|
io.state = "IMAGE_LOADED";
|
||||||
|
io.io_master.input(io.id, image_data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
io.io_master.no_input();
|
io.io_master.no_input();
|
||||||
|
@ -8,7 +8,7 @@ def snap(image):
|
|||||||
return np.flipud(image)
|
return np.flipud(image)
|
||||||
|
|
||||||
|
|
||||||
iface = gr.Interface(snap, gr.inputs.Image(shape=(100,100), image_mode="L", source="webcam"), "image")
|
iface = gr.Interface(snap, gr.inputs.Image(shape=(100,100), image_mode="L", source="webcam"), "image", live=True)
|
||||||
|
|
||||||
iface.test_launch()
|
iface.test_launch()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -87,14 +87,18 @@ const image_input = {
|
|||||||
dest_height: dim,
|
dest_height: dim,
|
||||||
})
|
})
|
||||||
Webcam.attach(this.target.find(".webcam_box")[0]);
|
Webcam.attach(this.target.find(".webcam_box")[0]);
|
||||||
io.target.find(".webcam").click(function() {
|
if (io.io_master.config.live) {
|
||||||
Webcam.snap(function(image_data) {
|
io.target.find(".webcam span").hide();
|
||||||
io.target.find(".webcam").hide();
|
} else {
|
||||||
io.target.find(".image_display").removeClass("hide");
|
io.target.find(".webcam").click(function() {
|
||||||
io.set_image_data(image_data, /*update_editor=*/true);
|
Webcam.snap(function(image_data) {
|
||||||
io.state = "IMAGE_LOADED";
|
io.target.find(".webcam").hide();
|
||||||
});
|
io.target.find(".image_display").removeClass("hide");
|
||||||
})
|
io.set_image_data(image_data, /*update_editor=*/true);
|
||||||
|
io.state = "IMAGE_LOADED";
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (this.source == "canvas") {
|
} else if (this.source == "canvas") {
|
||||||
io.target.find(".sketchpad").removeClass("hide");
|
io.target.find(".sketchpad").removeClass("hide");
|
||||||
var dimension = Math.min(this.target.find(".canvas_holder").width(),
|
var dimension = Math.min(this.target.find(".canvas_holder").width(),
|
||||||
@ -156,12 +160,20 @@ const image_input = {
|
|||||||
io.io_master.input(io.id, this.image_data);
|
io.io_master.input(io.id, this.image_data);
|
||||||
}
|
}
|
||||||
} else if (this.source == "webcam") {
|
} else if (this.source == "webcam") {
|
||||||
|
if (!Webcam.loaded) {
|
||||||
|
io.io_master.no_input();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Webcam.snap(function(image_data) {
|
Webcam.snap(function(image_data) {
|
||||||
io.target.find(".webcam").hide();
|
if (io.io_master.config.live) {
|
||||||
io.target.find(".image_display").removeClass("hide");
|
io.io_master.input(io.id, image_data);
|
||||||
io.set_image_data(image_data, /*update_editor=*/true);
|
} else {
|
||||||
io.state = "IMAGE_LOADED";
|
io.target.find(".webcam").hide();
|
||||||
io.io_master.input(io.id, image_data);
|
io.target.find(".image_display").removeClass("hide");
|
||||||
|
io.set_image_data(image_data, /*update_editor=*/true);
|
||||||
|
io.state = "IMAGE_LOADED";
|
||||||
|
io.io_master.input(io.id, image_data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
io.io_master.no_input();
|
io.io_master.no_input();
|
||||||
|
Loading…
Reference in New Issue
Block a user