webcam fixes

This commit is contained in:
Ali Abid 2020-11-19 06:32:04 -08:00
parent 095f263fdf
commit acd806dda8
3 changed files with 51 additions and 27 deletions

View File

@ -87,14 +87,18 @@ const image_input = {
dest_height: dim,
})
Webcam.attach(this.target.find(".webcam_box")[0]);
io.target.find(".webcam").click(function() {
Webcam.snap(function(image_data) {
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";
});
})
if (io.io_master.config.live) {
io.target.find(".webcam span").hide();
} else {
io.target.find(".webcam").click(function() {
Webcam.snap(function(image_data) {
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") {
io.target.find(".sketchpad").removeClass("hide");
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);
}
} else if (this.source == "webcam") {
if (!Webcam.loaded) {
io.io_master.no_input();
return;
}
Webcam.snap(function(image_data) {
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";
io.io_master.input(io.id, image_data);
if (io.io_master.config.live) {
io.io_master.input(io.id, image_data);
} else {
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";
io.io_master.input(io.id, image_data);
}
});
} else {
io.io_master.no_input();

View File

@ -8,7 +8,7 @@ def snap(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()
if __name__ == "__main__":

View File

@ -87,14 +87,18 @@ const image_input = {
dest_height: dim,
})
Webcam.attach(this.target.find(".webcam_box")[0]);
io.target.find(".webcam").click(function() {
Webcam.snap(function(image_data) {
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";
});
})
if (io.io_master.config.live) {
io.target.find(".webcam span").hide();
} else {
io.target.find(".webcam").click(function() {
Webcam.snap(function(image_data) {
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") {
io.target.find(".sketchpad").removeClass("hide");
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);
}
} else if (this.source == "webcam") {
if (!Webcam.loaded) {
io.io_master.no_input();
return;
}
Webcam.snap(function(image_data) {
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";
io.io_master.input(io.id, image_data);
if (io.io_master.config.live) {
io.io_master.input(io.id, image_data);
} else {
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";
io.io_master.input(io.id, image_data);
}
});
} else {
io.io_master.no_input();