level 4
义海涵言
楼主
挖背景问题:能不能将人之外的每个像素挖掉或者清除?只想留住人,其他透明或者挖掉。
怎么将img图片中的人留住,其余挖掉成透明。
图中绿色去掉

(img 图片)
for (int x = 0; x < img.width; x ++ ) {
for (int y = 0; y < img.height; y ++ ) {
int loc = x + y*iimg.width; // Step 1, 1D位置是什么
color fgColor = img.pixels[loc]; // Step 2, 前景色是什么
color bgColor = backgroundImage.pixels[loc]; // Step 3, 背景色是什么
float r1 = red(fgColor);
float g1 = green(fgColor);
float b1 = blue(fgColor);
float r2 = red(bgColor);
float g2 = green(bgColor);
float b2 = blue(bgColor);
float diff = dist(r1,g1,b1,r2,g2,b2);
if (diff > 30) {
// 如果是,显示前景色
pixels[loc] = fgColor;
} else {
// 如果不是,显示绿色
//注:想将绿色改为 透明或者挖掉,怎么办啊?球帮忙
pixels[loc] = color(0,255,0); //
}
}
}
updatePixels();
2016年04月17日 03点04分
1
怎么将img图片中的人留住,其余挖掉成透明。
图中绿色去掉

(img 图片)for (int x = 0; x < img.width; x ++ ) {
for (int y = 0; y < img.height; y ++ ) {
int loc = x + y*iimg.width; // Step 1, 1D位置是什么
color fgColor = img.pixels[loc]; // Step 2, 前景色是什么
color bgColor = backgroundImage.pixels[loc]; // Step 3, 背景色是什么
float r1 = red(fgColor);
float g1 = green(fgColor);
float b1 = blue(fgColor);
float r2 = red(bgColor);
float g2 = green(bgColor);
float b2 = blue(bgColor);
float diff = dist(r1,g1,b1,r2,g2,b2);
if (diff > 30) {
// 如果是,显示前景色
pixels[loc] = fgColor;
} else {
// 如果不是,显示绿色
//注:想将绿色改为 透明或者挖掉,怎么办啊?球帮忙
pixels[loc] = color(0,255,0); //
}
}
}
updatePixels();

