0
我一直在研究處理中的一個程序,該程序比較兩個圖像並給出百分比匹配。我通過使用for循環爲圖像中的每個像素調用get()來做到這一點。我必須找到一種方法來調用一個在循環之外的for循環中初始化的變量。我瀏覽過幾個網站,似乎無法給我任何好的答案,而且我想知道這是否有可能,如果沒有,是否有辦法解決它。這裏是我的代碼:如何調用它之外的變量的範圍正在處理中
PImage fce1;
PImage fce2;
color f1;
color f2;
void setup(){
fullScreen();
background(#353535);
fce1 = loadImage("Face1.jpg");
fce2 = loadImage("Face2.jpg.png");
}
void draw(){
image(fce1, width/2 - 500, 200, 350, 500);
image(fce2, width/2 + 150, 200, 350, 500);
//line(width/2 - 150, height/2 - 250, width/2 + 150, height/2 - 250);
for(int i = height/2 - 250; i <= fce1.height + (height/2 - 250); i ++){
for(int x = width/2 - 500; x <= fce1.width + (width/2 - 500); x ++){
color vm1 = fce1.get(x, i);
this.f1 = vm1;
}
}
for(int i = height/2 - 250; i <= fce2.height + (height/2 - 250); i ++){
for(int x = width/2 + 150; x <= fce2.width + (width/2 + 150); x ++){
color vm2 = fce2.get(x, i);
this.f2 = vm2;
}
}
}
void mousePressed(){
if(mouseX >= 20 && mouseX <= 70 && mouseY >= 20 && mouseY <=70){
exit();
}
}
我試圖調用爲()循環外部變量f1,因爲for()循環初始化。提前致謝!
我不確定你在問什麼。 'f1'變量在草圖的頂部定義,所以你可以在任何你想要的地方使用它。還要注意,'f1'變量只會「保留」你給它的最後一個值。 –
哦。謝謝。我會嘗試的。 –
...你在想什麼? –