我想做的是将视频摄像头中的像素转换为图像 为了更好地解释它,想象一个 3D 模型,所以......像素将是每个多边形,我想做的是将每个多边形转换成图像。
到目前为止我所拥有的是:
**
import processing.video.*;
PImage hoja;
Capture cam;
boolean uno, dos, tres, cuatro;
import ddf.minim.*;
Minim minim;
AudioPlayer audio;
float set;
void setup() {
//audio
minim = new Minim(this);
// audio = minim.loadFile("audio");
// audio.loop();
//
uno=false;
dos=false;
tres=false;
cuatro=true;
size(640, 480);
hoja=loadImage("hoja.gif");
cam = new Capture(this, width, height);
cam.start();
}
void draw() {
if (cam.available() == true) {
cam.read();
if (uno==true) {
filtroUno();
image(cam, 0, 0, 640, 480);
}
if (dos==true) {
filtroDos();
}
if(tres==true){
filtroTres();
}
if(cuatro==true){
filtroCuatro();
image(cam, set, 0,640,480);
}
}
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
}
void filtroUno() {
cam.loadPixels();
hoja.loadPixels();
for (int i=0;i<cam.pixels.length;i++) {
if (brightness(cam.pixels[i])>110) {
cam.pixels[i]=color(0, 255, 255);
}
else {
cam.pixels[i]=color(255, 0, 0);
}
}
for (int i=0;i<cam.width;i+=10) {
for (int j=0;j<cam.height;j+=10) {
int loc=i+(j*cam.width);
if (cam.pixels[loc]==color(255, 0, 0)) {
for (int x=i;x<i+10;x++) {
for (int y=j;y<j+10;y++) {
// println("bla");
int locDos=i+(j*cam.width);
cam.pixels[locDos]=hoja.get(x, y);
}
}
}
}
}
cam.updatePixels();
}
**
问题是每个像素都在为我创建一个矩阵,所以..不会重新创建要执行的操作。
我有 filtroUno 方法,但它没有显示正常.. 结果就是这样
void filtroUno() {
cam.loadPixels();
hoja.loadPixels();
for (int i=0;i<cam.pixels.length;i++) {
if (brightness(cam.pixels[i])>110) {
cam.pixels[i]=color(0, 255, 255);
}
else {
cam.pixels[i]=color(255, 0, 0);
}
}
for (int i=0;i<cam.width;i+=10) {
for (int j=0;j<cam.height;j+=10) {
int loc=i+j*hoja.width*10;
if (cam.pixels[loc]==color(255, 0, 0)) {
for (int x=i;x<i+10;x++) {
for (int y=j;y<j+10;y++) {
// println("bla");
int locDos=x+y*hoja.height*10;
cam.pixels[locDos]=hoja.get(x, y);
}
}
}
}
}
cam.updatePixels();
}
希望您能帮助我,谢谢
注意:每个红色像素应该是图像大小为10x10的gif图像
最佳答案
我认为您正在做的是循环遍历网络摄像头图像中的每 10 个像素,如果该像素为红色,则您将 10x10px gif 的内容放置在网络摄像头图像上,并将 gif 的左上角定位在红色像素处。
// loop through each 10th column in the camera
for (int i=0;i<cam.width;i+=10) {
// loop through each 10th row in the camera
for (int j=0;j<cam.height;j+=10) {
// calculate the pixel location at (i, j)
int loc=i+(j*cam.width);
// check the pixel is red
if (cam.pixels[loc]==color(255, 0, 0)) {
// loop through each column in the gif image
for (int x=0;x<10;x++) {
// loop through each row in the gif image
for (int y=0;y<10;y++) {
int locDos = (i + x) + ((j + y) * cam.width);
cam.pixels[locDos]=hoja.get(x, y);
}
}
}
}
}
关于java - 将像素从图像复制到网络摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12765825/