如何解决处理无法访问内置网络摄像头
IllegalStateException: Could not find any devices
import processing.video.*;
Capture unicorn;
void setup(){
size(640,480);
unicorn=new Capture (this,640,480);
unicorn.start();
background(0);
}
void captureEvent(Capture video){
video.read();
}
void draw(){
for(int i=0; i<100; i++){
float x=random(width);
float y=random(height);
color c=unicorn.get(int(x),int(y));
fill(c);
nostroke();
ellipse(x,y,16,16);
}
}
解决方法
确定一下:您是否已经添加了用于处理的视频库(它是名为“视频 | 基于 GStreamer 的用于处理的视频库”的库。)?此 Processing video tutorial 的第 1 步解释了安装,其中包含更多有趣的信息和精彩的视频示例。既然你可以运行你的草图,这应该已经没问题了。
正如 statox 已经提到的,确保相机正在为其他程序工作;可能有一些硬件或驱动程序问题。要列出 Processing 可以检测到的摄像头,您可以使用 Capture documentation 中的代码。这只是显示可用相机的部分;使用完整示例的链接:
import processing.video.*;
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
} else {
println("Available cameras:");
for (int cameraIndex = 0; cameraIndex < cameras.length; cameraIndex++) {
println(cameras[cameraIndex]);
}
}
在我有两个摄像头的系统上,输出如下所示:
Processing video library using GStreamer 1.16.2
Available cameras:
<Camera 1>
<Camera 2>
如果 Capture 文档中的代码对您不起作用,您可以尝试 Neil C Smith on the Processing forum 建议的替代方法(statox 已经提到):
import processing.video.*;
Capture camera;
void setup() {
size(640,480);
// Suggestion from Neil C Smith on the Processing forum:
camera = new Capture(this,"pipeline:autovideosrc");
camera.start();
}
void draw() {
if (camera.available()) {
camera.read();
}
image(camera,0);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。