from image import * def isGreen(greenPixel): if greenPixel.getGreen() > greenPixel.getRed() + greenPixel.getBlue(): return True return False # 第一张图片应该是背景绿色的(参考拍电影抠图像,都是绿色背景),且两张图片大小一样 green_image = FileImage('ninja.gif') background_image = FileImage('mtn.gif') image_window = ImageWin( green_image.width * 2, green_image.height * 2) green_image.draw(image_window) background_image.setPosition(green_image.width + 1, 0) background_image.draw(image_window) combined_image = EmptyImage(green_image.width, green_image.height) combined_image.setPosition(0, green_image.height+1) combined_image.draw(image_window) combined_image.setDelay(1,200) for row in range(green_image.height): for col in range(green_image.width): if isGreen(green_image.getPixel(col, row)): new_pixel = background_image.getPixel(col, row) combined_image.setPixel(col, row, new_pixel) else: new_pixel = green_image.getPixel(col, row) combined_image.setPixel(col, row, new_pixel) combined_image.draw(image_window) image_window.exitOnClick()
settings
unfold_less visibility play_arrow